forked from libsv/go-bt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptflag.go
101 lines (80 loc) · 3.1 KB
/
scriptflag.go
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
package scriptflag
// Flag is a bitmask defining additional operations or tests that will be
// done when executing a script pair.
type Flag uint32
const (
// Bip16 defines whether the bip16 threshold has passed and thus
// pay-to-script hash transactions will be fully validated.
Bip16 Flag = 1 << iota
// StrictMultiSig defines whether to verify the stack item
// used by CHECKMULTISIG is zero length.
StrictMultiSig
// DiscourageUpgradableNops defines whether to verify that
// NOP1 through NOP10 are reserved for future soft-fork upgrades. This
// flag must not be used for consensus critical code nor applied to
// blocks as this flag is only for stricter standard transaction
// checks. This flag is only applied when the above opcodes are
// executed.
DiscourageUpgradableNops
// VerifyCheckLockTimeVerify defines whether to verify that
// a transaction output is spendable based on the locktime.
// This is BIP0065.
VerifyCheckLockTimeVerify
// VerifyCheckSequenceVerify defines whether to allow execution
// pathways of a script to be restricted based on the age of the output
// being spent. This is BIP0112.
VerifyCheckSequenceVerify
// VerifyCleanStack defines that the stack must contain only
// one stack element after evaluation and that the element must be
// true if interpreted as a boolean. This is rule 6 of BIP0062.
// This flag should never be used without the Bip16 flag.
VerifyCleanStack
// VerifyDERSignatures defines that signatures are required
// to comply with the DER format.
VerifyDERSignatures
// VerifyLowS defines that signatures are required to comply with
// the DER format and whose S value is <= order / 2. This is rule 5
// of BIP0062.
VerifyLowS
// VerifyMinimalData defines that signatures must use the smallest
// push operator. This is both rules 3 and 4 of BIP0062.
VerifyMinimalData
// VerifyNullFail defines that signatures must be empty if
// a CHECKSIG or CHECKMULTISIG operation fails.
VerifyNullFail
// VerifySigPushOnly defines that signature scripts must contain
// only pushed data. This is rule 2 of BIP0062.
VerifySigPushOnly
// EnableSighashForkID defined that signature scripts have forkid
// enabled.
EnableSighashForkID
// VerifyStrictEncoding defines that signature scripts and
// public keys must follow the strict encoding requirements.
VerifyStrictEncoding
// VerifyBip143SigHash defines that signature hashes should
// be calculated using the bip0143 signature hashing algorithm.
VerifyBip143SigHash
// UTXOAfterGenesis defines that the utxo was created after
// genesis.
UTXOAfterGenesis
// VerifyMinimalIf defines the enforcement of any conditional statement using the
// minimum required data.
VerifyMinimalIf
)
// HasFlag returns whether the Flags has the passed flag set.
func (s Flag) HasFlag(flag Flag) bool {
return s&flag == flag
}
// HasAny returns true if any of the passed in flags are present.
func (s Flag) HasAny(flags ...Flag) bool {
for _, f := range flags {
if s&f == f {
return true
}
}
return false
}
// AddFlag adds the passed flag to Flags
func (s *Flag) AddFlag(flag Flag) {
*s |= flag
}