@@ -658,8 +658,14 @@ def serialize(self):
658658 return self .serialize_with_witness ()
659659
660660 def getwtxid (self ):
661+ """Return wtxid (transaction hash with witness) as hex string."""
661662 return hash256 (self .serialize ())[::- 1 ].hex ()
662663
664+ @property
665+ def wtxid_int (self ):
666+ """Return wtxid (transaction hash with witness) as integer."""
667+ return uint256_from_str (hash256 (self .serialize_with_witness ()))
668+
663669 @property
664670 def hash (self ):
665671 """Return txid (transaction hash without witness) as hex string."""
@@ -675,12 +681,6 @@ def sha256(self):
675681 def rehash (self ):
676682 return self .hash
677683
678- # TODO: get rid of this method, replace call-sites by .wtxid_int access (not introduced yet)
679- def calc_sha256 (self , with_witness = False ):
680- if with_witness :
681- # Don't cache the result, just return it
682- return uint256_from_str (hash256 (self .serialize_with_witness ()))
683-
684684 def is_valid (self ):
685685 for tout in self .vout :
686686 if tout .nValue < 0 or tout .nValue > 21000000 * COIN :
@@ -819,7 +819,7 @@ def calc_witness_merkle_root(self):
819819
820820 for tx in self .vtx [1 :]:
821821 # Calculate the hashes with witness data
822- hashes .append (ser_uint256 (tx .calc_sha256 ( True ) ))
822+ hashes .append (ser_uint256 (tx .wtxid_int ))
823823
824824 return self .get_merkle_root (hashes )
825825
@@ -1003,7 +1003,7 @@ def initialize_from_block(self, block, nonce=0, prefill_list=None, use_witness=F
10031003 if i not in prefill_list :
10041004 tx_hash = block .vtx [i ].sha256
10051005 if use_witness :
1006- tx_hash = block .vtx [i ].calc_sha256 ( with_witness = True )
1006+ tx_hash = block .vtx [i ].wtxid_int
10071007 self .shortids .append (calculate_shortid (k0 , k1 , tx_hash ))
10081008
10091009 def __repr__ (self ):
0 commit comments