Prevent unnecessary copying of raw blocks
This commit is contained in:
parent
3eef0ba4cf
commit
f696a7933d
10
lib/coins.py
10
lib/coins.py
@ -273,7 +273,7 @@ class Coin(object):
|
|||||||
def block(cls, raw_block, height):
|
def block(cls, raw_block, height):
|
||||||
'''Return a Block namedtuple given a raw block and its height.'''
|
'''Return a Block namedtuple given a raw block and its height.'''
|
||||||
header = cls.block_header(raw_block, height)
|
header = cls.block_header(raw_block, height)
|
||||||
txs = cls.DESERIALIZER(raw_block[len(header):]).read_tx_block()
|
txs = cls.DESERIALIZER(raw_block, start=len(header)).read_tx_block()
|
||||||
return Block(raw_block, header, txs)
|
return Block(raw_block, header, txs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -313,8 +313,8 @@ class AuxPowMixin(object):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def block_header(cls, block, height):
|
def block_header(cls, block, height):
|
||||||
'''Return the AuxPow block header bytes'''
|
'''Return the AuxPow block header bytes'''
|
||||||
block = cls.DESERIALIZER(block)
|
deserializer = cls.DESERIALIZER(block)
|
||||||
return block.read_header(height, cls.BASIC_HEADER_SIZE)
|
return deserializer.read_header(height, cls.BASIC_HEADER_SIZE)
|
||||||
|
|
||||||
|
|
||||||
class Bitcoin(Coin):
|
class Bitcoin(Coin):
|
||||||
@ -762,8 +762,8 @@ class Zcash(Coin):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def block_header(cls, block, height):
|
def block_header(cls, block, height):
|
||||||
'''Return the block header bytes'''
|
'''Return the block header bytes'''
|
||||||
block = cls.DESERIALIZER(block)
|
deserializer = cls.DESERIALIZER(block)
|
||||||
return block.read_header(height, cls.BASIC_HEADER_SIZE)
|
return deserializer.read_header(height, cls.BASIC_HEADER_SIZE)
|
||||||
|
|
||||||
|
|
||||||
class Einsteinium(Coin):
|
class Einsteinium(Coin):
|
||||||
|
|||||||
@ -75,10 +75,10 @@ class Deserializer(object):
|
|||||||
millions of times during sync.
|
millions of times during sync.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, binary):
|
def __init__(self, binary, start=0):
|
||||||
assert isinstance(binary, bytes)
|
assert isinstance(binary, bytes)
|
||||||
self.binary = binary
|
self.binary = binary
|
||||||
self.cursor = 0
|
self.cursor = start
|
||||||
|
|
||||||
def read_tx(self):
|
def read_tx(self):
|
||||||
'''Return a (Deserialized TX, TX_HASH) pair.
|
'''Return a (Deserialized TX, TX_HASH) pair.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user