Skip to main content

nectar_postage/
error.rs

1//! Error types for postage operations.
2
3use crate::BatchId;
4use alloy_primitives::Address;
5use thiserror::Error;
6
7/// Errors that can occur when working with stamps.
8#[non_exhaustive]
9#[derive(Debug, Clone, PartialEq, Eq, Error)]
10pub enum StampError {
11    /// The owner recovered from the signature doesn't match the batch owner.
12    #[error("owner mismatch: expected {expected}, got {actual}")]
13    OwnerMismatch {
14        /// The expected owner address.
15        expected: Address,
16        /// The actual owner recovered from the signature.
17        actual: Address,
18    },
19
20    /// The stamp index exceeds the maximum allowed for the batch depth.
21    #[error("invalid index: index exceeds batch capacity")]
22    InvalidIndex,
23
24    /// The chunk address doesn't match the expected collision bucket.
25    #[error("bucket mismatch: chunk address doesn't belong to stamp bucket")]
26    BucketMismatch,
27
28    /// The batch was not found.
29    #[error("batch not found: {0}")]
30    BatchNotFound(BatchId),
31
32    /// The batch is not yet usable (needs more confirmations).
33    #[error(
34        "batch not usable: created at block {created}, current block {current}, need {threshold} confirmations"
35    )]
36    BatchNotUsable {
37        /// Block when batch was created.
38        created: u64,
39        /// Current block number.
40        current: u64,
41        /// Required confirmations.
42        threshold: u64,
43    },
44
45    /// The batch has expired.
46    #[error("batch expired: value {value} <= total_amount {total_amount}")]
47    BatchExpired {
48        /// Current batch value.
49        value: u128,
50        /// Total amount consumed.
51        total_amount: u128,
52    },
53
54    /// Invalid stamp data format.
55    #[error("invalid stamp data: {0}")]
56    InvalidData(&'static str),
57
58    /// The batch bucket is full and cannot accept more chunks.
59    #[error("bucket full: bucket {bucket} has reached capacity {capacity}")]
60    BucketFull {
61        /// The bucket that is full.
62        bucket: u32,
63        /// Maximum capacity of the bucket.
64        capacity: u32,
65    },
66
67    /// Signature verification failed.
68    #[error("invalid signature")]
69    InvalidSignature,
70
71    /// A chunk operation in `nectar-primitives` failed (for example decoding or
72    /// address verification of the chunk half of a stamped chunk).
73    ///
74    /// The variant carries a `&'static str` context rather than embedding the
75    /// underlying [`nectar_primitives::PrimitivesError`]: [`StampError`] is
76    /// `Clone`, `PartialEq` and `Eq`, whereas `PrimitivesError` is none of these
77    /// (it carries `std::io::Error` among others), and this crate is `no_std`
78    /// without `alloc`, so an owned `String` message is not available either.
79    #[error("chunk error: {0}")]
80    Chunk(&'static str),
81}