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    pub struct Switch: u32 {
18        /// None of verifier will be disabled
19        const NONE                      = 0b00000000;
20
21        /// Disable epoch verifier
22        const DISABLE_EPOCH             = 0b00000001;
23
24        /// Disable uncle verifier
25        const DISABLE_UNCLES            = 0b00000010;
26
27        /// Disable two phase commit verifier
28        const DISABLE_TWO_PHASE_COMMIT  = 0b00000100;
29
30        /// Disable dao header verifier
31        const DISABLE_DAOHEADER         = 0b00001000;
32
33        /// Disable reward verifier
34        const DISABLE_REWARD            = 0b00010000;
35
36        /// Disable non-contextual verifier
37        const DISABLE_NON_CONTEXTUAL    = 0b00100000;
38
39        /// Disable script verification
40        const DISABLE_SCRIPT            = 0b01000000;
41
42        /// Disable extension verification
43        const DISABLE_EXTENSION         = 0b10000000;
44
45        /// Disable all verifier
46        const DISABLE_ALL               = Self::DISABLE_EPOCH.bits | Self::DISABLE_UNCLES.bits |
47                                    Self::DISABLE_TWO_PHASE_COMMIT.bits | Self::DISABLE_DAOHEADER.bits |
48                                    Self::DISABLE_REWARD.bits |
49                                    Self::DISABLE_NON_CONTEXTUAL.bits | Self::DISABLE_SCRIPT.bits |
50                                    Self::DISABLE_EXTENSION.bits;
51
52        /// Only script verification
53        const ONLY_SCRIPT               = Self::DISABLE_ALL.bits & (!Self::DISABLE_SCRIPT.bits);
54    }
55}
56
57impl Switch {
58    /// Whether all verifiers are disabled
59    pub fn disable_all(self) -> bool {
60        self.contains(Switch::DISABLE_ALL)
61    }
62
63    /// Whether non-contextual verifier is disabled
64    pub fn disable_non_contextual(self) -> bool {
65        self.contains(Switch::DISABLE_NON_CONTEXTUAL)
66    }
67
68    /// Whether epoch verifier is disabled
69    pub fn disable_epoch(&self) -> bool {
70        self.contains(Switch::DISABLE_EPOCH)
71    }
72
73    /// Whether uncles verifier is disabled
74    pub fn disable_uncles(&self) -> bool {
75        self.contains(Switch::DISABLE_UNCLES)
76    }
77
78    /// Whether two-phase-commit verifier is disabled
79    pub fn disable_two_phase_commit(&self) -> bool {
80        self.contains(Switch::DISABLE_TWO_PHASE_COMMIT)
81    }
82
83    /// Whether DAO-header verifier is disabled
84    pub fn disable_daoheader(&self) -> bool {
85        self.contains(Switch::DISABLE_DAOHEADER)
86    }
87
88    /// Whether reward verifier is disabled
89    pub fn disable_reward(&self) -> bool {
90        self.contains(Switch::DISABLE_REWARD)
91    }
92
93    /// Whether extension verifier is disabled
94    pub fn disable_extension(&self) -> bool {
95        self.contains(Switch::DISABLE_EXTENSION)
96    }
97
98    /// Whether script verifier is disabled
99    pub fn disable_script(&self) -> bool {
100        self.contains(Switch::DISABLE_SCRIPT)
101    }
102}