axon_tools/
error.rs

1use alloc::string::{String, ToString};
2
3#[allow(dead_code)]
4#[derive(Debug)]
5pub enum Error {
6    InvalidProofBlockHash,
7    NotEnoughSignatures,
8    VerifyMptProof,
9
10    #[cfg(feature = "hex")]
11    #[cfg_attr(doc_cfg, doc(cfg(feature = "hex")))]
12    Hex(faster_hex::Error),
13
14    #[cfg(feature = "proof")]
15    #[cfg_attr(doc_cfg, doc(cfg(feature = "proof")))]
16    Bls(blst::BLST_ERROR),
17
18    #[cfg(feature = "proof")]
19    #[cfg_attr(doc_cfg, doc(cfg(feature = "proof")))]
20    Trie(cita_trie::TrieError),
21}
22
23#[cfg(feature = "hex")]
24#[cfg_attr(doc_cfg, doc(cfg(feature = "hex")))]
25impl From<faster_hex::Error> for Error {
26    fn from(value: faster_hex::Error) -> Self {
27        Self::Hex(value)
28    }
29}
30
31#[cfg(feature = "proof")]
32#[cfg_attr(doc_cfg, doc(cfg(feature = "proof")))]
33impl From<blst::BLST_ERROR> for Error {
34    fn from(e: blst::BLST_ERROR) -> Self {
35        Self::Bls(e)
36    }
37}
38
39#[cfg(feature = "proof")]
40#[cfg_attr(doc_cfg, doc(cfg(feature = "proof")))]
41impl From<cita_trie::TrieError> for Error {
42    fn from(e: cita_trie::TrieError) -> Self {
43        Self::Trie(e)
44    }
45}
46
47impl ToString for Error {
48    fn to_string(&self) -> String {
49        match self {
50            Error::InvalidProofBlockHash => "Invalid proof block hash".to_string(),
51            Error::NotEnoughSignatures => "Not enough signatures".to_string(),
52            Error::VerifyMptProof => "Verify mpt proof".to_string(),
53            #[cfg(feature = "hex")]
54            Error::Hex(e) => alloc::format!("Hex error: {:?}", e),
55            #[cfg(feature = "proof")]
56            Error::Bls(e) => alloc::format!("Bls error: {:?}", e),
57            #[cfg(feature = "proof")]
58            Error::Trie(e) => alloc::format!("Trie error: {:?}", e),
59        }
60    }
61}