internal/ethapi: unified handling of errors in DoEstimateGas

This commit is contained in:
Marius van der Wijden 2020-06-02 14:05:16 +02:00 committed by Péter Szilágyi
parent 693db4dc17
commit 5048fd1028
No known key found for this signature in database
GPG Key ID: E9AE538CEDF8293D
1 changed files with 7 additions and 10 deletions

View File

@ -999,19 +999,16 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash
}
if failed {
if result != nil && result.Err != vm.ErrOutOfGas {
var revert string
if len(result.Revert()) > 0 {
ret, err := abi.UnpackRevert(result.Revert())
if err != nil {
revert = hexutil.Encode(result.Revert())
} else {
revert = ret
reason, err := abi.UnpackRevert(result.Revert())
if err == nil {
return 0, &revertError{
error: errors.New("execution reverted"),
errData: reason,
}
}
return 0, revertError{
error: errors.New("always failing transaction"),
errData: revert,
}
return 0, result.Err
}
// Otherwise, the specified gas cap is too low
return 0, fmt.Errorf("gas required exceeds allowance (%d)", cap)