From b1ca91e3c1e12a7eb770cb8de6a8e1e75bb47c11 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Mon, 11 Jan 2021 00:00:00 +0000 Subject: [PATCH] Add the blk*.data file path basename to Block.blk_file --- blockchain_parser/block.py | 3 ++- blockchain_parser/blockchain.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/blockchain_parser/block.py b/blockchain_parser/block.py index f00db41..15caf22 100644 --- a/blockchain_parser/block.py +++ b/blockchain_parser/block.py @@ -46,7 +46,7 @@ class Block(object): Represents a Bitcoin block, contains its header and its transactions. """ - def __init__(self, raw_hex, height=None): + def __init__(self, raw_hex, height=None, blk_file=None): self.hex = raw_hex self._hash = None self._transactions = None @@ -54,6 +54,7 @@ def __init__(self, raw_hex, height=None): self._n_transactions = None self.size = len(raw_hex) self.height = height + self.blk_file = blk_file def __repr__(self): return "Block(%s)" % self.hash diff --git a/blockchain_parser/blockchain.py b/blockchain_parser/blockchain.py index 454e7c2..c4d24be 100644 --- a/blockchain_parser/blockchain.py +++ b/blockchain_parser/blockchain.py @@ -94,7 +94,7 @@ def get_unordered_blocks(self): """ for blk_file in get_files(self.path): for raw_block in get_blocks(blk_file): - yield Block(raw_block) + yield Block(raw_block, None, os.path.split(blk_file)[1]) def __getBlockIndexes(self, index): """There is no method of leveldb to close the db (and release the lock).