mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-03-04 02:23:48 +00:00
internal/ethapi: move handling of revert out of docall
This commit is contained in:
parent
9f8a0b597e
commit
7b6fbcadc3
2 changed files with 26 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue