use crate::grin_core::core::{committed, transaction};
use crate::grin_core::libtx;
use crate::grin_keychain;
use crate::grin_util::secp;
use crate::util;
use grin_store;
#[derive(Clone, Eq, PartialEq, Debug, thiserror::Error, Serialize, Deserialize)]
pub enum Error {
#[error("Not enough funds. Required: {needed_disp:?}, Available: {available_disp:?}")]
NotEnoughFunds {
available: u64,
available_disp: String,
needed: u64,
needed_disp: String,
},
#[error("Fee Error: {0}")]
Fee(String),
#[error("LibTx Error")]
LibTX(#[from] libtx::Error),
#[error("Keychain error")]
Keychain(#[from] grin_keychain::Error),
#[error("Transaction error")]
Transaction(#[from] transaction::Error),
#[error("Client Callback Error: {0}")]
ClientCallback(String),
#[error("Secp Lib Error")]
Secp(#[from] secp::Error),
#[error("Onion V3 Address Error: {0}")]
OnionV3Address(#[from] util::OnionV3AddressError),
#[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::grin_core::ser::Error),
#[error("I/O error {0}")]
IO(String),
#[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 {0} doesn't exist")]
TransactionDoesntExist(String),
#[error("Transaction {0} cannot be cancelled")]
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 {0} has already been received")]
TransactionAlreadyReceived(String),
#[error("Transaction {0} has been cancelled")]
TransactionWasCancelled(String),
#[error("Transaction building not completed: {0}")]
TransactionBuildingNotCompleted(u32),
#[error("Invalid BIP32 Depth (must be 1 or greater)")]
InvalidBIP32Depth,
#[error("Account Label '{0}' already exists")]
AccountLabelAlreadyExists(String),
#[error("Unknown Account Label '{0}'")]
UnknownAccountLabel(String),
#[error("Committed Error")]
Committed(committed::Error),
#[error("Committed Error: {0}")]
Commit(String),
#[error("Can't parse slate version")]
SlateVersionParse,
#[error("Can't Serialize slate")]
SlateSer,
#[error("Can't Deserialize slate")]
SlateDeser,
#[error("Invalid slate state")]
SlateState,
#[error("Can't Serialize slatepack")]
SlatepackSer,
#[error("Can't Deserialize slatepack: {0}")]
SlatepackDeser(String),
#[error("Unknown Slate Version: {0}")]
SlateVersion(u16),
#[error("Slate transaction required in this context")]
SlateTransactionRequired,
#[error("Can't downgrade slate: {0}")]
SlateInvalidDowngrade(String),
#[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("Kernel Features Arg {0} missing")]
KernelFeaturesMissing(String),
#[error("Unknown Kernel Feature: {0}")]
UnknownKernelFeatures(u8),
#[error("Invalid Kernel Feature: {0}")]
InvalidKernelFeatures(u8),
#[error("Invalid Slatepack Data: {0}")]
InvalidSlatepackData(String),
#[error("Couldn't encrypt Slatepack: {0}")]
SlatepackEncryption(String),
#[error("Couldn't decrypt Slatepack: {0}")]
SlatepackDecryption(String),
#[error("Age error: {0}")]
Age(String),
#[error("Rewind Hash error: {0}")]
RewindHash(String),
#[error("Nonce error: {0}")]
Nonce(String),
#[error("SlatepackAddress error: {0}")]
SlatepackAddress(String),
#[error("Stored Tx error: {0}")]
StoredTx(String),
#[error("Generic error: {0}")]
GenericError(String),
}
impl From<grin_store::Error> for Error {
fn from(error: grin_store::Error) -> Error {
Error::Backend(format!("{}", error))
}
}
impl From<age::EncryptError> for Error {
fn from(error: age::EncryptError) -> Error {
Error::Age(format!("{}", error))
}
}
impl From<age::DecryptError> for Error {
fn from(error: age::DecryptError) -> Error {
Error::Age(format!("{}", error))
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Error {
Error::IO(e.to_string())
}
}
impl From<&str> for Error {
fn from(error: &str) -> Error {
Error::Age(format!("Bech32 Key Encoding - {}", error))
}
}
impl From<bech32::Error> for Error {
fn from(error: bech32::Error) -> Error {
Error::SlatepackAddress(format!("{}", error))
}
}