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 pub struct Switch: u32 {
18 const NONE = 0b00000000;
20
21 const DISABLE_EPOCH = 0b00000001;
23
24 const DISABLE_UNCLES = 0b00000010;
26
27 const DISABLE_TWO_PHASE_COMMIT = 0b00000100;
29
30 const DISABLE_DAOHEADER = 0b00001000;
32
33 const DISABLE_REWARD = 0b00010000;
35
36 const DISABLE_NON_CONTEXTUAL = 0b00100000;
38
39 const DISABLE_SCRIPT = 0b01000000;
41
42 const DISABLE_EXTENSION = 0b10000000;
44
45 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 const ONLY_SCRIPT = Self::DISABLE_ALL.bits & (!Self::DISABLE_SCRIPT.bits);
54 }
55}
56
57impl Switch {
58 pub fn disable_all(self) -> bool {
60 self.contains(Switch::DISABLE_ALL)
61 }
62
63 pub fn disable_non_contextual(self) -> bool {
65 self.contains(Switch::DISABLE_NON_CONTEXTUAL)
66 }
67
68 pub fn disable_epoch(&self) -> bool {
70 self.contains(Switch::DISABLE_EPOCH)
71 }
72
73 pub fn disable_uncles(&self) -> bool {
75 self.contains(Switch::DISABLE_UNCLES)
76 }
77
78 pub fn disable_two_phase_commit(&self) -> bool {
80 self.contains(Switch::DISABLE_TWO_PHASE_COMMIT)
81 }
82
83 pub fn disable_daoheader(&self) -> bool {
85 self.contains(Switch::DISABLE_DAOHEADER)
86 }
87
88 pub fn disable_reward(&self) -> bool {
90 self.contains(Switch::DISABLE_REWARD)
91 }
92
93 pub fn disable_extension(&self) -> bool {
95 self.contains(Switch::DISABLE_EXTENSION)
96 }
97
98 pub fn disable_script(&self) -> bool {
100 self.contains(Switch::DISABLE_SCRIPT)
101 }
102}