Skip to content

Commit 8a5dbe2

Browse files
committed
test: add CScript method for checking for witness program
This is needed in the next commit to calculate the dust threshold for a given output script and min feerate for defining dust.
1 parent cac29f5 commit 8a5dbe2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

test/functional/test_framework/script.py

+7
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,13 @@ def GetSigOpCount(self, fAccurate):
597597
lastOpcode = opcode
598598
return n
599599

600+
def IsWitnessProgram(self):
601+
"""A witness program is any valid CScript that consists of a 1-byte
602+
push opcode followed by a data push between 2 and 40 bytes."""
603+
return ((4 <= len(self) <= 42) and
604+
(self[0] == OP_0 or (OP_1 <= self[0] <= OP_16)) and
605+
(self[1] + 2 == len(self)))
606+
600607

601608
SIGHASH_DEFAULT = 0 # Taproot-only default, semantics same as SIGHASH_ALL
602609
SIGHASH_ALL = 1

0 commit comments

Comments
 (0)