Skip to content

Commit 3644c36

Browse files
authored
Create fetch_tx_outputs.py
Easy way to fetch all the tx into stdout
1 parent ac72836 commit 3644c36

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

examples/fetch_tx_outputs.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
import sys
3+
from blockchain_parser.blockchain import Blockchain
4+
5+
# Instantiate the Blockchain by giving the path to the directory
6+
# containing the .blk files created by bitcoind
7+
blockchain = Blockchain(os.path.expanduser('/bitcoin-data/blocks'))
8+
print("block_height,block.header_timestamp,tx.hash,no,output.type,address,output_value")
9+
for block in blockchain.get_ordered_blocks(os.path.expanduser('/bitcoin-data/blocks/index'),start=int(sys.argv[1]), end=int(sys.argv[2])):
10+
for tx in block.transactions:
11+
for no, output in enumerate(tx.outputs):
12+
try:
13+
print("%s,%s,%s,%d,%s,%s,%s" % (block.height,block.header.timestamp,tx.hash, no, output.type, output.addresses[0].address if output.addresses else output.addresses , output.value))
14+
except Exception:
15+
print("%s,%s,%s,%d,%s,%s,%s" % (block.height,block.header.timestamp,tx.hash, no, "no","no", output.value))

0 commit comments

Comments
 (0)