use crate::storage::{
registers::{EntryHash, User},
ChunkAddress, DbcAddress, RegisterAddress,
};
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 w/ xorname {0:?}")]
ChunkNotStored(XorName),
#[error("Register not found: {0:?}")]
RegisterNotFound(RegisterAddress),
#[error("Register operation was not stored: {0:?}")]
RegisterCmdNotStored(RegisterAddress),
#[error(
"The CRDT operation cannot be applied since the Register operation destination address ({dst_addr:?}) \
doesn't match the targeted Register's address: {reg_addr:?}"
)]
RegisterAddrMismatch {
dst_addr: RegisterAddress,
reg_addr: RegisterAddress,
},
#[error("Access denied for user: {0:?}")]
AccessDenied(User),
#[error("Entry is too big to fit inside a register: {size}, max: {max}")]
EntryTooBig {
size: usize,
max: usize,
},
#[error("Cannot add another entry since the register entry cap has been reached: {0}")]
TooManyEntries(usize),
#[error("Requested entry not found {0}")]
NoSuchEntry(EntryHash),
#[error("Requested user not found {0:?}")]
NoSuchUser(User),
#[error("Provided PublicKey could not validate signature: {0:?}")]
InvalidSignature(bls::PublicKey),
#[error("Spend not found: {0:?}")]
SpendNotFound(DbcAddress),
#[error("Insufficient valid spends found: {0:?}")]
InsufficientValidSpendsFound(DbcAddress),
#[error("Failed to store spend: {0:?}")]
FailedToStoreSpend(DbcAddress),
#[error("Failed to get spend: {0:?}")]
FailedToGetSpend(DbcAddress),
#[error("A double spend was detected. Two diverging signed spends: {0:?}, {1:?}")]
DoubleSpendAttempt(Box<SignedSpend>, Box<SignedSpend>),
#[error("Spend signature is invalid: {0}")]
InvalidSpendSignature(String),
#[error("Spend parents are invalid: {0}")]
InvalidSpendParents(String),
#[error(
"The signed spend src tx ({signed_src_tx_hash:?}) did not match a valid parent's dst tx hash: {parent_dst_tx_hash:?}. The trail is invalid."
)]
TxTrailMismatch {
signed_src_tx_hash: Hash,
parent_dst_tx_hash: Hash,
},
#[error(
"The provided source tx (with hash {provided_src_tx_hash:?}) when verified with all supposed inputs to it (i.e. our spends parents).."
)]
InvalidSourceTxProvided {
signed_src_tx_hash: Hash,
provided_src_tx_hash: Hash,
},
}