use sn_evm::AttoTokens;
use sn_protocol::{NetworkAddress, PrettyPrintRecordKey};
use sn_transfers::WalletError;
use thiserror::Error;
pub(super) type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("Network error {0}")]
Network(#[from] sn_networking::NetworkError),
#[error("Protocol error {0}")]
Protocol(#[from] sn_protocol::Error),
#[error("Register error {0}")]
Register(#[from] sn_registers::Error),
#[error("WalletError error {0}")]
Wallet(#[from] WalletError),
#[error("Transfers Error {0}")]
Transfers(#[from] sn_evm::EvmError),
#[error("Failed to parse NodeEvent")]
NodeEventParsingFailed,
#[error("Failed to send a cmd to the node: {0}")]
NodeCmdFailed(String),
#[error("Overflow occurred while adding values")]
NumericOverflow,
#[error("Record was not stored as no payment supplied: {0:?}")]
InvalidPutWithoutPayment(PrettyPrintRecordKey<'static>),
#[error("Record should not be a `WithPayment` type: {0:?}")]
UnexpectedRecordWithPayment(PrettyPrintRecordKey<'static>),
#[error("The Record::key does not match with the key derived from Record::value")]
RecordKeyMismatch,
#[error("A newer version of this Scratchpad already exists")]
IgnoringOutdatedScratchpadPut,
#[error("Scratchpad signature is invalid over the counter + content hash")]
InvalidScratchpadSignature,
#[error("The content of the payment quote is invalid")]
InvalidQuoteContent,
#[error("The payment quote's signature is invalid")]
InvalidQuoteSignature,
#[error("The payment quote expired for {0:?}")]
QuoteExpired(NetworkAddress),
#[error(
"Payment proof received with record:{0:?}. No payment for our node in its transaction"
)]
NoPaymentToOurNode(PrettyPrintRecordKey<'static>),
#[error("Missing network royalties payment in proof received with record: {0:?}.")]
NoNetworkRoyaltiesPayment(PrettyPrintRecordKey<'static>),
#[error("The amount paid by payment proof is not the required for the received content, paid {paid}, expected {expected}")]
PaymentProofInsufficientAmount {
paid: AttoTokens,
expected: AttoTokens,
},
#[error("A payment we received contains cash notes already confirmed to be spent")]
ReusedPayment,
#[error("Failed to generate a reward key")]
FailedToGenerateRewardKey,
#[error("Failed to obtain node's current port")]
FailedToGetNodePort,
#[error("Invalid request: {0}")]
InvalidRequest(String),
#[error("Error occured in async thread: {0}")]
JoinErrorInAsyncThread(String),
#[error("EVM Network error: {0}")]
EvmNetwork(String),
#[error("Invalid quote timestamp: {0}")]
InvalidQuoteTimestamp(String),
}