internal/ethapi: moved revert reason logic to doCall

This commit is contained in:
Marius van der Wijden
2020-05-15 09:30:54 +02:00
committed by Péter Szilágyi
parent fd70cfe87a
commit 6d13d42e71

View File

@ -861,8 +861,15 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
if evm.Cancelled() { if evm.Cancelled() {
return nil, fmt.Errorf("execution aborted (timeout = %v)", timeout) return nil, fmt.Errorf("execution aborted (timeout = %v)", timeout)
} }
// If the result contains a revert reason, unpack and return it.
return result, err if result.Err != nil {
reason, err := abi.UnpackRevert(result.Revert())
if err != nil {
return nil, err
}
return nil, fmt.Errorf("execution reverted: %v", reason)
}
return result, nil
} }
// Call executes the given transaction on the state for the given block number. // Call executes the given transaction on the state for the given block number.
@ -880,13 +887,6 @@ func (s *PublicBlockChainAPI) Call(ctx context.Context, args CallArgs, blockNrOr
if err != nil { if err != nil {
return nil, err return nil, err
} }
if result.Err != nil {
reason, err := abi.UnpackRevert(result.Revert())
if err != nil {
return result.Return(), err
}
return result.Return(), errors.New(reason)
}
return result.Return(), nil return result.Return(), nil
} }