ckb_verification_traits/
lib.rs1#![allow(clippy::bad_bit_mask)]
2
3use bitflags::bitflags;
5use ckb_error::Error;
6
7pub trait Verifier {
9    type Target;
11    fn verify(&self, target: &Self::Target) -> Result<(), Error>;
13}
14
15bitflags! {
16    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
18    pub struct Switch: u32 {
19        const NONE                      = 0b00000000;
21
22        const DISABLE_EPOCH             = 0b00000001;
24
25        const DISABLE_UNCLES            = 0b00000010;
27
28        const DISABLE_TWO_PHASE_COMMIT  = 0b00000100;
30
31        const DISABLE_DAOHEADER         = 0b00001000;
33
34        const DISABLE_REWARD            = 0b00010000;
36
37        const DISABLE_NON_CONTEXTUAL    = 0b00100000;
39
40        const DISABLE_SCRIPT            = 0b01000000;
42
43        const DISABLE_EXTENSION         = 0b10000000;
45
46        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        const ONLY_SCRIPT               = Self::DISABLE_ALL.bits() & (!Self::DISABLE_SCRIPT.bits());
55    }
56}
57
58impl Switch {
59    pub fn disable_all(self) -> bool {
61        self.contains(Switch::DISABLE_ALL)
62    }
63
64    pub fn disable_non_contextual(self) -> bool {
66        self.contains(Switch::DISABLE_NON_CONTEXTUAL)
67    }
68
69    pub fn disable_epoch(&self) -> bool {
71        self.contains(Switch::DISABLE_EPOCH)
72    }
73
74    pub fn disable_uncles(&self) -> bool {
76        self.contains(Switch::DISABLE_UNCLES)
77    }
78
79    pub fn disable_two_phase_commit(&self) -> bool {
81        self.contains(Switch::DISABLE_TWO_PHASE_COMMIT)
82    }
83
84    pub fn disable_daoheader(&self) -> bool {
86        self.contains(Switch::DISABLE_DAOHEADER)
87    }
88
89    pub fn disable_reward(&self) -> bool {
91        self.contains(Switch::DISABLE_REWARD)
92    }
93
94    pub fn disable_extension(&self) -> bool {
96        self.contains(Switch::DISABLE_EXTENSION)
97    }
98
99    pub fn disable_script(&self) -> bool {
101        self.contains(Switch::DISABLE_SCRIPT)
102    }
103}