parent
aa1f43b6be
commit
4c7ab221a7
@ -79,6 +79,8 @@ class Deserializer(object):
|
|||||||
millions of times during sync.
|
millions of times during sync.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
TX_HASH_FN = staticmethod(double_sha256)
|
||||||
|
|
||||||
def __init__(self, binary, start=0):
|
def __init__(self, binary, start=0):
|
||||||
assert isinstance(binary, bytes)
|
assert isinstance(binary, bytes)
|
||||||
self.binary = binary
|
self.binary = binary
|
||||||
@ -101,7 +103,7 @@ class Deserializer(object):
|
|||||||
we process it in the natural serialized order.
|
we process it in the natural serialized order.
|
||||||
'''
|
'''
|
||||||
start = self.cursor
|
start = self.cursor
|
||||||
return self.read_tx(), double_sha256(self.binary[start:self.cursor])
|
return self.read_tx(), self.TX_HASH_FN(self.binary[start:self.cursor])
|
||||||
|
|
||||||
def read_tx_and_vsize(self):
|
def read_tx_and_vsize(self):
|
||||||
'''Return a (deserialized TX, vsize) pair.'''
|
'''Return a (deserialized TX, vsize) pair.'''
|
||||||
@ -213,7 +215,7 @@ class DeserializerSegWit(Deserializer):
|
|||||||
marker = self.binary[self.cursor + 4]
|
marker = self.binary[self.cursor + 4]
|
||||||
if marker:
|
if marker:
|
||||||
tx = super().read_tx()
|
tx = super().read_tx()
|
||||||
tx_hash = double_sha256(self.binary[start:self.cursor])
|
tx_hash = self.TX_HASH_FN(self.binary[start:self.cursor])
|
||||||
return tx, tx_hash, self.binary_length
|
return tx, tx_hash, self.binary_length
|
||||||
|
|
||||||
# Ugh, this is nasty.
|
# Ugh, this is nasty.
|
||||||
@ -237,7 +239,7 @@ class DeserializerSegWit(Deserializer):
|
|||||||
vsize = (3 * base_size + self.binary_length) // 4
|
vsize = (3 * base_size + self.binary_length) // 4
|
||||||
|
|
||||||
return TxSegWit(version, marker, flag, inputs, outputs, witness,
|
return TxSegWit(version, marker, flag, inputs, outputs, witness,
|
||||||
locktime), double_sha256(orig_ser), vsize
|
locktime), self.TX_HASH_FN(orig_ser), vsize
|
||||||
|
|
||||||
def read_tx(self):
|
def read_tx(self):
|
||||||
return self._read_tx_parts()[0]
|
return self._read_tx_parts()[0]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user