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#[derive(Debug, Clone, PartialEq, Eq, Error)]
9pub enum StampError {
10    /// The owner recovered from the signature doesn't match the batch owner.
11    #[error("owner mismatch: expected {expected}, got {actual}")]
12    OwnerMismatch {
13        /// The expected owner address.
14        expected: Address,
15        /// The actual owner recovered from the signature.
16        actual: Address,
17    },
18
19    /// The stamp index exceeds the maximum allowed for the batch depth.
20    #[error("invalid index: index exceeds batch capacity")]
21    InvalidIndex,
22
23    /// The chunk address doesn't match the expected collision bucket.
24    #[error("bucket mismatch: chunk address doesn't belong to stamp bucket")]
25    BucketMismatch,
26
27    /// The batch was not found.
28    #[error("batch not found: {0}")]
29    BatchNotFound(BatchId),
30
31    /// The batch is not yet usable (needs more confirmations).
32    #[error(
33        "batch not usable: created at block {created}, current block {current}, need {threshold} confirmations"
34    )]
35    BatchNotUsable {
36        /// Block when batch was created.
37        created: u64,
38        /// Current block number.
39        current: u64,
40        /// Required confirmations.
41        threshold: u64,
42    },
43
44    /// The batch has expired.
45    #[error("batch expired: value {value} <= total_amount {total_amount}")]
46    BatchExpired {
47        /// Current batch value.
48        value: u128,
49        /// Total amount consumed.
50        total_amount: u128,
51    },
52
53    /// Invalid stamp data format.
54    #[error("invalid stamp data: {0}")]
55    InvalidData(&'static str),
56
57    /// The batch bucket is full and cannot accept more chunks.
58    #[error("bucket full: bucket {bucket} has reached capacity {capacity}")]
59    BucketFull {
60        /// The bucket that is full.
61        bucket: u32,
62        /// Maximum capacity of the bucket.
63        capacity: u32,
64    },
65
66    /// Signature verification failed.
67    #[error("invalid signature")]
68    InvalidSignature,
69}