#[cfg(feature = "bincode")]
use rialo_s_sdk::{hash::ParseHashError, pubkey::ParsePubkeyError};
use thiserror::Error;
#[derive(Debug, Clone)]
pub struct RpcErrorDetails {
pub status: Option<u16>,
pub code: i64,
pub message: String,
}
impl RpcErrorDetails {
pub fn new(status: Option<u16>, code: i64, message: String) -> Self {
Self {
status,
code,
message,
}
}
pub fn from_message(message: String) -> Self {
Self {
status: None,
code: 0,
message,
}
}
}
impl std::fmt::Display for RpcErrorDetails {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.message)
}
}
#[derive(Error, Debug)]
pub enum RialoError {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("RPC error: {0}")]
Rpc(RpcErrorDetails),
#[cfg(feature = "bincode")]
#[error("Pubkey error: {0}")]
ParsePubkey(#[from] ParsePubkeyError),
#[cfg(feature = "bincode")]
#[error("Invalid blockhash format: {0}")]
InvalidBlockhashFormat(#[from] ParseHashError),
#[cfg(not(feature = "bincode"))]
#[error("Pubkey error: {0}")]
ParsePubkeyError(String),
#[cfg(not(feature = "bincode"))]
#[error("Invalid blockhash format: {0}")]
InvalidBlockhashFormatError(String),
#[error("Keyring error: {0}")]
Keyring(String),
#[deprecated(since = "0.2.0", note = "Use Keyring variant instead")]
#[error("Wallet error: {0}")]
Wallet(String),
#[error("Config error: {0}")]
Config(String),
#[error("Transaction error: {0}")]
Transaction(String),
#[cfg(feature = "rpc-client")]
#[error("Network error: {0}")]
Network(#[from] reqwest::Error),
#[error("Password error: {0}")]
Password(String),
#[error("Encryption error: {0}")]
Encryption(String),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[cfg(feature = "hd-wallet")]
#[error("BIP32 error: {0}")]
Bip32(#[from] bip32::Error),
#[error("Invalid input: {0}")]
InvalidInput(String),
#[error("Serialization error: {0}")]
SerializationError(String),
#[error("Transaction confirmation timeout")]
TransactionTimeout,
}
pub type Result<T> = std::result::Result<T, RialoError>;