From ac72836b1bbfbd1288acc5baef11eff03f4fd7de Mon Sep 17 00:00:00 2001 From: Paim pozhil Date: Wed, 25 Apr 2018 22:07:04 +0530 Subject: [PATCH 1/2] Create fetch_tx_inputs.py Get all the the blocks transaction inputs --- examples/fetch_tx_inputs.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 examples/fetch_tx_inputs.py diff --git a/examples/fetch_tx_inputs.py b/examples/fetch_tx_inputs.py new file mode 100644 index 0000000..acfb1f0 --- /dev/null +++ b/examples/fetch_tx_inputs.py @@ -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)) From 3644c36ccd5b6bbda3fe2b007bf2243d0f8021bd Mon Sep 17 00:00:00 2001 From: Paim pozhil Date: Wed, 25 Apr 2018 22:07:59 +0530 Subject: [PATCH 2/2] Create fetch_tx_outputs.py Easy way to fetch all the tx into stdout --- examples/fetch_tx_outputs.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 examples/fetch_tx_outputs.py diff --git a/examples/fetch_tx_outputs.py b/examples/fetch_tx_outputs.py new file mode 100644 index 0000000..a7f67fe --- /dev/null +++ b/examples/fetch_tx_outputs.py @@ -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))