Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
refactor(BUX-451): cleanup staticcheck errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-4chain committed Jan 16, 2024
1 parent 2987346 commit 663a5fa
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 424 deletions.
31 changes: 2 additions & 29 deletions action_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions beef_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
279 changes: 0 additions & 279 deletions chainstate/mock_minercraft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
1 change: 0 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
Loading

0 comments on commit 663a5fa

Please sign in to comment.