use crate::{
storage::{ChunkAddress, DbcAddress, RecordKind, RegisterAddress},
NetworkAddress,
};
use serde::{Deserialize, Serialize};
use sn_dbc::{Hash, SignedSpend};
use thiserror::Error;
use xor_name::XorName;
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("Chunk not found: {0:?}")]
ChunkNotFound(ChunkAddress),
#[error("Chunk was not stored, xorname: {0:?}")]
ChunkNotStored(XorName),
#[error("Register was not stored, xorname: {0:?}")]
RegisterNotStored(XorName),
#[error("Register not found: {0:?}")]
RegisterNotFound(RegisterAddress),
#[error("Register is Invalid: {0:?}")]
RegisterInvalid(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(DbcAddress),
#[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("Dbc Spend is empty")]
SpendIsEmpty,
#[error("There was an error getting the storecost from kademlia store")]
GetStoreCostFailed,
#[error("There was an error signing the storecost from kademlia store")]
SignStoreCostFailed,
#[error("The amount paid by payment proof is not the required for the received content, paid {paid}, expected {expected}")]
PaymentProofInsufficientAmount { paid: usize, expected: usize },
#[error("At least one input of payment proof provided for {0:?} has a mismatching spend Tx")]
PaymentProofTxMismatch(XorName),
#[error("Payment proof received for {0:?} has no inputs in its transaction")]
PaymentProofWithoutInputs(XorName),
#[error("The id of the fee output found in a storage payment proof is invalid: {}", .0.to_hex())]
PaymentProofInvalidFeeOutput(Hash),
#[error("Payment proof provided deemed invalid for item's name {addr_name:?}: {reason}")]
InvalidPaymentProof {
addr_name: XorName,
reason: String,
},
#[error("Peer {holder:?} cannot find ReplicatedData {address:?}")]
ReplicatedDataNotFound {
holder: NetworkAddress,
address: NetworkAddress,
},
#[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),
}