use ant_protocol::PrettyPrintRecordKey;
use libp2p::PeerId;
use thiserror::Error;
pub(super) type Result<T, E = Error> = std::result::Result<T, E>;
const SCRATCHPAD_MAX_SIZE: usize = ant_protocol::storage::Scratchpad::MAX_SIZE;
#[derive(Debug, Error)]
#[allow(missing_docs)]
pub enum PutValidationError {
#[error("Error while requesting data from the local swarm")]
LocalSwarmError,
#[error("The record header cannot be deserialized")]
InvalidRecordHeader,
#[error("The record cannot be deserialized to the expected type")]
InvalidRecord(PrettyPrintRecordKey<'static>),
#[error("The Record::key does not match with the key derived from Record::value")]
RecordKeyMismatch,
#[error("Failed to serialize the record")]
RecordSerializationFailed(PrettyPrintRecordKey<'static>),
#[error("The record did not contain any payments: {0:?}")]
NoPayment(PrettyPrintRecordKey<'static>),
#[error("Record should not be a `WithPayment` type: {0:?}")]
UnexpectedRecordWithPayment(PrettyPrintRecordKey<'static>),
#[error("Our node did not receive any payment for record: {0:?}")]
PaymentNotMadeToOurNode(PrettyPrintRecordKey<'static>),
#[error("The payment was made to an incorrect data type: {0:?}")]
PaymentMadeToIncorrectDataType(PrettyPrintRecordKey<'static>),
#[error(
"The payment quote has out of range payees for record: {record_key:?}. Payees: {payees:?}"
)]
PaymentQuoteOutOfRange {
record_key: PrettyPrintRecordKey<'static>,
payees: Vec<PeerId>,
},
#[error(
"Failed to verify payment with EVM network for record: {record_key:?}. Error: {error}"
)]
PaymentVerificationFailed {
record_key: PrettyPrintRecordKey<'static>,
error: ant_evm::payment_vault::error::Error,
},
#[error("Chunk is too large: {0} bytes, when max size is {1} bytes")]
OversizedChunk(usize, usize),
#[error("A newer version of this Scratchpad already exists")]
IgnoringOutdatedScratchpadPut,
#[error("Scratchpad signature is invalid")]
InvalidScratchpadSignature,
#[error("Scratchpad too big: {0}, max size is {SCRATCHPAD_MAX_SIZE}")]
ScratchpadTooBig(usize),
#[error("There are no GraphEntries in the record: {0:?}")]
EmptyGraphEntry(PrettyPrintRecordKey<'static>),
#[error("Pointer signature is invalid")]
InvalidPointerSignature,
}
#[derive(Debug, Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("Network error {0}")]
Network(#[from] ant_networking::NetworkError),
#[error("Failed to parse NodeEvent")]
NodeEventParsingFailed,
#[error("Failed to obtain node's current port")]
FailedToGetNodePort,
#[error("The content of the payment quote is invalid")]
InvalidQuoteContent,
#[error("The payment quote's signature is invalid")]
InvalidQuoteSignature,
}