1use ant_protocol::PrettyPrintRecordKey;
10use libp2p::PeerId;
11use thiserror::Error;
12
13pub(super) type Result<T, E = Error> = std::result::Result<T, E>;
14
15const SCRATCHPAD_MAX_SIZE: usize = ant_protocol::storage::Scratchpad::MAX_SIZE;
16
17#[derive(Debug, Error)]
19#[allow(missing_docs)]
20pub enum PutValidationError {
21 #[error("Error while requesting data from the local swarm")]
22 LocalSwarmError,
23
24 #[error("The record header cannot be deserialized")]
25 InvalidRecordHeader,
26
27 #[error("The record cannot be deserialized to the expected type")]
28 InvalidRecord(PrettyPrintRecordKey<'static>),
29
30 #[error("The Record::key does not match with the key derived from Record::value")]
31 RecordKeyMismatch,
32
33 #[error("Failed to serialize the record")]
34 RecordSerializationFailed(PrettyPrintRecordKey<'static>),
35
36 #[error("The record did not contain any payments: {0:?}")]
38 NoPayment(PrettyPrintRecordKey<'static>),
39
40 #[error("Record should not be a `WithPayment` type: {0:?}")]
42 UnexpectedRecordWithPayment(PrettyPrintRecordKey<'static>),
43
44 #[error("Our node did not receive any payment for record: {0:?}")]
45 PaymentNotMadeToOurNode(PrettyPrintRecordKey<'static>),
46
47 #[error("The payment was made to an incorrect data type: {0:?}")]
48 PaymentMadeToIncorrectDataType(PrettyPrintRecordKey<'static>),
49
50 #[error(
51 "The payment quote has out of range payees for record: {record_key:?}. Payees: {payees:?}"
52 )]
53 PaymentQuoteOutOfRange {
54 record_key: PrettyPrintRecordKey<'static>,
55 payees: Vec<PeerId>,
56 },
57
58 #[error(
59 "Failed to verify payment with EVM network for record: {record_key:?}. Error: {error}"
60 )]
61 PaymentVerificationFailed {
62 record_key: PrettyPrintRecordKey<'static>,
63 error: ant_evm::payment_vault::error::Error,
64 },
65
66 #[error("Chunk is too large: {0} bytes, when max size is {1} bytes")]
68 OversizedChunk(usize, usize),
69
70 #[error("A newer version of this Scratchpad already exists")]
72 IgnoringOutdatedScratchpadPut,
73
74 #[error("Scratchpad signature is invalid")]
75 InvalidScratchpadSignature,
76
77 #[error("Scratchpad too big: {0}, max size is {SCRATCHPAD_MAX_SIZE}")]
78 ScratchpadTooBig(usize),
79
80 #[error("There are no GraphEntries in the record: {0:?}")]
82 EmptyGraphEntry(PrettyPrintRecordKey<'static>),
83
84 #[error("Pointer signature is invalid")]
86 InvalidPointerSignature,
87}
88
89#[derive(Debug, Error)]
91#[allow(missing_docs)]
92pub enum Error {
93 #[error("Network error {0}")]
94 Network(#[from] ant_networking::NetworkError),
95
96 #[error("Failed to parse NodeEvent")]
97 NodeEventParsingFailed,
98
99 #[error("Failed to obtain node's current port")]
100 FailedToGetNodePort,
101
102 #[error("The content of the payment quote is invalid")]
104 InvalidQuoteContent,
105
106 #[error("The payment quote's signature is invalid")]
107 InvalidQuoteSignature,
108}