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)) 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))