Skip to content

Commit

Permalink
Issue alecalve#29 & alecalve#105 solved: get_transaction() returns b…
Browse files Browse the repository at this point in the history
…lock header
  • Loading branch information
levushakov committed Mar 5, 2024
1 parent c06f420 commit 2b59f05
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion blockchain_parser/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from .block import Block
from .index import DBBlockIndex
from .utils import format_hash
from .block_header import BlockHeader


# Constant separating blocks in the .blk files
Expand Down Expand Up @@ -243,13 +244,15 @@ def get_transaction(self, txid, db):
offset = tx_idx.block_offset

transaction_data = raw_hex[80:]
block_header_data = raw_hex[:80]
# Try from 1024 (1KiB) -> 1073741824 (1GiB) slice widths
for j in range(0, 20):
try:
block_header = BlockHeader.from_hex(block_header_data)
offset_e = offset + (1024 * 2 ** j)
transaction = Transaction.from_hex(
transaction_data[offset:offset_e])
return transaction
return [block_header, transaction]
except Exception:
continue

Expand Down

0 comments on commit 2b59f05

Please sign in to comment.