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

Commit

Permalink
deal with other evm errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-nguy committed Jul 26, 2021
1 parent f19da1e commit eec45d9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
8 changes: 7 additions & 1 deletion ethereum/rpc/namespaces/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/core/vm"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"math/big"
"strings"

Expand Down Expand Up @@ -560,7 +563,10 @@ func (e *PublicAPI) doCall(
}

if res.Failed() {
return nil, evmtypes.NewExecErrorWithReason(res.Ret, res.VmError)
if res.VmError != vm.ErrExecutionReverted.Error() {
return nil, status.Error(codes.Internal, res.VmError)
}
return nil, evmtypes.NewExecErrorWithReason(res.Ret)
}

return res, nil
Expand Down
4 changes: 2 additions & 2 deletions x/evm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ func (k Keeper) EstimateGas(c context.Context, req *types.EthCallRequest) (*type
}
if failed {
if result != nil && result.VmError != vm.ErrOutOfGas.Error() {
if result.Failed() {
return nil, evmtypes.NewExecErrorWithReason(result.Ret, result.VmError)
if result.VmError == vm.ErrExecutionReverted.Error() {
return nil, evmtypes.NewExecErrorWithReason(result.Ret)
}
return nil, status.Error(codes.Internal, result.VmError)
}
Expand Down
9 changes: 2 additions & 7 deletions x/evm/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,8 @@ var (

// NewExecErrorWithReason unpacks the revert return bytes and returns a wrapped error
// with the return reason.
func NewExecErrorWithReason(revertReason []byte, vmError string) *revertError {
var result []byte
result = nil
if vmError == vm.ErrExecutionReverted.Error() {
result = common.CopyBytes(revertReason)
}

func NewExecErrorWithReason(revertReason []byte) *revertError {
var result = common.CopyBytes(revertReason)
reason, errUnpack := abi.UnpackRevert(result)
err := errors.New("execution reverted")
if errUnpack == nil {
Expand Down

0 comments on commit eec45d9

Please sign in to comment.