From 8a49027e502cd8fcd4db8074dd67e1570d765284 Mon Sep 17 00:00:00 2001 From: dgnsrekt Date: Sat, 9 Feb 2019 14:58:08 -0600 Subject: [PATCH 1/3] Add the ability to start from specific blkfile to get_unordered_blocks() --- blockchain_parser/blockchain.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/blockchain_parser/blockchain.py b/blockchain_parser/blockchain.py index bb826ae..c4c8b84 100644 --- a/blockchain_parser/blockchain.py +++ b/blockchain_parser/blockchain.py @@ -83,13 +83,16 @@ def __init__(self, path): self.blockIndexes = None self.indexPath = None - def get_unordered_blocks(self): + def get_unordered_blocks(self, start_from_blk_file=0): """Yields the blocks contained in the .blk files as is, without ordering them according to height. """ - for blk_file in get_files(self.path): - for raw_block in get_blocks(blk_file): - yield Block(raw_block) + for index, blk_file in enumerate(get_files(self.path)): + if index < start_from_blk_file: + continue + else: + for raw_block in get_blocks(blk_file): + yield Block(raw_block) def __getBlockIndexes(self, index): """There is no method of leveldb to close the db (and release the lock). From aa8e39a1b583624302a34f91bba49f3564a36b8f Mon Sep 17 00:00:00 2001 From: dgnsrekt Date: Sat, 9 Feb 2019 15:30:35 -0600 Subject: [PATCH 2/3] Added get_unordered_blocks_starting_from_blkfile() --- blockchain_parser/blockchain.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/blockchain_parser/blockchain.py b/blockchain_parser/blockchain.py index c4c8b84..6b2ee87 100644 --- a/blockchain_parser/blockchain.py +++ b/blockchain_parser/blockchain.py @@ -83,10 +83,19 @@ def __init__(self, path): self.blockIndexes = None self.indexPath = None - def get_unordered_blocks(self, start_from_blk_file=0): + def get_unordered_blocks(self): """Yields the blocks contained in the .blk files as is, without ordering them according to height. """ + for blk_file in get_files(self.path): + for raw_block in get_blocks(blk_file): + yield Block(raw_block) + + def get_unordered_blocks_starting_from_blkfile(self, start=0): + """Yields the blocks contained in the .blk files as is, + without ordering them according to height starting from a + specific file. + """ for index, blk_file in enumerate(get_files(self.path)): if index < start_from_blk_file: continue From ce6933dc1b8d3f71cf6d316e0284f962fef6f49d Mon Sep 17 00:00:00 2001 From: dgnsrekt Date: Sun, 10 Feb 2019 10:10:28 -0600 Subject: [PATCH 3/3] Add the ability to start and stop from last known parsed unordered block --- blockchain_parser/blockchain.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/blockchain_parser/blockchain.py b/blockchain_parser/blockchain.py index 6b2ee87..09f8d26 100644 --- a/blockchain_parser/blockchain.py +++ b/blockchain_parser/blockchain.py @@ -91,17 +91,20 @@ def get_unordered_blocks(self): for raw_block in get_blocks(blk_file): yield Block(raw_block) - def get_unordered_blocks_starting_from_blkfile(self, start=0): - """Yields the blocks contained in the .blk files as is, - without ordering them according to height starting from a - specific file. + def get_unordered_blocks_from(self, blk_file_idx=0, unordered_block_position=0): + """Yields a tuple containing the blk files index, blocks postion in the file, + and the block from the .blk file as is, without ordering them according to height. """ for index, blk_file in enumerate(get_files(self.path)): - if index < start_from_blk_file: + if index < blk_file_idx: continue else: - for raw_block in get_blocks(blk_file): - yield Block(raw_block) + for block_position, raw_block in enumerate(get_blocks(blk_file)): + if block_position < unordered_block_position: + continue + else: + yield index, block_position, Block(raw_block) + unordered_block_position = 0 def __getBlockIndexes(self, index): """There is no method of leveldb to close the db (and release the lock).