address – Is it possible to retrieve input addresses and input values of bitcoin transactions from raw blk.dat files?

[ad_1]

E.g. in Python with https://github.com/alecalve/python-bitcoin-blockchain-parser:

#!/usr/bin/env python3

# stdlib
import os
import sys

# Third party
from bitcoin.core.script import *
import blockchain_parser.blockchain

datadir="/home/ciro/snap/bitcoin-core/common/.bitcoin/blocks"
blockchain = blockchain_parser.blockchain.Blockchain(datadir)
for block in blockchain.get_ordered_blocks(
    os.path.join(datadir, 'index'),
    cache="cache.pkl",
):
    for txno, tx in enumerate(block.transactions):
        print(tx.txid)
        print('inputs')
        for inp in tx.inputs:
            print(inp.sequence_number)
            print(inp.witnesses)
            print(inp.script)
            print(inp.transaction_index)

requirements.txt

#git+https://github.com/alecalve/python-bitcoin-blockchain-parser.git@c06f420995b345c9a193c8be6e0916eb70335863
git+https://github.com/cirosantilli/[email protected]
requests==2.31.0

I needed a small patch on my fork: https://github.com/alecalve/python-bitcoin-blockchain-parser/pull/112

Sample output:

tx 63f9df910b54c60a391e0842cd485c455f9c7fb7c7c79eb07706b2c0ef7ebe93
4294967295
[]
Script(ffff001d 8101)
4294967295
tx 58d089afb985c772232e17dec60c9eed5c281d985cace881fb1f6b34c43e7500
4294967295
[]
Script(ffff001d 5e)
4294967295

At https://github.com/cirosantilli/bitcoin-strings-with-txids/blob/b560fc0bcfb6f0f64a256bdcd15b48810262dc67/main.py I used some more of their functionality for my purposes which may serve as further reference.

I haven’t researched a lot before choosing this one, but it kind of works. Sometimes I wonder if there’s a faster one though in some compiled language, but this one gets there eventually.

[ad_2]

Source link


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *