@@ -841,6 +841,52 @@ def serialize(self, with_witness=True):
841841 def __repr__ (self ):
842842 return "BlockTransactions(hash=%064x transactions=%s)" % (self .blockhash , repr (self .transactions ))
843843
844+ class CPartialMerkleTree ():
845+ def __init__ (self ):
846+ self .nTransactions = 0
847+ self .vHash = []
848+ self .vBits = []
849+ self .fBad = False
850+
851+ def deserialize (self , f ):
852+ self .nTransactions = struct .unpack ("<i" , f .read (4 ))[0 ]
853+ self .vHash = deser_uint256_vector (f )
854+ vBytes = deser_string (f )
855+ self .vBits = []
856+ for i in range (len (vBytes ) * 8 ):
857+ self .vBits .append (vBytes [i // 8 ] & (1 << (i % 8 )) != 0 )
858+
859+ def serialize (self ):
860+ r = b""
861+ r += struct .pack ("<i" , self .nTransactions )
862+ r += ser_uint256_vector (self .vHash )
863+ vBytesArray = bytearray ([0x00 ] * ((len (self .vBits ) + 7 )// 8 ))
864+ for i in range (len (self .vBits )):
865+ vBytesArray [i // 8 ] |= self .vBits [i ] << (i % 8 )
866+ r += ser_string (bytes (vBytesArray ))
867+ return r
868+
869+ def __repr__ (self ):
870+ return "CPartialMerkleTree(nTransactions=%d, vHash=%s, vBits=%s)" % (self .nTransactions , repr (self .vHash ), repr (self .vBits ))
871+
872+ class CMerkleBlock ():
873+ def __init__ (self ):
874+ self .header = CBlockHeader ()
875+ self .txn = CPartialMerkleTree ()
876+
877+ def deserialize (self , f ):
878+ self .header .deserialize (f )
879+ self .txn .deserialize (f )
880+
881+ def serialize (self ):
882+ r = b""
883+ r += self .header .serialize ()
884+ r += self .txn .serialize ()
885+ return r
886+
887+ def __repr__ (self ):
888+ return "CMerkleBlock(header=%s, txn=%s)" % (repr (self .header ), repr (self .txn ))
889+
844890
845891# Objects that correspond to messages on the wire
846892class msg_version ():
0 commit comments