use crate::{
storage::{RecordKind, RegisterAddress, SpendAddress},
NetworkAddress, PrettyPrintRecordKey,
};
use serde::{Deserialize, Serialize};
use sn_transfers::{NanoTokens, SignedSpend};
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Clone, PartialEq, Eq, Serialize, Deserialize, custom_debug::Debug)]
#[non_exhaustive]
pub enum Error {
#[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("Register was not stored: {0}")]
RegisterNotStored(Box<RegisterAddress>),
#[error("Register not found: {0}")]
RegisterNotFound(Box<RegisterAddress>),
#[error("Register is Invalid: {0}")]
RegisterInvalid(Box<RegisterAddress>),
#[error("Register is Invalid: {0}")]
RegisterError(#[from] sn_registers::Error),
#[error("The Register was already created by another owner: {0:?}")]
RegisterAlreadyClaimed(bls::PublicKey),
#[error("Spend not found: {0:?}")]
SpendNotFound(SpendAddress),
#[error("Failed to store spend: {0:?}")]
SpendNotStored(String),
#[error("A double spend was detected. Two diverging signed spends: {0:?}, {1:?}")]
DoubleSpendAttempt(Box<SignedSpend>, Box<SignedSpend>),
#[error("Spend signature is invalid: {0}")]
SpendSignatureInvalid(String),
#[error("Invalid Parent Tx: {0}")]
SpendParentTxInvalid(String),
#[error("CashNote Spend is empty")]
SpendIsEmpty,
#[error("Total tokens exceeds what is possible on the network.")]
PaymentExceedsTotalTokens,
#[error("There was an error getting the storecost from kademlia store")]
GetStoreCostFailed,
#[error("The amount paid by payment proof is not the required for the received content, paid {paid}, expected {expected}")]
PaymentProofInsufficientAmount {
paid: NanoTokens,
expected: NanoTokens,
},
#[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("Payments received could not be stored on node's local wallet: {0}")]
FailedToStorePaymentIntoNodeWallet(String),
#[error("Failed to decypher transfer, we probably are not the recipient")]
FailedToDecypherTransfer,
#[error("Failed to encrypt transfer")]
FailedToEncryptTransfer,
#[error("Failed to get transfer parent spend")]
FailedToGetTransferParentSpend,
#[error("Transfer is invalid: {0}")]
InvalidTransfer(String),
#[error("Peer {holder:?} cannot find Record {key:?}")]
ReplicatedRecordNotFound {
holder: Box<NetworkAddress>,
key: Box<NetworkAddress>,
},
#[error("Record was not stored: {0:?}: {1:?}")]
RecordNotStored(PrettyPrintRecordKey<'static>, String),
#[error("Could not Serialize/Deserialize RecordHeader to/from Record")]
RecordHeaderParsingFailed,
#[error("Could not Serialize/Deserialize Record")]
RecordParsingFailed,
#[error("The Record::key does not match with the key derived from Record::value")]
RecordKeyMismatch,
#[error("The RecordKind obtained from the Record did not match with the expected kind: {0}")]
RecordKindMismatch(RecordKind),
#[error("The record already exists, so do not charge for it: {0:?}")]
RecordExists(PrettyPrintRecordKey<'static>),
}