ckb_verification_traits/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#![allow(clippy::bad_bit_mask)]

//! The trait abstract for particular verification
use bitflags::bitflags;
use ckb_error::Error;

/// Trait for verification
pub trait Verifier {
    /// The verification associated target
    type Target;
    /// The Interface for verification
    fn verify(&self, target: &Self::Target) -> Result<(), Error>;
}

bitflags! {
    /// The bit flags for particular process block verify
    pub struct Switch: u32 {
        /// None of verifier will be disabled
        const NONE                      = 0b00000000;

        /// Disable epoch verifier
        const DISABLE_EPOCH             = 0b00000001;

        /// Disable uncle verifier
        const DISABLE_UNCLES            = 0b00000010;

        /// Disable two phase commit verifier
        const DISABLE_TWO_PHASE_COMMIT  = 0b00000100;

        /// Disable dao header verifier
        const DISABLE_DAOHEADER         = 0b00001000;

        /// Disable reward verifier
        const DISABLE_REWARD            = 0b00010000;

        /// Disable non-contextual verifier
        const DISABLE_NON_CONTEXTUAL    = 0b00100000;

        /// Disable script verification
        const DISABLE_SCRIPT            = 0b01000000;

        /// Disable extension verification
        const DISABLE_EXTENSION         = 0b10000000;

        /// Disable all verifier
        const DISABLE_ALL               = Self::DISABLE_EPOCH.bits | Self::DISABLE_UNCLES.bits |
                                    Self::DISABLE_TWO_PHASE_COMMIT.bits | Self::DISABLE_DAOHEADER.bits |
                                    Self::DISABLE_REWARD.bits |
                                    Self::DISABLE_NON_CONTEXTUAL.bits | Self::DISABLE_SCRIPT.bits |
                                    Self::DISABLE_EXTENSION.bits;

        /// Only script verification
        const ONLY_SCRIPT               = Self::DISABLE_ALL.bits & (!Self::DISABLE_SCRIPT.bits);
    }
}

impl Switch {
    /// Whether all verifiers are disabled
    pub fn disable_all(self) -> bool {
        self.contains(Switch::DISABLE_ALL)
    }

    /// Whether non-contextual verifier is disabled
    pub fn disable_non_contextual(self) -> bool {
        self.contains(Switch::DISABLE_NON_CONTEXTUAL)
    }

    /// Whether epoch verifier is disabled
    pub fn disable_epoch(&self) -> bool {
        self.contains(Switch::DISABLE_EPOCH)
    }

    /// Whether uncles verifier is disabled
    pub fn disable_uncles(&self) -> bool {
        self.contains(Switch::DISABLE_UNCLES)
    }

    /// Whether two-phase-commit verifier is disabled
    pub fn disable_two_phase_commit(&self) -> bool {
        self.contains(Switch::DISABLE_TWO_PHASE_COMMIT)
    }

    /// Whether DAO-header verifier is disabled
    pub fn disable_daoheader(&self) -> bool {
        self.contains(Switch::DISABLE_DAOHEADER)
    }

    /// Whether reward verifier is disabled
    pub fn disable_reward(&self) -> bool {
        self.contains(Switch::DISABLE_REWARD)
    }

    /// Whether extension verifier is disabled
    pub fn disable_extension(&self) -> bool {
        self.contains(Switch::DISABLE_EXTENSION)
    }

    /// Whether script verifier is disabled
    pub fn disable_script(&self) -> bool {
        self.contains(Switch::DISABLE_SCRIPT)
    }
}