use crate::epic_core::core::{committed, transaction};
use crate::epic_keychain;
use crate::epic_util::secp;
use std::io;
#[derive(Clone, Eq, PartialEq, Debug, thiserror::Error, Serialize, Deserialize)]
pub enum Error {
#[error(
"Not enough funds. Required: {}, Available: {}",
needed_disp,
available_disp
)]
NotEnoughFunds {
available: u64,
available_disp: String,
needed: u64,
needed_disp: String,
},
#[error("Fee Error: {}", _0)]
Fee(String),
#[error("LibTx Error: {}", _0)]
LibTX(String),
#[error("Keychain error")]
Keychain(epic_keychain::Error),
#[error("Transaction error")]
Transaction(transaction::Error),
#[error("Client Callback Error: {}", _0)]
ClientCallback(String),
#[error("Secp error")]
Secp(secp::Error),
#[error("Trait Implementation error")]
CallbackImpl(&'static str),
#[error("Wallet store error: {}", _0)]
Backend(String),
#[error("Restore Error")]
Restore,
#[error("JSON format error: {}", _0)]
Format(String),
#[error("Ser/Deserialization error")]
Deser(crate::epic_core::ser::Error),
#[error("I/O error")]
IO,
#[error("Node API error")]
Node,
#[error("Wallet Communication Error: {}", _0)]
WalletComms(String),
#[error("Hyper error")]
Hyper,
#[error("Uri parsing error")]
Uri,
#[error("Signature error: {}", _0)]
Signature(String),
#[error("{}", _0)]
APIEncryption(String),
#[error("Duplicate transaction ID error")]
DuplicateTransactionId,
#[error("Wallet seed exists error: {}", _0)]
WalletSeedExists(String),
#[error("Wallet seed doesn't exist error")]
WalletSeedDoesntExist,
#[error("Wallet seed decryption error")]
WalletSeedDecryption,
#[error("Transaction {} doesn't exist", _0)]
TransactionDoesntExist(String),
#[error("Transaction {} cannot be cancelled", _0)]
TransactionNotCancellable(String),
#[error("Cancellation Error: {}", _0)]
TransactionCancellationError(&'static str),
#[error("Tx dump Error: {}", _0)]
TransactionDumpError(&'static str),
#[error("Transaction already confirmed error")]
TransactionAlreadyConfirmed,
#[error("Transaction {} has already been received", _0)]
TransactionAlreadyReceived(String),
#[error("Transaction building not completed: {}", _0)]
TransactionBuildingNotCompleted(u32),
#[error("Invalid BIP32 Depth (must be 1 or greater)")]
InvalidBIP32Depth,
#[error("Account Label '{}' already exists", _0)]
AccountLabelAlreadyExists(String),
#[error("Unknown Account Label '{}'", _0)]
UnknownAccountLabel(String),
#[error("Committed Error")]
Committed(committed::Error),
#[error("Can't parse slate version")]
SlateVersionParse,
#[error("Can't Serialize slate")]
SlateSer,
#[error("Can't Deserialize slate")]
SlateDeser,
#[error("Unknown Slate Version: {}", _0)]
SlateVersion(u16),
#[error("Compatibility Error: {}", _0)]
Compatibility(String),
#[error("Keychain doesn't exist (has wallet been opened?)")]
KeychainDoesntExist,
#[error("Lifecycle Error: {}", _0)]
Lifecycle(String),
#[error("Supplied Keychain Mask Token is incorrect")]
InvalidKeychainMask,
#[error("Tor Process Error: {}", _0)]
TorProcess(String),
#[error("Tor Config Error: {}", _0)]
TorConfig(String),
#[error("Error generating ed25519 secret key: {}", _0)]
ED25519Key(String),
#[error("Payment Proof generation error: {}", _0)]
PaymentProof(String),
#[error("Payment Proof retrieval error: {}", _0)]
PaymentProofRetrieval(String),
#[error("Payment Proof parsing error: {}", _0)]
PaymentProofParsing(String),
#[error("Proof Address decoding: {}", _0)]
AddressDecoding(String),
#[error("Transaction Expired")]
TransactionExpired,
#[error("SQLite Error: {}", _0)]
SQLiteError(String),
#[error("Invalid base58 character!")]
InvalidBase58Character(char, usize),
#[error("Invalid base58 length")]
InvalidBase58Length,
#[error("Invalid base58 checksum")]
InvalidBase58Checksum,
#[error("Invalid base58 version bytes")]
InvalidBase58Version,
#[error("Invalid key")]
InvalidBase58Key,
#[error("Could not parse number from string")]
NumberParsingError,
#[error("Listener for {} closed", 0)]
ClosedListener(String),
#[error("Unable to encrypt message")]
Encryption,
#[error("Unable to decrypt message")]
Decryption,
#[error("Could not parse '{}' to a epicbox address", 0)]
EpicboxAddressParsingError(String),
#[error("Generic error: {}", _0)]
GenericError(String),
#[error("Request error: {0}")]
RequestError(String),
#[error("Invalid Arguments: {}", _0)]
ArgumentError(String),
#[error("Parsing IO error: {}", _0)]
IOError(String),
#[error("User Cancelled")]
CancelledError,
#[error("Too many unsuccessful attempts at reconnection")]
EpicboxReconnectLimit,
#[error("LibWallet Error: {}", _0)]
LibWallet(String),
#[error("NotFoundErr Error: {}", _0)]
NotFoundErr(String),
}
impl From<io::Error> for Error {
fn from(_error: io::Error) -> Error {
Error::IO
}
}
impl From<epic_keychain::Error> for Error {
fn from(error: epic_keychain::Error) -> Error {
Error::Keychain(error)
}
}
impl From<transaction::Error> for Error {
fn from(error: transaction::Error) -> Error {
Error::Transaction(error)
}
}
impl From<crate::epic_core::ser::Error> for Error {
fn from(error: crate::epic_core::ser::Error) -> Error {
Error::Deser(error)
}
}
impl From<secp::Error> for Error {
fn from(error: secp::Error) -> Error {
Error::Secp(error)
}
}
impl From<sqlite::Error> for Error {
fn from(error: sqlite::Error) -> Error {
Error::SQLiteError(format!("{}", error))
}
}
impl From<crate::epic_core::libtx::Error> for Error {
fn from(error: crate::epic_core::libtx::Error) -> Error {
Error::LibTX(format!("{}", error))
}
}
impl From<committed::Error> for Error {
fn from(error: committed::Error) -> Error {
Error::Committed(error)
}
}