mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add exceeds allowance error message (#14232)
This commit is contained in:
@ -139,6 +139,16 @@ pub trait EstimateCall: Call {
|
||||
&mut db,
|
||||
))
|
||||
}
|
||||
Err(err) if err.is_gas_too_low() => {
|
||||
// This failed because the configured gas cost of the tx was lower than what
|
||||
// actually consumed by the tx This can happen if the
|
||||
// request provided fee values manually and the resulting gas cost exceeds the
|
||||
// sender's allowance, so we return the appropriate error here
|
||||
return Err(RpcInvalidTransactionError::GasRequiredExceedsAllowance {
|
||||
gas_limit: tx_env.gas_limit(),
|
||||
}
|
||||
.into_eth_err())
|
||||
}
|
||||
// Propagate other results (successful or other errors).
|
||||
ethres => ethres?,
|
||||
};
|
||||
|
||||
@ -338,6 +338,16 @@ pub enum RpcInvalidTransactionError {
|
||||
/// Current balance of transaction sender.
|
||||
balance: U256,
|
||||
},
|
||||
/// This is similar to [`Self::InsufficientFunds`] but with a different error message and
|
||||
/// exists for compatibility reasons.
|
||||
///
|
||||
/// This error is used in `eth_estimateCall` when the highest available gas limit, capped with
|
||||
/// the allowance of the caller is too low: [`Self::GasTooLow`].
|
||||
#[error("gas required exceeds allowance ({gas_limit})")]
|
||||
GasRequiredExceedsAllowance {
|
||||
/// The gas limit the transaction was executed with.
|
||||
gas_limit: u64,
|
||||
},
|
||||
/// Thrown when calculating gas usage
|
||||
#[error("gas uint64 overflow")]
|
||||
GasUintOverflow,
|
||||
@ -448,9 +458,10 @@ impl RpcInvalidTransactionError {
|
||||
/// Returns the rpc error code for this error.
|
||||
pub const fn error_code(&self) -> i32 {
|
||||
match self {
|
||||
Self::InvalidChainId | Self::GasTooLow | Self::GasTooHigh => {
|
||||
EthRpcErrorCode::InvalidInput.code()
|
||||
}
|
||||
Self::InvalidChainId |
|
||||
Self::GasTooLow |
|
||||
Self::GasTooHigh |
|
||||
Self::GasRequiredExceedsAllowance { .. } => EthRpcErrorCode::InvalidInput.code(),
|
||||
Self::Revert(_) => EthRpcErrorCode::ExecutionError.code(),
|
||||
_ => EthRpcErrorCode::TransactionRejected.code(),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user