drive/error/
proof.rs

1use grovedb::query_result_type::Path;
2
3/// Proof errors
4#[derive(Debug, thiserror::Error)]
5pub enum ProofError {
6    /// Too many elements error
7    #[error("too many elements error: {0}")]
8    TooManyElements(&'static str),
9
10    /// Wrong element count error
11    #[error("wrong element count error expected: {expected} got: {got}")]
12    WrongElementCount {
13        /// The expected count
14        expected: usize,
15        /// The count we got
16        got: usize,
17    },
18
19    /// Overflow error
20    #[error("overflow error: {0}")]
21    Overflow(&'static str),
22
23    /// An incoherent result is akin to a corrupted code execution, the proof returned is said to
24    /// be valid, however data it possesses isn't what was asked for.
25    #[error("corrupted error: {0}")]
26    CorruptedProof(String),
27
28    /// The proof returned is said to be valid, data is what we asked for, but is not what was
29    /// expected, for example if we updated a contract, but we are getting back the old contract
30    #[error("incorrect proof error: {0}")]
31    IncorrectProof(String),
32
33    /// The proof returned is said to be valid, data is what we asked for, but is not what was
34    /// expected, for example we ask for token balance, and we get that the token does not exist.
35    /// UnexpectedResultProof is most likely is a User error.
36    /// IncorrectProof is most likely a system error.
37    #[error("unexpected result in proof error: {0}")]
38    UnexpectedResultProof(String),
39
40    /// The transition we are trying to prove was executed is invalid
41    #[error("invalid transition error: {0}")]
42    InvalidTransition(String),
43
44    /// The transition we are trying to prove has an unknown contract
45    #[error("unknown contract in documents batch transition error: {0}")]
46    UnknownContract(String),
47
48    /// The metadata we got back from platform is incorrect
49    #[error("invalid metadata: {0}")]
50    InvalidMetadata(String),
51
52    /// We are trying to callback to retrieve a contract, but there was an error
53    #[error("the contract could not be retrieved during verification: {0}")]
54    ErrorRetrievingContract(String),
55
56    /// We are missing a context requirement
57    #[error("missing context requirement error: {0}")]
58    MissingContextRequirement(String),
59
60    /// Incomplete proof error
61    #[error("incomplete proof error: {0}")]
62    IncompleteProof(&'static str),
63
64    /// Incorrect value size
65    #[error("incorrect value size error: {0}")]
66    IncorrectValueSize(&'static str),
67
68    /// Incorrect element path error
69    #[error("incorrect element path error")]
70    IncorrectElementPath {
71        /// The expected path
72        expected: Path,
73        /// The actual path
74        actual: Path,
75    },
76}
77#[allow(dead_code)]
78#[deprecated(note = "This function is marked as unused.")]
79#[allow(deprecated)]
80fn get_error_code(error: &ProofError) -> u32 {
81    match error {
82        ProofError::TooManyElements(_) => 6000,
83        ProofError::WrongElementCount { .. } => 6001,
84        ProofError::Overflow(_) => 6002,
85        ProofError::CorruptedProof(_) => 6003,
86        ProofError::IncompleteProof(_) => 6004,
87        ProofError::IncorrectValueSize(_) => 6005,
88        ProofError::IncorrectElementPath { .. } => 6006,
89        ProofError::IncorrectProof(_) => 6007,
90        ProofError::InvalidTransition(_) => 6008,
91        ProofError::UnknownContract(_) => 6009,
92        ProofError::ErrorRetrievingContract(_) => 6010,
93        ProofError::InvalidMetadata(_) => 6011,
94        ProofError::MissingContextRequirement(_) => 6012,
95        ProofError::UnexpectedResultProof(_) => 6013,
96    }
97}