Move serialize code block
This commit is contained in:
parent
41e00449f8
commit
43249a9ec0
@ -20,6 +20,20 @@ from chainsyncer.error import (
|
|||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def sync_state_serialize(block_height, tx_index, block_target):
|
||||||
|
b = block_height.to_bytes(4, 'big')
|
||||||
|
b += tx_index.to_bytes(4, 'big')
|
||||||
|
b += block_target.to_bytes(4, 'big', signed=True)
|
||||||
|
return b
|
||||||
|
|
||||||
|
|
||||||
|
def sync_state_deserialize(b):
|
||||||
|
block_height = int.from_bytes(b[:4], 'big')
|
||||||
|
tx_index = int.from_bytes(b[4:8], 'big')
|
||||||
|
block_target = int.from_bytes(b[8:], 'big', signed=True)
|
||||||
|
return (block_height, tx_index, block_target,)
|
||||||
|
|
||||||
|
|
||||||
# NOT thread safe
|
# NOT thread safe
|
||||||
class SyncFsItem:
|
class SyncFsItem:
|
||||||
|
|
||||||
@ -293,16 +307,3 @@ class SyncFsStore:
|
|||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
self.filter_state.disconnect()
|
self.filter_state.disconnect()
|
||||||
|
|
||||||
|
|
||||||
def sync_state_serialize(block_height, tx_index, block_target):
|
|
||||||
b = block_height.to_bytes(4, 'big')
|
|
||||||
b += tx_index.to_bytes(4, 'big')
|
|
||||||
b += block_target.to_bytes(4, 'big', signed=True)
|
|
||||||
return b
|
|
||||||
|
|
||||||
|
|
||||||
def sync_state_deserialize(b):
|
|
||||||
block_height = int.from_bytes(b[:4], 'big')
|
|
||||||
tx_index = int.from_bytes(b[4:8], 'big')
|
|
||||||
block_target = int.from_bytes(b[8:], 'big', signed=True)
|
|
||||||
return (block_height, tx_index, block_target,)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user