|
|
@ -452,10 +452,10 @@ class CTransaction(): |
|
|
|
r += struct.pack("<I", self.nLockTime) |
|
|
|
r += struct.pack("<I", self.nLockTime) |
|
|
|
return r |
|
|
|
return r |
|
|
|
|
|
|
|
|
|
|
|
# Regular serialization is without witness -- must explicitly |
|
|
|
# Regular serialization is with witness -- must explicitly |
|
|
|
# call serialize_with_witness to include witness data. |
|
|
|
# call serialize_without_witness to exclude witness data. |
|
|
|
def serialize(self): |
|
|
|
def serialize(self): |
|
|
|
return self.serialize_without_witness() |
|
|
|
return self.serialize_with_witness() |
|
|
|
|
|
|
|
|
|
|
|
# Recalculate the txid (transaction hash without witness) |
|
|
|
# Recalculate the txid (transaction hash without witness) |
|
|
|
def rehash(self): |
|
|
|
def rehash(self): |
|
|
@ -471,7 +471,7 @@ class CTransaction(): |
|
|
|
|
|
|
|
|
|
|
|
if self.sha256 is None: |
|
|
|
if self.sha256 is None: |
|
|
|
self.sha256 = uint256_from_str(hash256(self.serialize_without_witness())) |
|
|
|
self.sha256 = uint256_from_str(hash256(self.serialize_without_witness())) |
|
|
|
self.hash = encode(hash256(self.serialize())[::-1], 'hex_codec').decode('ascii') |
|
|
|
self.hash = encode(hash256(self.serialize_without_witness())[::-1], 'hex_codec').decode('ascii') |
|
|
|
|
|
|
|
|
|
|
|
def is_valid(self): |
|
|
|
def is_valid(self): |
|
|
|
self.calc_sha256() |
|
|
|
self.calc_sha256() |
|
|
@ -568,7 +568,7 @@ class CBlock(CBlockHeader): |
|
|
|
if with_witness: |
|
|
|
if with_witness: |
|
|
|
r += ser_vector(self.vtx, "serialize_with_witness") |
|
|
|
r += ser_vector(self.vtx, "serialize_with_witness") |
|
|
|
else: |
|
|
|
else: |
|
|
|
r += ser_vector(self.vtx) |
|
|
|
r += ser_vector(self.vtx, "serialize_without_witness") |
|
|
|
return r |
|
|
|
return r |
|
|
|
|
|
|
|
|
|
|
|
# Calculate the merkle root given a vector of transaction hashes |
|
|
|
# Calculate the merkle root given a vector of transaction hashes |
|
|
@ -635,7 +635,7 @@ class PrefilledTransaction(): |
|
|
|
self.tx = CTransaction() |
|
|
|
self.tx = CTransaction() |
|
|
|
self.tx.deserialize(f) |
|
|
|
self.tx.deserialize(f) |
|
|
|
|
|
|
|
|
|
|
|
def serialize(self, with_witness=False): |
|
|
|
def serialize(self, with_witness=True): |
|
|
|
r = b"" |
|
|
|
r = b"" |
|
|
|
r += ser_compact_size(self.index) |
|
|
|
r += ser_compact_size(self.index) |
|
|
|
if with_witness: |
|
|
|
if with_witness: |
|
|
@ -644,6 +644,9 @@ class PrefilledTransaction(): |
|
|
|
r += self.tx.serialize_without_witness() |
|
|
|
r += self.tx.serialize_without_witness() |
|
|
|
return r |
|
|
|
return r |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def serialize_without_witness(self): |
|
|
|
|
|
|
|
return self.serialize(with_witness=False) |
|
|
|
|
|
|
|
|
|
|
|
def serialize_with_witness(self): |
|
|
|
def serialize_with_witness(self): |
|
|
|
return self.serialize(with_witness=True) |
|
|
|
return self.serialize(with_witness=True) |
|
|
|
|
|
|
|
|
|
|
@ -683,7 +686,7 @@ class P2PHeaderAndShortIDs(): |
|
|
|
if with_witness: |
|
|
|
if with_witness: |
|
|
|
r += ser_vector(self.prefilled_txn, "serialize_with_witness") |
|
|
|
r += ser_vector(self.prefilled_txn, "serialize_with_witness") |
|
|
|
else: |
|
|
|
else: |
|
|
|
r += ser_vector(self.prefilled_txn) |
|
|
|
r += ser_vector(self.prefilled_txn, "serialize_without_witness") |
|
|
|
return r |
|
|
|
return r |
|
|
|
|
|
|
|
|
|
|
|
def __repr__(self): |
|
|
|
def __repr__(self): |
|
|
@ -814,13 +817,13 @@ class BlockTransactions(): |
|
|
|
self.blockhash = deser_uint256(f) |
|
|
|
self.blockhash = deser_uint256(f) |
|
|
|
self.transactions = deser_vector(f, CTransaction) |
|
|
|
self.transactions = deser_vector(f, CTransaction) |
|
|
|
|
|
|
|
|
|
|
|
def serialize(self, with_witness=False): |
|
|
|
def serialize(self, with_witness=True): |
|
|
|
r = b"" |
|
|
|
r = b"" |
|
|
|
r += ser_uint256(self.blockhash) |
|
|
|
r += ser_uint256(self.blockhash) |
|
|
|
if with_witness: |
|
|
|
if with_witness: |
|
|
|
r += ser_vector(self.transactions, "serialize_with_witness") |
|
|
|
r += ser_vector(self.transactions, "serialize_with_witness") |
|
|
|
else: |
|
|
|
else: |
|
|
|
r += ser_vector(self.transactions) |
|
|
|
r += ser_vector(self.transactions, "serialize_without_witness") |
|
|
|
return r |
|
|
|
return r |
|
|
|
|
|
|
|
|
|
|
|
def __repr__(self): |
|
|
|
def __repr__(self): |
|
|
@ -1020,7 +1023,7 @@ class msg_block(): |
|
|
|
self.block.deserialize(f) |
|
|
|
self.block.deserialize(f) |
|
|
|
|
|
|
|
|
|
|
|
def serialize(self): |
|
|
|
def serialize(self): |
|
|
|
return self.block.serialize() |
|
|
|
return self.block.serialize(with_witness=False) |
|
|
|
|
|
|
|
|
|
|
|
def __repr__(self): |
|
|
|
def __repr__(self): |
|
|
|
return "msg_block(block=%s)" % (repr(self.block)) |
|
|
|
return "msg_block(block=%s)" % (repr(self.block)) |
|
|
@ -1291,7 +1294,7 @@ class msg_blocktxn(): |
|
|
|
|
|
|
|
|
|
|
|
def serialize(self): |
|
|
|
def serialize(self): |
|
|
|
r = b"" |
|
|
|
r = b"" |
|
|
|
r += self.block_transactions.serialize() |
|
|
|
r += self.block_transactions.serialize(with_witness=False) |
|
|
|
return r |
|
|
|
return r |
|
|
|
|
|
|
|
|
|
|
|
def __repr__(self): |
|
|
|
def __repr__(self): |
|
|
|