rpc: internal/ethapi: added custom error types
This commit is contained in:
committed by
Péter Szilágyi
parent
ca35628cc2
commit
d77770d96e
@ -864,6 +864,21 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
|
||||
return result, err
|
||||
}
|
||||
|
||||
var _ rpc.DataError = (*revertError)(nil)
|
||||
|
||||
type revertError struct {
|
||||
err string // The error string
|
||||
errData interface{} // additional data
|
||||
}
|
||||
|
||||
func (e revertError) Error() string {
|
||||
return e.err
|
||||
}
|
||||
|
||||
func (e revertError) ErrorData() interface{} {
|
||||
return e.errData
|
||||
}
|
||||
|
||||
// Call executes the given transaction on the state for the given block number.
|
||||
//
|
||||
// Additionally, the caller can specify a batch of contract for fields overriding.
|
||||
@ -883,12 +898,17 @@ func (s *PublicBlockChainAPI) Call(ctx context.Context, args CallArgs, blockNrOr
|
||||
if len(result.Revert()) > 0 {
|
||||
reason, err := abi.UnpackRevert(result.Revert())
|
||||
if err == nil {
|
||||
return nil, fmt.Errorf("execution reverted: %v", reason)
|
||||
return nil, &revertError{
|
||||
err: "execution reverted",
|
||||
errData: reason,
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.Return(), nil
|
||||
return result.Return(), result.Err
|
||||
}
|
||||
|
||||
var _ rpc.DataError = (*estimateGasError)(nil)
|
||||
|
||||
type estimateGasError struct {
|
||||
error string // Concrete error type if it's failed to estimate gas usage
|
||||
vmerr error // Additional field, it's non-nil if the given transaction is invalid
|
||||
@ -906,6 +926,10 @@ func (e estimateGasError) Error() string {
|
||||
return errMsg
|
||||
}
|
||||
|
||||
func (e estimateGasError) ErrorData() interface{} {
|
||||
return e.revert
|
||||
}
|
||||
|
||||
func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, gasCap *big.Int) (hexutil.Uint64, error) {
|
||||
// Binary search the gas requirement, as it may be higher than the amount used
|
||||
var (
|
||||
|
Reference in New Issue
Block a user