bsv_script/interpreter/
flags.rs1use std::ops::{BitAnd, BitOr, BitOrAssign};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
7pub struct ScriptFlags(pub u32);
8
9impl ScriptFlags {
10 pub const NONE: ScriptFlags = ScriptFlags(0);
12 pub const BIP16: ScriptFlags = ScriptFlags(1 << 0);
14 pub const STRICT_MULTI_SIG: ScriptFlags = ScriptFlags(1 << 1);
16 pub const DISCOURAGE_UPGRADABLE_NOPS: ScriptFlags = ScriptFlags(1 << 2);
18 pub const VERIFY_CHECKLOCKTIMEVERIFY: ScriptFlags = ScriptFlags(1 << 3);
20 pub const VERIFY_CHECKSEQUENCEVERIFY: ScriptFlags = ScriptFlags(1 << 4);
22 pub const VERIFY_CLEAN_STACK: ScriptFlags = ScriptFlags(1 << 5);
24 pub const VERIFY_DER_SIGNATURES: ScriptFlags = ScriptFlags(1 << 6);
26 pub const VERIFY_LOW_S: ScriptFlags = ScriptFlags(1 << 7);
28 pub const VERIFY_MINIMAL_DATA: ScriptFlags = ScriptFlags(1 << 8);
30 pub const VERIFY_NULL_FAIL: ScriptFlags = ScriptFlags(1 << 9);
32 pub const VERIFY_SIG_PUSH_ONLY: ScriptFlags = ScriptFlags(1 << 10);
34 pub const ENABLE_SIGHASH_FORKID: ScriptFlags = ScriptFlags(1 << 11);
36 pub const VERIFY_STRICT_ENCODING: ScriptFlags = ScriptFlags(1 << 12);
38 pub const VERIFY_BIP143_SIGHASH: ScriptFlags = ScriptFlags(1 << 13);
40 pub const UTXO_AFTER_GENESIS: ScriptFlags = ScriptFlags(1 << 14);
42 pub const VERIFY_MINIMAL_IF: ScriptFlags = ScriptFlags(1 << 15);
44
45 pub fn has_flag(self, flag: ScriptFlags) -> bool {
47 self.0 & flag.0 == flag.0
48 }
49
50 pub fn has_any(self, flags: &[ScriptFlags]) -> bool {
52 flags.iter().any(|f| self.has_flag(*f))
53 }
54
55 pub fn add_flag(&mut self, flag: ScriptFlags) {
57 self.0 |= flag.0;
58 }
59}
60
61impl BitOr for ScriptFlags {
62 type Output = Self;
63 fn bitor(self, rhs: Self) -> Self {
64 ScriptFlags(self.0 | rhs.0)
65 }
66}
67
68impl BitOrAssign for ScriptFlags {
69 fn bitor_assign(&mut self, rhs: Self) {
70 self.0 |= rhs.0;
71 }
72}
73
74impl BitAnd for ScriptFlags {
75 type Output = Self;
76 fn bitand(self, rhs: Self) -> Self {
77 ScriptFlags(self.0 & rhs.0)
78 }
79}