ckb_verification_traits/
lib.rs

1#![allow(clippy::bad_bit_mask)]
2
3//! The trait abstract for particular verification
4use bitflags::bitflags;
5use ckb_error::Error;
6
7/// Trait for verification
8pub trait Verifier {
9    /// The verification associated target
10    type Target;
11    /// The Interface for verification
12    fn verify(&self, target: &Self::Target) -> Result<(), Error>;
13}
14
15bitflags! {
16    /// The bit flags for particular process block verify
17    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
18    pub struct Switch: u32 {
19        /// None of verifier will be disabled
20        const NONE                      = 0b00000000;
21
22        /// Disable epoch verifier
23        const DISABLE_EPOCH             = 0b00000001;
24
25        /// Disable uncle verifier
26        const DISABLE_UNCLES            = 0b00000010;
27
28        /// Disable two phase commit verifier
29        const DISABLE_TWO_PHASE_COMMIT  = 0b00000100;
30
31        /// Disable dao header verifier
32        const DISABLE_DAOHEADER         = 0b00001000;
33
34        /// Disable reward verifier
35        const DISABLE_REWARD            = 0b00010000;
36
37        /// Disable non-contextual verifier
38        const DISABLE_NON_CONTEXTUAL    = 0b00100000;
39
40        /// Disable script verification
41        const DISABLE_SCRIPT            = 0b01000000;
42
43        /// Disable extension verification
44        const DISABLE_EXTENSION         = 0b10000000;
45
46        /// Disable all verifier
47        const DISABLE_ALL               = Self::DISABLE_EPOCH.bits() | Self::DISABLE_UNCLES.bits() |
48                                    Self::DISABLE_TWO_PHASE_COMMIT.bits() | Self::DISABLE_DAOHEADER.bits() |
49                                    Self::DISABLE_REWARD.bits() |
50                                    Self::DISABLE_NON_CONTEXTUAL.bits() | Self::DISABLE_SCRIPT.bits() |
51                                    Self::DISABLE_EXTENSION.bits();
52
53        /// Only script verification
54        const ONLY_SCRIPT               = Self::DISABLE_ALL.bits() & (!Self::DISABLE_SCRIPT.bits());
55    }
56}
57
58impl Switch {
59    /// Whether all verifiers are disabled
60    pub fn disable_all(self) -> bool {
61        self.contains(Switch::DISABLE_ALL)
62    }
63
64    /// Whether non-contextual verifier is disabled
65    pub fn disable_non_contextual(self) -> bool {
66        self.contains(Switch::DISABLE_NON_CONTEXTUAL)
67    }
68
69    /// Whether epoch verifier is disabled
70    pub fn disable_epoch(&self) -> bool {
71        self.contains(Switch::DISABLE_EPOCH)
72    }
73
74    /// Whether uncles verifier is disabled
75    pub fn disable_uncles(&self) -> bool {
76        self.contains(Switch::DISABLE_UNCLES)
77    }
78
79    /// Whether two-phase-commit verifier is disabled
80    pub fn disable_two_phase_commit(&self) -> bool {
81        self.contains(Switch::DISABLE_TWO_PHASE_COMMIT)
82    }
83
84    /// Whether DAO-header verifier is disabled
85    pub fn disable_daoheader(&self) -> bool {
86        self.contains(Switch::DISABLE_DAOHEADER)
87    }
88
89    /// Whether reward verifier is disabled
90    pub fn disable_reward(&self) -> bool {
91        self.contains(Switch::DISABLE_REWARD)
92    }
93
94    /// Whether extension verifier is disabled
95    pub fn disable_extension(&self) -> bool {
96        self.contains(Switch::DISABLE_EXTENSION)
97    }
98
99    /// Whether script verifier is disabled
100    pub fn disable_script(&self) -> bool {
101        self.contains(Switch::DISABLE_SCRIPT)
102    }
103}