use super::RpcError;
#[derive(Debug, thiserror::Error)]
pub enum RetrievalError {
#[error("Missing blockchain data: {field}")]
MissingBlockchainData {
field: String,
},
#[error("Event decode failed: {details}")]
EventDecodeFailed {
details: String,
},
#[error("Conversion failed: {details}")]
ConversionFailed {
details: String,
},
#[error("RPC error: {0}")]
Rpc(#[from] RpcError),
}
impl RetrievalError {
pub fn missing_blockchain_data(field: impl Into<String>) -> Self {
RetrievalError::MissingBlockchainData {
field: field.into(),
}
}
pub fn event_decode_failed(details: impl Into<String>) -> Self {
RetrievalError::EventDecodeFailed {
details: details.into(),
}
}
pub fn conversion_failed(details: impl Into<String>) -> Self {
RetrievalError::ConversionFailed {
details: details.into(),
}
}
pub fn missing_transaction_hash() -> Self {
Self::missing_blockchain_data("transaction_hash")
}
pub fn missing_block_number() -> Self {
Self::missing_blockchain_data("block_number")
}
pub fn missing_transaction(tx_hash: &str) -> Self {
Self::missing_blockchain_data(format!("transaction for hash {}", tx_hash))
}
pub fn missing_receipt(tx_hash: &str) -> Self {
Self::missing_blockchain_data(format!("receipt for transaction {}", tx_hash))
}
pub fn bigdecimal_conversion_failed(value: impl std::fmt::Display) -> Self {
Self::conversion_failed(format!("Failed to convert {} to BigDecimal", value))
}
}