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

Commit

Permalink
Introduce lint analysis GH workflow (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal authored Nov 23, 2023
1 parent e7472b7 commit 3f3e31e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 33 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 0 additions & 24 deletions etherman/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package etherman

import (
"errors"
"strings"
)

var (
Expand All @@ -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
}
30 changes: 21 additions & 9 deletions rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 3f3e31e

Please sign in to comment.