1- # Copyright (C) 2012-2015 The python-bitcoinlib developers
1+ # Copyright (C) 2012-2017 The python-bitcoinlib developers
22#
33# This file is part of python-bitcoinlib.
44#
@@ -356,8 +356,21 @@ def from_tx(cls, tx):
356356 else :
357357 return cls (tx .vin , tx .vout , tx .nLockTime , tx .nVersion )
358358
359+ def GetTxid (self ):
360+ return super (CTransaction , self ).GetHash ()
359361
360- @__make_mutable
362+ def GetHash (self ):
363+ raise AttributeError ("CTransaction.GetHash() has been removed; use GetTxid() instead" )
364+
365+
366+ # preserve GetHash so our AttributeError-raising stub works
367+ def __make_CMutableTransaction_mutable (cls ):
368+ get_hash_fn = cls .GetHash
369+ cls = __make_mutable (cls )
370+ cls .GetHash = get_hash_fn
371+ return cls
372+
373+ @__make_CMutableTransaction_mutable
361374class CMutableTransaction (CTransaction ):
362375 """A mutable transaction"""
363376 __slots__ = []
@@ -384,7 +397,11 @@ def from_tx(cls, tx):
384397
385398 return cls (vin , vout , tx .nLockTime , tx .nVersion )
386399
400+ def GetTxid (self ):
401+ return Serializable .GetHash (self )
387402
403+ def GetHash (self ):
404+ raise AttributeError ("CMutableTransaction.GetHash() has been removed; use GetTxid() instead" )
388405
389406
390407class CBlockHeader (ImmutableSerializable ):
@@ -478,7 +495,7 @@ def build_merkle_tree_from_txids(txids):
478495 @staticmethod
479496 def build_merkle_tree_from_txs (txs ):
480497 """Build a full merkle tree from transactions"""
481- txids = [tx .GetHash () for tx in txs ]
498+ txids = [tx .GetTxid () for tx in txs ]
482499 return CBlock .build_merkle_tree_from_txids (txids )
483500
484501 def calc_merkle_root (self ):
@@ -730,7 +747,7 @@ def CheckBlock(block, fCheckPoW = True, fCheckMerkleRoot = True, cur_time=None):
730747
731748 CheckTransaction (tx )
732749
733- txid = tx .GetHash ()
750+ txid = tx .GetTxid ()
734751 if txid in unique_txids :
735752 raise CheckBlockError ("CheckBlock() : duplicate transaction" )
736753 unique_txids .add (txid )
0 commit comments