1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! Common error types.

/// Error type for cell related errors.
#[derive(Debug, Clone, Eq, PartialEq, thiserror::Error)]
pub enum Error {
    /// There were not enough bits or refs in the cell slice.
    #[error("cell underflow")]
    CellUnderflow,
    /// There were not enough bits or refs capacity in the cell builder.
    #[error("cell overflow")]
    CellOverflow,
    /// Something tried to load a pruned branch cell.
    #[error("pruned branch access")]
    PrunedBranchAccess,
    /// Cell contains invalid descriptor or data.
    #[error("invalid cell")]
    InvalidCell,
    /// Data does not satisfy some constraints.
    #[error("invalid data")]
    InvalidData,
    /// Unknown TLB tag.
    #[error("invalid tag")]
    InvalidTag,
    /// Merkle proof does not contain the root cell.
    #[error("empty proof")]
    EmptyProof,
    /// Tree of cells is too deep.
    #[error("cell depth overflow")]
    DepthOverflow,
    /// Signature check failed.
    #[error("invalid signature")]
    InvalidSignature,
}

/// Error type for integer parsing related errors.
#[derive(Debug, Clone, thiserror::Error)]
pub enum ParseIntError {
    /// Error while parsing underlying type.
    #[error("cannot parse underlying integer")]
    InvalidString(#[source] std::num::ParseIntError),
    /// Underlying integer type does not fit into the target type.
    #[error("underlying integer is too large to fin in target type")]
    Overflow,
}

/// Error type for hash bytes parsing related errors.
#[derive(Debug, Clone, thiserror::Error)]
pub enum ParseHashBytesError {
    /// Failed to parse base64 encoded bytes.
    #[error("invalid base64 string")]
    InvalidBase64(#[from] base64::DecodeSliceError),
    /// Failed to parse hex encoded bytes.
    #[error("invalid hex string")]
    InvalidHex(#[from] hex::FromHexError),
    /// Error for an unexpected string length.
    #[error("expected string of 44, 64 or 66 bytes")]
    UnexpectedStringLength,
}

/// Error type for address parsing related errors.
#[derive(Debug, Clone, thiserror::Error)]
pub enum ParseAddrError {
    /// Tried to parse an empty string.
    #[error("cannot parse address from an empty string")]
    Empty,
    /// Workchain id is too large.
    #[error("workchain id is too large to fit in target type")]
    InvalidWorkchain,
    /// Invalid account id hex.
    #[error("cannot parse account id")]
    InvalidAccountId,
    /// Too many address parts.
    #[error("unexpected address part")]
    UnexpectedPart,
}

/// Error type for block id parsing related errors.
#[derive(Debug, Clone, thiserror::Error)]
pub enum ParseBlockIdError {
    /// Tried to parse an empty string.
    #[error("cannot parse block id from an empty string")]
    Empty,
    /// Workchain id is too large.
    #[error("cannot parse workchain id")]
    InvalidWorkchain,
    /// Invalid workchain or shard prefix.
    #[error("invalid shard id")]
    InvalidShardIdent,
    /// Invalid block seqno.
    #[error("cannot parse block seqno")]
    InvalidSeqno,
    /// Invalid root hash hex.
    #[error("cannot parse root hash")]
    InvalidRootHash,
    /// Invalid file hash hex.
    #[error("cannot parse file hash")]
    InvalidFileHash,
    /// Too many block id parts.
    #[error("unexpected block id part")]
    UnexpectedPart,
}