use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error("HTTP request failed: {0}")]
HttpRequest(#[from] reqwest::Error),
#[error("BscScan API error: {message}")]
ApiError { message: String },
#[error("Rate limit exceeded. Please retry after some time")]
RateLimitExceeded,
#[error("Invalid configuration: {0}")]
InvalidConfig(String),
#[error("Invalid address format: {0}")]
InvalidAddress(String),
#[error("Invalid transaction hash: {0}")]
InvalidTxHash(String),
#[error("Transaction not found: {0}")]
TransactionNotFound(String),
#[error("Payment verification failed: {0}")]
VerificationFailed(String),
#[error("Amount mismatch: expected {expected}, found {actual}")]
AmountMismatch { expected: String, actual: String },
#[error("Recipient mismatch: expected {expected}, found {actual}")]
RecipientMismatch { expected: String, actual: String },
#[error("Token contract mismatch: expected {expected}, found {actual}")]
TokenMismatch { expected: String, actual: String },
#[error("Insufficient confirmations: {current}/{required}")]
InsufficientConfirmations { current: u64, required: u64 },
#[error("Payment timeout: no transaction found within {0} seconds")]
PaymentTimeout(u64),
#[error("Serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("Cache error: {0}")]
CacheError(String),
#[cfg(any(feature = "postgres-storage", feature = "sqlite-storage"))]
#[error("Storage error: {0}")]
StorageError(#[from] sqlx::Error),
#[error("{0}")]
Generic(String),
}
impl Error {
pub fn api_error(message: impl Into<String>) -> Self {
Self::ApiError {
message: message.into(),
}
}
pub fn verification_failed(message: impl Into<String>) -> Self {
Self::VerificationFailed(message.into())
}
pub fn generic(message: impl Into<String>) -> Self {
Self::Generic(message.into())
}
}