Skip to content

Commit

Permalink
fix: transaction not found on blockscout (#4)
Browse files Browse the repository at this point in the history
* fix: transaction not found on blockscout

* refactor: remove duplicate code
  • Loading branch information
trungnt1811 committed Oct 27, 2022
1 parent 8a04b51 commit 1b3cbce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions infrastructure/blockscout/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
)

const GET_DETAIL_EVM_TX = "/api/v1?module=transaction&action=getTxCosmosInfo&txhash="
const TX_NOT_FOUND = "transaction not found"

type HTTPClient struct {
httpClient *retryablehttp.Client
Expand Down Expand Up @@ -123,5 +124,10 @@ func (client *HTTPClient) GetDetailEvmTx(txHash string) (*TransactionEvm, error)
if err := jsoniter.NewDecoder(rawRespBody).Decode(&txResp); err != nil {
return nil, err
}

if txResp.Status == "0" {
return nil, fmt.Errorf(TX_NOT_FOUND)
}

return &txResp.Result, nil
}
14 changes: 11 additions & 3 deletions infrastructure/httpapi/handlers/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package handlers

import (
"errors"
"fmt"
"strings"
"time"

"github.com/AstraProtocol/astra-indexing/appinterface/pagination"
Expand Down Expand Up @@ -59,9 +61,15 @@ func (handler *Transactions) FindByHash(ctx *fasthttp.RequestCtx) {
if string(ctx.QueryArgs().Peek("type")) == "evm" {
transaction, err := handler.blockscoutClient.GetDetailEvmTx(hashParam)
if err != nil {
handler.logger.Errorf("error parsing tx response from blockscout: %v", err)
httpapi.InternalServerError(ctx)
return
if strings.Contains(fmt.Sprint(err), blockscout_infrastructure.TX_NOT_FOUND) {
ctx.QueryArgs().Del("type")
handler.FindByHash(ctx)
return
} else {
handler.logger.Errorf("error parsing tx response from blockscout: %v", err)
httpapi.InternalServerError(ctx)
return
}
}
httpapi.Success(ctx, transaction)
} else {
Expand Down

0 comments on commit 1b3cbce

Please sign in to comment.