diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..28af00f --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,23 @@ +name: Lint +on: + pull_request: + workflow_call: {} + workflow_dispatch: {} + +jobs: + lint: + name: Run Linter + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: 1.21.x + + - name: Checkout code + uses: actions/checkout@v3 + + - name: Lint + uses: golangci/golangci-lint-action@v3 + with: + args: --timeout 10m --verbose diff --git a/etherman/errors.go b/etherman/errors.go index d98bce5..71781b5 100644 --- a/etherman/errors.go +++ b/etherman/errors.go @@ -2,7 +2,6 @@ package etherman import ( "errors" - "strings" ) var ( @@ -22,27 +21,4 @@ var ( ErrNoSigner = errors.New("no signer to authorize the transaction with") // ErrMissingTrieNode means that a node is missing on the trie ErrMissingTrieNode = errors.New("missing trie node") - - errorsCache = map[string]error{ - ErrGasRequiredExceedsAllowance.Error(): ErrGasRequiredExceedsAllowance, - ErrContentLengthTooLarge.Error(): ErrContentLengthTooLarge, - ErrTimestampMustBeInsideRange.Error(): ErrTimestampMustBeInsideRange, - ErrInsufficientAllowance.Error(): ErrInsufficientAllowance, - ErrBothGasPriceAndMaxFeeGasAreSpecified.Error(): ErrBothGasPriceAndMaxFeeGasAreSpecified, - ErrMaxFeeGasAreSpecifiedButLondonNotActive.Error(): ErrMaxFeeGasAreSpecifiedButLondonNotActive, - ErrNoSigner.Error(): ErrNoSigner, - ErrMissingTrieNode.Error(): ErrMissingTrieNode, - } ) - -func tryParseError(err error) (error, bool) { - parsedError, exists := errorsCache[err.Error()] - if !exists { - for errStr, actualErr := range errorsCache { - if strings.Contains(err.Error(), errStr) { - return actualErr, true - } - } - } - return parsedError, exists -} diff --git a/rpc/rpc.go b/rpc/rpc.go index 0f9e8c1..4d5cd74 100644 --- a/rpc/rpc.go +++ b/rpc/rpc.go @@ -130,16 +130,28 @@ func (i *InteropEndpoints) SendTx(signedTx tx.SignedTx) (interface{}, types.Erro return signedTx.Tx.Hash(), nil } -func (i *InteropEndpoints) GetTxStatus(hash common.Hash) (interface{}, types.Error) { +func (i *InteropEndpoints) GetTxStatus(hash common.Hash) (result interface{}, err types.Error) { ctx := context.TODO() - dbTx, err := i.db.BeginStateTransaction(ctx) - defer dbTx.Rollback(ctx) - if err != nil { - return "0x0", types.NewRPCError(types.DefaultErrorCode, fmt.Sprintf("failed to begin dbTx, error: %s", err)) + dbTx, innerErr := i.db.BeginStateTransaction(ctx) + if innerErr != nil { + result = "0x0" + err = types.NewRPCError(types.DefaultErrorCode, fmt.Sprintf("failed to begin dbTx, error: %s", err)) } - res, err := i.ethTxManager.Result(ctx, ethTxManOwner, hash.Hex(), dbTx) - if err != nil { - return "0x0", types.NewRPCError(types.DefaultErrorCode, fmt.Sprintf("failed to get tx, error: %s", err)) + + res, innerErr := i.ethTxManager.Result(ctx, ethTxManOwner, hash.Hex(), dbTx) + if innerErr != nil { + result = "0x0" + err = types.NewRPCError(types.DefaultErrorCode, fmt.Sprintf("failed to get tx, error: %s", err)) } - return res.Status.String(), nil + + defer func() { + if innerErr := dbTx.Rollback(ctx); innerErr != nil { + result = "0x0" + err = types.NewRPCError(types.DefaultErrorCode, fmt.Sprintf("failed to rollback dbTx, error: %s", err)) + } + }() + + result = res.Status.String() + + return result, err }