use super::RpcError;
#[derive(Debug, thiserror::Error)]
pub enum GasCalculationError {
#[error("Failed to decode event at log index {log_index}")]
EventDecodeFailed {
log_index: u64,
#[source]
source: alloy_sol_types::Error,
},
#[error("Missing required data: {field}")]
MissingData {
field: String,
},
#[error("Gas calculation failed: {details}")]
CalculationFailed {
details: String,
},
#[error("RPC error: {0}")]
Rpc(#[from] RpcError),
}
impl GasCalculationError {
pub fn event_decode_failed(log_index: u64, source: alloy_sol_types::Error) -> Self {
GasCalculationError::EventDecodeFailed { log_index, source }
}
pub fn missing_data(field: impl Into<String>) -> Self {
GasCalculationError::MissingData {
field: field.into(),
}
}
pub fn calculation_failed(details: impl Into<String>) -> Self {
GasCalculationError::CalculationFailed {
details: details.into(),
}
}
pub fn missing_transaction_hash() -> Self {
Self::missing_data("transaction_hash")
}
pub fn missing_block_number() -> Self {
Self::missing_data("block_number")
}
pub fn missing_transaction(tx_hash: &str) -> Self {
Self::missing_data(format!("transaction for hash {}", tx_hash))
}
pub fn missing_receipt(tx_hash: &str) -> Self {
Self::missing_data(format!("receipt for transaction {}", tx_hash))
}
}