use std::fmt;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("invalid base58: {0}")]
Base58(String),
#[error("checksum mismatch: {0}")]
Checksum(&'static str),
#[error("invalid key: {0}")]
Key(String),
#[error("invalid signature: {0}")]
Signature(String),
#[error("serialization: {0}")]
Serialization(String),
#[error("unknown {kind}: {name}")]
Unknown {
kind: &'static str,
name: String,
},
#[error("field error: {0}")]
Field(String),
#[error("invalid time: {0}")]
Time(String),
#[error("TaPoS reference is stale: {0}")]
StaleTapos(String),
#[error("memo: {0}")]
Memo(String),
#[error("rpc: {0}")]
Rpc(String),
#[error("rpc error {code}: {message}")]
RpcResponse {
code: i64,
message: String,
},
#[error("chain: {0}")]
Chain(String),
}
impl Error {
pub(crate) fn key(msg: impl fmt::Display) -> Self {
Error::Key(msg.to_string())
}
pub(crate) fn sig(msg: impl fmt::Display) -> Self {
Error::Signature(msg.to_string())
}
pub(crate) fn ser(msg: impl fmt::Display) -> Self {
Error::Serialization(msg.to_string())
}
pub(crate) fn field(msg: impl fmt::Display) -> Self {
Error::Field(msg.to_string())
}
}
impl From<bs58::decode::Error> for Error {
fn from(e: bs58::decode::Error) -> Self {
Error::Base58(e.to_string())
}
}
impl From<secp256k1::Error> for Error {
fn from(e: secp256k1::Error) -> Self {
Error::Signature(e.to_string())
}
}