From 663a5fa90fd89d51f94faededa698990f2ac6136 Mon Sep 17 00:00:00 2001 From: Krzysztof Tomecki <152964795+chris-4chain@users.noreply.github.com> Date: Tue, 16 Jan 2024 07:28:57 +0100 Subject: [PATCH] refactor(BUX-451): cleanup staticcheck errors --- action_transaction.go | 31 +--- beef_tx.go | 3 + chainstate/mock_minercraft.go | 279 --------------------------------- client.go | 1 - interface.go | 1 - model_incoming_transactions.go | 24 +-- model_sync_transactions.go | 7 - model_transactions.go | 5 +- model_transactions_test.go | 4 +- model_xpubs_test.go | 12 +- sync_tx_repository.go | 18 --- tx_repository.go | 57 ------- 12 files changed, 18 insertions(+), 424 deletions(-) diff --git a/action_transaction.go b/action_transaction.go index 103364eb..f597da8f 100644 --- a/action_transaction.go +++ b/action_transaction.go @@ -92,10 +92,7 @@ func (c *Client) NewTransaction(ctx context.Context, rawXpubKey string, config * return draftTransaction, nil } -// GetTransaction will get a transaction from the Datastore -// -// ctx is the context -// testTxID is the transaction ID +// GetTransaction will get a transaction by its ID from the Datastore func (c *Client) GetTransaction(ctx context.Context, xPubID, txID string) (*Transaction, error) { // Check for existing NewRelic transaction ctx = c.GetOrStartTxn(ctx, "get_transaction") @@ -114,12 +111,7 @@ func (c *Client) GetTransaction(ctx context.Context, xPubID, txID string) (*Tran return transaction, nil } -// GetTransactionByID will get a transaction from the Datastore by tx ID -// uses GetTransaction -func (c *Client) GetTransactionByID(ctx context.Context, txID string) (*Transaction, error) { - return c.GetTransaction(ctx, "", txID) -} - +// GetTransactionsByIDs returns array of transactions by their IDs from the Datastore func (c *Client) GetTransactionsByIDs(ctx context.Context, txIDs []string) ([]*Transaction, error) { // Check for existing NewRelic transaction ctx = c.GetOrStartTxn(ctx, "get_transactions_by_ids") @@ -169,25 +161,6 @@ func (c *Client) GetTransactions(ctx context.Context, metadataConditions *Metada return transactions, nil } -// GetTransactionsAggregate will get a count of all transactions per aggregate column from the Datastore -func (c *Client) GetTransactionsAggregate(ctx context.Context, metadataConditions *Metadata, - conditions *map[string]interface{}, aggregateColumn string, opts ...ModelOps, -) (map[string]interface{}, error) { - // Check for existing NewRelic transaction - ctx = c.GetOrStartTxn(ctx, "get_transactions") - - // Get the transactionAggregate - transactionAggregate, err := getTransactionsAggregate( - ctx, metadataConditions, conditions, aggregateColumn, - c.DefaultModelOptions(opts...)..., - ) - if err != nil { - return nil, err - } - - return transactionAggregate, nil -} - // GetTransactionsCount will get a count of all the transactions from the Datastore func (c *Client) GetTransactionsCount(ctx context.Context, metadataConditions *Metadata, conditions *map[string]interface{}, opts ...ModelOps, diff --git a/beef_tx.go b/beef_tx.go index b8b60e69..a2fa8cde 100644 --- a/beef_tx.go +++ b/beef_tx.go @@ -28,6 +28,9 @@ func ToBeef(ctx context.Context, tx *Transaction, store TransactionGetter) (stri } bumps, err := calculateMergedBUMP(bumpFactors) + if err != nil { + return "", err + } sortedTxs := kahnTopologicalSortTransactions(bumpBtFactors) beefHex, err := toBeefHex(ctx, bumps, sortedTxs) if err != nil { diff --git a/chainstate/mock_minercraft.go b/chainstate/mock_minercraft.go index caa9678d..1812ad3b 100644 --- a/chainstate/mock_minercraft.go +++ b/chainstate/mock_minercraft.go @@ -524,253 +524,6 @@ func (m *minerCraftBroadcastSuccess) SubmitTransaction(_ context.Context, miner return nil, errors.New("missing miner response") } -// //nolint: unused //TODO: remove this when the method is implemented -type minerCraftInMempool struct { - minerCraftTxOnChain -} - -// SubmitTransaction submits a transaction to the miner. -// //nolint: unused // TODO: remove this when the method is implemented -func (m *minerCraftInMempool) SubmitTransaction(_ context.Context, miner *minercraft.Miner, - _ *minercraft.Transaction, -) (*minercraft.SubmitTransactionResponse, error) { - if miner.Name == minercraft.MinerTaal { - sig := "30440220008615778c5b8610c29b12925c8eb479f692ad6de9e62b7e622a3951baf9fbd8022014aaa27698cd3aba4144bfd707f3323e12ac20101d6e44f22eb8ed0856ef341a" - pubKey := miner.MinerID - return &minercraft.SubmitTransactionResponse{ - JSONEnvelope: minercraft.JSONEnvelope{ - Miner: miner, - Validated: true, - JSONEnvelope: envelope.JSONEnvelope{ - Payload: "{\"apiVersion\":\"1.4.0\",\"timestamp\":\"2022-02-01T15:19:40.889523Z\",\"txid\":\"683e11d4db8a776e293dc3bfe446edf66cf3b145a6ec13e1f5f1af6bb5855364\",\"returnResult\":\"failure\",\"resultDescription\":\"Missing inputs\",\"minerId\":\"030d1fe5c1b560efe196ba40540ce9017c20daa9504c4c4cec6184fc702d9f274e\",\"currentHighestBlockHash\":\"00000000000000000652def5827ad3de6380376f8fc8d3e835503095a761e0d2\",\"currentHighestBlockHeight\":724807,\"txSecondMempoolExpiry\":0}", - Signature: &sig, - PublicKey: &pubKey, - Encoding: utf8Type, - MimeType: applicationJSONType, - }, - }, - Results: &minercraft.UnifiedSubmissionPayload{ - APIVersion: "1.4.0", - CurrentHighestBlockHash: "00000000000000000652def5827ad3de6380376f8fc8d3e835503095a761e0d2", - CurrentHighestBlockHeight: 724807, - MinerID: miner.MinerID, - ResultDescription: "Missing inputs", - ReturnResult: mAPIFailure, - Timestamp: "2022-02-01T15:19:40.889523Z", - TxID: onChainExample1TxID, - }, - }, nil - } else if miner.Name == minercraft.MinerMempool { - return &minercraft.SubmitTransactionResponse{ - JSONEnvelope: minercraft.JSONEnvelope{ - Miner: miner, - Validated: true, - JSONEnvelope: envelope.JSONEnvelope{ - Payload: "{\"apiVersion\":\"\",\"timestamp\":\"2022-02-01T17:47:52.518Z\",\"txid\":\"\",\"returnResult\":\"failure\",\"resultDescription\":\"ERROR: Missing inputs\",\"minerId\":null,\"currentHighestBlockHash\":\"0000000000000000064c900b1fceb316302426aedb2242852530b5e78144f2c1\",\"currentHighestBlockHeight\":724816,\"txSecondMempoolExpiry\":0}", - Encoding: utf8Type, - MimeType: applicationJSONType, - }, - }, - Results: &minercraft.UnifiedSubmissionPayload{ - APIVersion: "", - CurrentHighestBlockHash: "0000000000000000064c900b1fceb316302426aedb2242852530b5e78144f2c1", - CurrentHighestBlockHeight: 724816, - MinerID: miner.MinerID, - ResultDescription: "ERROR: Missing inputs", - ReturnResult: mAPIFailure, - Timestamp: "2022-02-01T17:47:52.518Z", - TxID: "", - }, - }, nil - } else if miner.Name == minercraft.MinerMatterpool { - sig := matterCloudSig1 - pubKey := miner.MinerID - return &minercraft.SubmitTransactionResponse{ - JSONEnvelope: minercraft.JSONEnvelope{ - Miner: miner, - Validated: true, - JSONEnvelope: envelope.JSONEnvelope{ - Payload: "{\"apiVersion\":\"1.1.0-1-g35ba2d3\",\"timestamp\":\"2022-02-01T17:50:15.130Z\",\"txid\":\"\",\"returnResult\":\"failure\",\"resultDescription\":\"ERROR: Missing inputs\",\"minerId\":\"0253a9b2d017254b91704ba52aad0df5ca32b4fb5cb6b267ada6aefa2bc5833a93\",\"currentHighestBlockHash\":\"0000000000000000064c900b1fceb316302426aedb2242852530b5e78144f2c1\",\"currentHighestBlockHeight\":724816,\"txSecondMempoolExpiry\":0}", - Signature: &sig, - PublicKey: &pubKey, - Encoding: utf8Type, - MimeType: applicationJSONType, - }, - }, - Results: &minercraft.UnifiedSubmissionPayload{ - APIVersion: "1.1.0-1-g35ba2d3", - CurrentHighestBlockHash: "0000000000000000064c900b1fceb316302426aedb2242852530b5e78144f2c1", - CurrentHighestBlockHeight: 724816, - MinerID: miner.MinerID, - ResultDescription: "ERROR: Missing inputs", - ReturnResult: mAPIFailure, - Timestamp: "2022-02-01T17:50:15.130Z", - TxID: "", - }, - }, nil - } else if miner.Name == minercraft.MinerGorillaPool { - sig := gorillaPoolSig1 - pubKey := miner.MinerID - return &minercraft.SubmitTransactionResponse{ - JSONEnvelope: minercraft.JSONEnvelope{ - Miner: miner, - Validated: true, - JSONEnvelope: envelope.JSONEnvelope{ - Payload: "{\"apiVersion\":\"\",\"timestamp\":\"2022-02-01T17:52:04.405Z\",\"txid\":\"\",\"returnResult\":\"failure\",\"resultDescription\":\"ERROR: Missing inputs\",\"minerId\":\"03ad780153c47df915b3d2e23af727c68facaca4facd5f155bf5018b979b9aeb83\",\"currentHighestBlockHash\":\"0000000000000000064c900b1fceb316302426aedb2242852530b5e78144f2c1\",\"currentHighestBlockHeight\":724816,\"txSecondMempoolExpiry\":0}", - Signature: &sig, - PublicKey: &pubKey, - Encoding: utf8Type, - MimeType: applicationJSONType, - }, - }, - Results: &minercraft.UnifiedSubmissionPayload{ - APIVersion: "", - CurrentHighestBlockHash: "0000000000000000064c900b1fceb316302426aedb2242852530b5e78144f2c1", - CurrentHighestBlockHeight: 724816, - MinerID: miner.MinerID, - ResultDescription: "ERROR: Missing inputs", - ReturnResult: mAPIFailure, - Timestamp: "2022-02-01T17:52:04.405Z", - TxID: "", - }, - }, nil - } - - return nil, errors.New("missing miner response") -} - -type minerCraftTxNotFound struct { - MinerCraftBase -} - -// SubmitTransaction submits a transaction to the miner. -func (m *minerCraftTxNotFound) SubmitTransaction(_ context.Context, miner *minercraft.Miner, - _ *minercraft.Transaction, -) (*minercraft.SubmitTransactionResponse, error) { - return &minercraft.SubmitTransactionResponse{ - JSONEnvelope: minercraft.JSONEnvelope{ - Miner: miner, - Validated: true, - JSONEnvelope: envelope.JSONEnvelope{ - Payload: "{\"apiVersion\":\"\",\"timestamp\":\"2022-02-01T17:47:52.518Z\",\"txid\":\"\",\"returnResult\":\"failure\",\"resultDescription\":\"ERROR: Mempool conflict\",\"minerId\":null,\"currentHighestBlockHash\":\"0000000000000000064c900b1fceb316302426aedb2242852530b5e78144f2c1\",\"currentHighestBlockHeight\":724816,\"txSecondMempoolExpiry\":0}", - Encoding: utf8Type, - MimeType: applicationJSONType, - }, - }, - Results: &minercraft.UnifiedSubmissionPayload{ - APIVersion: "", - CurrentHighestBlockHash: "0000000000000000064c900b1fceb316302426aedb2242852530b5e78144f2c1", - CurrentHighestBlockHeight: 724816, - MinerID: miner.MinerID, - ResultDescription: "ERROR: Mempool conflict", - ReturnResult: mAPIFailure, - Timestamp: "2022-02-01T17:47:52.518Z", - TxID: "", - }, - }, nil -} - -// QueryTransaction queries a transaction from the miner. -func (m *minerCraftTxNotFound) QueryTransaction(_ context.Context, miner *minercraft.Miner, - _ string, _ ...minercraft.QueryTransactionOptFunc, -) (*minercraft.QueryTransactionResponse, error) { - if miner.Name == minerTaal.Name { - sig := "304402201aae61ec65500cf38af48e552c0ea0c62c7937805a99ff6b2dc62bad1a23c183022027a0bb97890f92d41e7b333e8f3dec106aedcd16b782f2f8b46501e104104322" - pubKey := minerTaal.MinerID - return &minercraft.QueryTransactionResponse{ - JSONEnvelope: minercraft.JSONEnvelope{ - Miner: minerTaal, - Validated: true, - JSONEnvelope: envelope.JSONEnvelope{ - Payload: "{\"apiVersion\":\"1.4.0\",\"timestamp\":\"2022-01-24T01:36:23.0767761Z\",\"txid\":\"918c26f8227fa99f1b26f99a19648653a1382fb3b37b03870e9c138894d29b3b\",\"returnResult\":\"failure\",\"resultDescription\":\"No such mempool or blockchain transaction. Use gettransaction for wallet transactions.\",\"minerId\":\"030d1fe5c1b560efe196ba40540ce9017c20daa9504c4c4cec6184fc702d9f274e\",\"txSecondMempoolExpiry\":0}", - Signature: &sig, - PublicKey: &pubKey, - Encoding: utf8Type, - MimeType: applicationJSONType, - }, - }, - Query: &minercraft.QueryTxResponse{ - APIVersion: "1.4.0", - Timestamp: "2022-01-24T01:36:23.0767761Z", - TxID: notFoundExample1TxID, - ReturnResult: mAPIFailure, - ResultDescription: "No such mempool or blockchain transaction. Use gettransaction for wallet transactions.", - MinerID: minerTaal.MinerID, - }, - }, nil - } else if miner.Name == minerMempool.Name { - return &minercraft.QueryTransactionResponse{ - JSONEnvelope: minercraft.JSONEnvelope{ - Miner: minerMempool, - Validated: true, - JSONEnvelope: envelope.JSONEnvelope{ - Payload: "{\"apiVersion\":\"\",\"timestamp\":\"2022-01-24T01:39:58.066Z\",\"txid\":\"918c26f8227fa99f1b26f99a19648653a1382fb3b37b03870e9c138894d29b3b\",\"returnResult\":\"failure\",\"resultDescription\":\"ERROR: No such mempool or blockchain transaction. Use gettransaction for wallet transactions.\",\"blockHash\":null,\"blockHeight\":null,\"confirmations\":0,\"minerId\":null,\"txSecondMempoolExpiry\":0}", - Encoding: utf8Type, - MimeType: applicationJSONType, - }, - }, - Query: &minercraft.QueryTxResponse{ - APIVersion: "", // NOTE: missing from mempool response - Timestamp: "2022-01-24T01:39:58.066Z", - TxID: notFoundExample1TxID, - ReturnResult: mAPIFailure, - ResultDescription: "ERROR: No such mempool or blockchain transaction. Use gettransaction for wallet transactions.", - MinerID: "", // NOTE: missing from mempool response - }, - }, nil - } else if miner.Name == minerGorillaPool.Name { - sig := "3045022100eaf52c498ee79c7deb7f67ebcdb174b446e3f8e826ef6c9faa3e3365c14008a9022036b9a355574af9576e3f2c124855c81c56164df8713d0615bc0be09c50e103c8" - pubKey := minerGorillaPool.MinerID - return &minercraft.QueryTransactionResponse{ - JSONEnvelope: minercraft.JSONEnvelope{ - Miner: minerGorillaPool, - Validated: true, - JSONEnvelope: envelope.JSONEnvelope{ - Payload: "{\"apiVersion\":\"\",\"timestamp\":\"2022-01-24T01:40:41.136Z\",\"txid\":\"918c26f8227fa99f1b26f99a19648653a1382fb3b37b03870e9c138894d29b3b\",\"returnResult\":\"failure\",\"resultDescription\":\"Mixed results\",\"blockHash\":null,\"blockHeight\":null,\"confirmations\":0,\"minerId\":\"03ad780153c47df915b3d2e23af727c68facaca4facd5f155bf5018b979b9aeb83\",\"txSecondMempoolExpiry\":0}", - Encoding: utf8Type, - Signature: &sig, - PublicKey: &pubKey, - MimeType: applicationJSONType, - }, - }, - Query: &minercraft.QueryTxResponse{ - APIVersion: "", - Timestamp: "2022-01-24T01:40:41.136Z", - TxID: notFoundExample1TxID, - ReturnResult: mAPIFailure, - ResultDescription: "Mixed results", - MinerID: minerGorillaPool.MinerID, - }, - }, nil - } else if miner.Name == minerMatterPool.Name { - sig := "304402200abaf73f5b70f225f52dadc328fd5facf689d8e99ddd731b1c8a17522635c2aa022028c5d040402d8ddd7d64d94f2d7dbcd600ac50e1c503ae40fb314e0435c78b7f" - pubKey := minerMatterPool.MinerID - return &minercraft.QueryTransactionResponse{ - JSONEnvelope: minercraft.JSONEnvelope{ - Miner: minerMatterPool, - Validated: true, - JSONEnvelope: envelope.JSONEnvelope{ - Payload: "{\"apiVersion\":\"1.1.0-1-g35ba2d3\",\"timestamp\":\"2022-01-24T01:41:01.683Z\",\"txid\":\"918c26f8227fa99f1b26f99a19648653a1382fb3b37b03870e9c138894d29b3b\",\"returnResult\":\"failure\",\"resultDescription\":\"ERROR: No such mempool transaction. Use -txindex to enable blockchain transaction queries. Use gettransaction for wallet transactions.\",\"blockHash\":null,\"blockHeight\":null,\"confirmations\":0,\"minerId\":\"0253a9b2d017254b91704ba52aad0df5ca32b4fb5cb6b267ada6aefa2bc5833a93\",\"txSecondMempoolExpiry\":0}", - Encoding: utf8Type, - Signature: &sig, - PublicKey: &pubKey, - MimeType: applicationJSONType, - }, - }, - Query: &minercraft.QueryTxResponse{ - APIVersion: "1.1.0-1-g35ba2d3", - Timestamp: "2022-01-24T01:41:01.683Z", - TxID: notFoundExample1TxID, - ReturnResult: mAPIFailure, - ResultDescription: "ERROR: No such mempool transaction. Use -txindex to enable blockchain transaction queries. Use gettransaction for wallet transactions.", - MinerID: minerMatterPool.MinerID, - }, - }, nil - } - - return nil, nil -} - type minerCraftUnreachble struct { MinerCraftBase } @@ -779,35 +532,3 @@ type minerCraftUnreachble struct { func (m *minerCraftUnreachble) FeeQuote(context.Context, *minercraft.Miner) (*minercraft.FeeQuoteResponse, error) { return nil, errors.New("minercraft is unreachable") } - -type minerCraftBroadcastTimeout struct { - MinerCraftBase -} - -func (m *minerCraftBroadcastTimeout) SubmitTransaction(_ context.Context, miner *minercraft.Miner, - _ *minercraft.Transaction, -) (*minercraft.SubmitTransactionResponse, error) { - time.Sleep(defaultBroadcastTimeOut * 2) - - return &minercraft.SubmitTransactionResponse{ - JSONEnvelope: minercraft.JSONEnvelope{ - Miner: miner, - Validated: true, - JSONEnvelope: envelope.JSONEnvelope{ - Payload: "{\"apiVersion\":\"\",\"timestamp\":\"2022-02-01T17:47:52.518Z\",\"txid\":\"\",\"returnResult\":\"failure\",\"resultDescription\":\"ERROR: Mempool conflict\",\"minerId\":null,\"currentHighestBlockHash\":\"0000000000000000064c900b1fceb316302426aedb2242852530b5e78144f2c1\",\"currentHighestBlockHeight\":724816,\"txSecondMempoolExpiry\":0}", - Encoding: utf8Type, - MimeType: applicationJSONType, - }, - }, - Results: &minercraft.UnifiedSubmissionPayload{ - APIVersion: "", - CurrentHighestBlockHash: "0000000000000000064c900b1fceb316302426aedb2242852530b5e78144f2c1", - CurrentHighestBlockHeight: 724816, - MinerID: miner.MinerID, - ResultDescription: "ERROR: Mempool conflict", - ReturnResult: mAPIFailure, - Timestamp: "2022-02-01T17:47:52.518Z", - TxID: "", - }, - }, nil -} diff --git a/client.go b/client.go index bf595545..5e821645 100644 --- a/client.go +++ b/client.go @@ -114,7 +114,6 @@ type ( // taskManagerOptions holds the configuration for taskmanager taskManagerOptions struct { taskmanager.TaskEngine // Client for TaskManager - cronJobs taskmanager.CronJobs // List of cron jobs options []taskmanager.TaskManagerOptions // List of options cronCustomPeriods map[string]time.Duration // will override the default period of cronJob } diff --git a/interface.go b/interface.go index 5e661208..cd9f6bfa 100644 --- a/interface.go +++ b/interface.go @@ -131,7 +131,6 @@ type PaymailService interface { // TransactionService is the transaction actions type TransactionService interface { GetTransaction(ctx context.Context, xPubID, txID string) (*Transaction, error) - GetTransactionByID(ctx context.Context, txID string) (*Transaction, error) GetTransactionsByIDs(ctx context.Context, txIDs []string) ([]*Transaction, error) GetTransactionByHex(ctx context.Context, hex string) (*Transaction, error) GetTransactions(ctx context.Context, metadata *Metadata, conditions *map[string]interface{}, diff --git a/model_incoming_transactions.go b/model_incoming_transactions.go index 56575420..ab81b763 100644 --- a/model_incoming_transactions.go +++ b/model_incoming_transactions.go @@ -53,23 +53,6 @@ func newIncomingTransaction(hex string, opts ...ModelOps) (*IncomingTransaction, return tx, nil } -// getIncomingTransactionByID will get the incoming transactions to process -func getIncomingTransactionByID(ctx context.Context, id string, opts ...ModelOps) (*IncomingTransaction, error) { - // Construct an empty tx - tx := emptyIncomingTx(opts...) - tx.ID = id - - // Get the record - if err := Get(ctx, tx, nil, false, defaultDatabaseReadTimeout, false); err != nil { - if errors.Is(err, datastore.ErrNoResults) { - return nil, nil - } - return nil, err - } - - return tx, nil -} - // getIncomingTransactionsToProcess will get the incoming transactions to process func getIncomingTransactionsToProcess(ctx context.Context, queryParams *datastore.QueryParams, opts ...ModelOps, @@ -210,7 +193,8 @@ func (m *IncomingTransaction) Migrate(client datastore.ClientInterface) error { // processIncomingTransactions will process incoming transaction records func processIncomingTransactions(ctx context.Context, logClient *zerolog.Logger, maxTransactions int, - opts ...ModelOps) error { + opts ...ModelOps, +) error { queryParams := &datastore.QueryParams{Page: 1, PageSize: maxTransactions} // Get x records: @@ -241,8 +225,8 @@ func processIncomingTransactions(ctx context.Context, logClient *zerolog.Logger, // processIncomingTransaction will process the incoming transaction record into a transaction, or save the failure func processIncomingTransaction(ctx context.Context, logClient *zerolog.Logger, - incomingTx *IncomingTransaction) error { - + incomingTx *IncomingTransaction, +) error { if logClient == nil { logClient = incomingTx.client.Logger() } diff --git a/model_sync_transactions.go b/model_sync_transactions.go index e6e900e1..df9e9823 100644 --- a/model_sync_transactions.go +++ b/model_sync_transactions.go @@ -67,13 +67,6 @@ func (m *SyncTransaction) GetID() string { return m.ID } -// isSkipped will return true if Broadcasting, P2P and SyncOnChain are all skipped -func (m *SyncTransaction) isSkipped() bool { - return m.BroadcastStatus == SyncStatusSkipped && - m.SyncStatus == SyncStatusSkipped && - m.P2PStatus == SyncStatusSkipped -} - // GetModelName will get the name of the current model func (m *SyncTransaction) GetModelName() string { return ModelSyncTransaction.String() diff --git a/model_transactions.go b/model_transactions.go index 4e6ec267..cb919cc1 100644 --- a/model_transactions.go +++ b/model_transactions.go @@ -71,6 +71,7 @@ type Transaction struct { beforeCreateCalled bool `gorm:"-" bson:"-"` // Private information that the transaction lifecycle method BeforeCreate was already called } +// TransactionGetter interface for getting transactions by their IDs type TransactionGetter interface { GetTransactionsByIDs(ctx context.Context, txIDs []string) ([]*Transaction, error) } @@ -235,10 +236,6 @@ func (m *Transaction) getValues() (outputValue uint64, fee uint64) { return } -func (m *Transaction) isExternal() bool { - return m.draftTransaction == nil -} - func (m *Transaction) setChainInfo(txInfo *chainstate.TransactionInfo) { m.BlockHash = txInfo.BlockHash m.BlockHeight = uint64(txInfo.BlockHeight) diff --git a/model_transactions_test.go b/model_transactions_test.go index 09113837..d2bfcc94 100644 --- a/model_transactions_test.go +++ b/model_transactions_test.go @@ -220,10 +220,10 @@ func TestTransaction_BeforeCreating(t *testing.T) { transaction := emptyTx() opts := DefaultClientOpts(false, false) - client, err := NewClient(context.Background(), opts...) + client, _ := NewClient(context.Background(), opts...) transaction.client = client - err = transaction.BeforeCreating(context.Background()) + err := transaction.BeforeCreating(context.Background()) assert.Error(t, err) assert.ErrorIs(t, ErrMissingFieldHex, err) }) diff --git a/model_xpubs_test.go b/model_xpubs_test.go index 5edfa869..e132d9ce 100644 --- a/model_xpubs_test.go +++ b/model_xpubs_test.go @@ -185,10 +185,10 @@ func TestXpub_BeforeCreating(t *testing.T) { require.NotNil(t, xPub) opts := DefaultClientOpts(false, false) - client, err := NewClient(context.Background(), opts...) + client, _ := NewClient(context.Background(), opts...) xPub.client = client - err = xPub.BeforeCreating(context.Background()) + err := xPub.BeforeCreating(context.Background()) require.NoError(t, err) require.NotNil(t, xPub) }) @@ -209,10 +209,10 @@ func TestXpub_BeforeCreating(t *testing.T) { require.NotNil(t, xPub) opts := DefaultClientOpts(false, false) - client, err := NewClient(context.Background(), opts...) + client, _ := NewClient(context.Background(), opts...) xPub.client = client - err = xPub.BeforeCreating(context.Background()) + err := xPub.BeforeCreating(context.Background()) assert.Error(t, err) assert.EqualError(t, err, "xpub is an invalid length") }) @@ -227,10 +227,10 @@ func TestXpub_AfterCreated(t *testing.T) { require.NotNil(t, xPub) opts := DefaultClientOpts(false, false) - client, err := NewClient(context.Background(), opts...) + client, _ := NewClient(context.Background(), opts...) xPub.client = client - err = xPub.BeforeCreating(context.Background()) + err := xPub.BeforeCreating(context.Background()) require.NoError(t, err) require.NotNil(t, xPub) diff --git a/sync_tx_repository.go b/sync_tx_repository.go index a1eaa4d4..8532521e 100644 --- a/sync_tx_repository.go +++ b/sync_tx_repository.go @@ -100,24 +100,6 @@ func getTransactionsToSync(ctx context.Context, queryParams *datastore.QueryPara return txs, nil } -// getTransactionsToNotifyP2P will get the sync transactions to notify p2p paymail providers -func getTransactionsToNotifyP2P(ctx context.Context, queryParams *datastore.QueryParams, - opts ...ModelOps, -) ([]*SyncTransaction, error) { - // Get the records by status - txs, err := _getSyncTransactionsByConditions( - ctx, - map[string]interface{}{ - p2pStatusField: SyncStatusReady.String(), - }, - queryParams, opts..., - ) - if err != nil { - return nil, err - } - return txs, nil -} - /*** /public unexported funcs ***/ // getTransactionsToSync will get the sync transactions to sync diff --git a/tx_repository.go b/tx_repository.go index c49bd468..b0a89bac 100644 --- a/tx_repository.go +++ b/tx_repository.go @@ -199,63 +199,6 @@ func getTransactionsCountInternal(ctx context.Context, conditions map[string]int return count, nil } -// getTransactionsByConditions will get the sync transactions to migrate -func getTransactionsByConditions(ctx context.Context, conditions map[string]interface{}, - queryParams *datastore.QueryParams, opts ...ModelOps, -) ([]*Transaction, error) { - if queryParams == nil { - queryParams = &datastore.QueryParams{ - OrderByField: createdAtField, - SortDirection: datastore.SortAsc, - } - } else if queryParams.OrderByField == "" || queryParams.SortDirection == "" { - queryParams.OrderByField = createdAtField - queryParams.SortDirection = datastore.SortAsc - } - - // Get the records - var models []Transaction - if err := getModels( - ctx, NewBaseModel(ModelNameEmpty, opts...).Client().Datastore(), - &models, conditions, queryParams, defaultDatabaseReadTimeout, - ); err != nil { - if errors.Is(err, datastore.ErrNoResults) { - return nil, nil - } - return nil, err - } - - // Loop and enrich - txs := make([]*Transaction, 0) - for index := range models { - models[index].enrich(ModelTransaction, opts...) - txs = append(txs, &models[index]) - } - - return txs, nil -} - -// getTransactionsToMigrateMerklePath will get the transactions where bump should be calculated -func getTransactionsToCalculateBUMP(ctx context.Context, queryParams *datastore.QueryParams, - opts ...ModelOps, -) ([]*Transaction, error) { - // Get the records by status - txs, err := getTransactionsByConditions( - ctx, - map[string]interface{}{ - bumpField: nil, - merkleProofField: map[string]interface{}{ - "$exists": true, - }, - }, - queryParams, opts..., - ) - if err != nil { - return nil, err - } - return txs, nil -} - func getTransactionByHex(ctx context.Context, hex string, opts ...ModelOps) (*Transaction, error) { btTx, err := bt.NewTxFromString(hex) if err != nil {