internal/ethapi: move handling of revert out of docall

This commit is contained in:
Marius van der Wijden 2020-05-22 10:59:19 +02:00 committed by Péter Szilágyi
parent 9f8a0b597e
commit 7b6fbcadc3
No known key found for this signature in database
GPG key ID: E9AE538CEDF8293D
2 changed files with 26 additions and 9 deletions

View file

@ -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

View file

@ -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
}