@@ -483,7 +483,7 @@ def raw_iter(self):
483
483
i = 0
484
484
while i < len (self ):
485
485
sop_idx = i
486
- opcode = self [i ]
486
+ opcode = CScriptOp ( self [i ])
487
487
i += 1
488
488
489
489
if opcode > OP_PUSHDATA4 :
@@ -590,7 +590,7 @@ def GetSigOpCount(self, fAccurate):
590
590
n += 1
591
591
elif opcode in (OP_CHECKMULTISIG , OP_CHECKMULTISIGVERIFY ):
592
592
if fAccurate and (OP_1 <= lastOpcode <= OP_16 ):
593
- n += opcode .decode_op_n ()
593
+ n += lastOpcode .decode_op_n ()
594
594
else :
595
595
n += 20
596
596
lastOpcode = opcode
@@ -782,6 +782,20 @@ def test_cscriptnum_encoding(self):
782
782
for value in values :
783
783
self .assertEqual (CScriptNum .decode (CScriptNum .encode (CScriptNum (value ))), value )
784
784
785
+ def test_legacy_sigopcount (self ):
786
+ # test repeated single sig ops
787
+ for n_ops in range (1 , 100 , 10 ):
788
+ for singlesig_op in (OP_CHECKSIG , OP_CHECKSIGVERIFY ):
789
+ singlesigs_script = CScript ([singlesig_op ]* n_ops )
790
+ self .assertEqual (singlesigs_script .GetSigOpCount (fAccurate = False ), n_ops )
791
+ self .assertEqual (singlesigs_script .GetSigOpCount (fAccurate = True ), n_ops )
792
+ # test multisig op (including accurate counting, i.e. BIP16)
793
+ for n in range (1 , 16 + 1 ):
794
+ for multisig_op in (OP_CHECKMULTISIG , OP_CHECKMULTISIGVERIFY ):
795
+ multisig_script = CScript ([CScriptOp .encode_op_n (n ), multisig_op ])
796
+ self .assertEqual (multisig_script .GetSigOpCount (fAccurate = False ), 20 )
797
+ self .assertEqual (multisig_script .GetSigOpCount (fAccurate = True ), n )
798
+
785
799
def BIP341_sha_prevouts (txTo ):
786
800
return sha256 (b"" .join (i .prevout .serialize () for i in txTo .vin ))
787
801
0 commit comments