From 7b6fbcadc311be2b535ea5b6edc27e92d39286f7 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Fri, 22 May 2020 10:59:19 +0200 Subject: [PATCH] internal/ethapi: move handling of revert out of docall --- graphql/graphql.go | 21 +++++++++++++++++++-- internal/ethapi/api.go | 14 +++++++------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/graphql/graphql.go b/graphql/graphql.go index 9555d8cce2..548000271c 100644 --- a/graphql/graphql.go +++ b/graphql/graphql.go @@ -23,6 +23,7 @@ import ( "time" "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/rawdb" @@ -811,8 +812,16 @@ func (b *Block) Call(ctx context.Context, args struct { if result.Failed() { status = 0 } + data := result.Return() + // If the result contains a revert reason, try to unpack and return it. + if len(result.Revert()) > 0 { + reason, err := abi.UnpackRevert(result.Revert()) + if err == nil { + data = []byte(reason) + } + } return &CallResult{ - data: result.Return(), + data: data, gasUsed: hexutil.Uint64(result.UsedGas), status: status, }, nil @@ -880,8 +889,16 @@ func (p *Pending) Call(ctx context.Context, args struct { if result.Failed() { status = 0 } + data := result.Return() + // If the result contains a revert reason, try to unpack and return it. + if len(result.Revert()) > 0 { + reason, err := abi.UnpackRevert(result.Revert()) + if err == nil { + data = []byte(reason) + } + } return &CallResult{ - data: result.Return(), + data: data, gasUsed: hexutil.Uint64(result.UsedGas), status: status, }, nil diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index d6c0fa4c50..0a25cdc70c 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -861,13 +861,6 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo if evm.Cancelled() { return nil, fmt.Errorf("execution aborted (timeout = %v)", timeout) } - // If the result contains a revert reason, try to unpack and return it. - if len(result.Revert()) > 0 { - reason, err := abi.UnpackRevert(result.Revert()) - if err == nil { - return nil, fmt.Errorf("execution reverted: %v", reason) - } - } return result, err } @@ -886,6 +879,13 @@ func (s *PublicBlockChainAPI) Call(ctx context.Context, args CallArgs, blockNrOr if err != nil { return nil, err } + // If the result contains a revert reason, try to unpack and return it. + if len(result.Revert()) > 0 { + reason, err := abi.UnpackRevert(result.Revert()) + if err == nil { + return nil, fmt.Errorf("execution reverted: %v", reason) + } + } return result.Return(), nil }