Skip to content

Commit

Permalink
Minor clean up and fix for issue #128
Browse files Browse the repository at this point in the history
This closes #128
  • Loading branch information
mrz1836 committed May 3, 2024
1 parent f9d92c6 commit a3e4b94
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions submit_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type (
ResultDescription string `json:"resultDescription"`
ReturnResult string `json:"returnResult"`
TxID string `json:"txid"`

// FailureRetryable if true indicates the tx can be resubmitted to mAPI.
FailureRetryable bool `json:"failureRetryable"`

Expand Down Expand Up @@ -100,19 +101,20 @@ func (c *Client) SubmitTransactions(ctx context.Context, miner *Miner, txs []Tra
}
}

// submitTransactions submits the transactions to the miner.
func submitTransactions(ctx context.Context, client *Client, miner *Miner, txs []Transaction) (*RequestResponse, error) {
api, err := client.MinerAPIByMinerID(miner.MinerID, client.apiType)
if err != nil {
return nil, err
}

route, err := ActionRouteByAPIType(SubmitTx, client.apiType)
if err != nil {
var route string
if route, err = ActionRouteByAPIType(SubmitTxs, client.apiType); err != nil {
return nil, err
}

submitURL := api.URL + route
httpPayload := &httpPayload{
payload := &httpPayload{
Method: http.MethodPost,
URL: submitURL,
Token: api.Token,
Expand All @@ -121,22 +123,24 @@ func submitTransactions(ctx context.Context, client *Client, miner *Miner, txs [

switch client.apiType {
case MAPI:
err = proceedMapiSubmitTxs(txs, httpPayload)
if err != nil {
if err = proceedMapiSubmitTxs(
txs, payload,
); err != nil {
return nil, err
}

case Arc:
err = proceedArcSubmitTxs(txs, httpPayload)
if err != nil {
if err = proceedArcSubmitTxs(
txs, payload,
); err != nil {
return nil, err
}

default:
return nil, fmt.Errorf("unknown API type: %s", client.apiType)
}

response := httpRequest(ctx, client, httpPayload)
response := httpRequest(ctx, client, payload)
return response, nil
}

Expand Down Expand Up @@ -176,6 +180,7 @@ func proceedArcSubmitTxs(txs []Transaction, httpPayload *httpPayload) error {
return nil
}

// proceedMapiSubmitTxs prepares the payload for MAPI.
func proceedMapiSubmitTxs(txs []Transaction, httpPayload *httpPayload) error {
data, err := json.Marshal(txs)
if err != nil {
Expand All @@ -196,7 +201,9 @@ func parseRawSubmitTransactionsResponse(raw RawSubmitTransactionsResponse) (*Sub
}

var payload UnifiedTxsPayload
if err := json.Unmarshal([]byte(raw.Payload), &payload); err != nil {
if err := json.Unmarshal(
[]byte(raw.Payload), &payload,
); err != nil {
return nil, err
}
result.Payload = payload
Expand Down

0 comments on commit a3e4b94

Please sign in to comment.