Skip to content

New examples for transaction lists with inputs from commandline args #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions examples/fetch_tx_inputs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys
from blockchain_parser.blockchain import Blockchain
from blockchain_parser.transaction import Transaction


# Instantiate the Blockchain by giving the path to the directory
# containing the .blk files created by bitcoind
blockchain = Blockchain(os.path.expanduser('/bitcoin-data/blocks'))
print("block_height,block_header_timestamp,tx_hash,no,input_transaction_hash,input_transaction_index")
for block in blockchain.get_ordered_blocks(os.path.expanduser('/bitcoin-data/blocks/index'),start=int(sys.argv[1]), end=int(sys.argv[2]), cache='index-cache.pickle'):
for tx in block.transactions:
for no, input in enumerate(tx.inputs):
print("%s,%s,%s,%s,%s,%s" % (block.height,block.header.timestamp,tx.hash, no,(input.transaction_hash),input.transaction_index))
15 changes: 15 additions & 0 deletions examples/fetch_tx_outputs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import sys
from blockchain_parser.blockchain import Blockchain

# Instantiate the Blockchain by giving the path to the directory
# containing the .blk files created by bitcoind
blockchain = Blockchain(os.path.expanduser('/bitcoin-data/blocks'))
print("block_height,block.header_timestamp,tx.hash,no,output.type,address,output_value")
for block in blockchain.get_ordered_blocks(os.path.expanduser('/bitcoin-data/blocks/index'),start=int(sys.argv[1]), end=int(sys.argv[2])):
for tx in block.transactions:
for no, output in enumerate(tx.outputs):
try:
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))
except Exception:
print("%s,%s,%s,%d,%s,%s,%s" % (block.height,block.header.timestamp,tx.hash, no, "no","no", output.value))