From c4f6203eef50535e0c5c614d53b8c23903e6c0ce Mon Sep 17 00:00:00 2001 From: Shannon Appelcline Date: Wed, 2 Sep 2020 15:24:25 -1000 Subject: [PATCH] Create 17_4_getinfo.py --- src/17_4_getinfo.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/17_4_getinfo.py diff --git a/src/17_4_getinfo.py b/src/17_4_getinfo.py new file mode 100644 index 0000000..67ec0f4 --- /dev/null +++ b/src/17_4_getinfo.py @@ -0,0 +1,45 @@ +from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException +from pprint import pprint +import logging + +logging.basicConfig() +logging.getLogger("BitcoinRPC").setLevel(logging.DEBUG) +# rpc_user and rpc_password are set in the bitcoin.conf file +rpc_user = "StandUp" +rpc_pass = "6305f1b2dbb3bc5a16cd0f4aac7e1eba" +rpc_host = "127.0.0.1" +rpc_client = AuthServiceProxy(f"http://{rpc_user}:{rpc_pass}@{rpc_host}:18332", +timeout=120) + +block_count = rpc_client.getblockcount() +print("---------------------------------------------------------------") +print("Block Count:", block_count) +print("---------------------------------------------------------------\n") + +blockhash = rpc_client.getblockhash(block_count) +block = rpc_client.getblock(blockhash) + +nTx = block['nTx'] +if nTx > 10: + it_txs = 10 + list_tx_heading = "First 10 transactions: " +else: + it_txs = nTx + list_tx_heading = f"All the {it_txs} transactions: " +print("---------------------------------------------------------------") +print("BLOCK: ", block_count) +print("-------------") +print("Block Hash...: ", blockhash) +print("Merkle Root..: ", block['merkleroot']) +print("Block Size...: ", block['size']) +print("Block Weight.: ", block['weight']) +print("Nonce........: ", block['nonce']) +print("Difficulty...: ", block['difficulty']) +print("Number of Tx.: ", nTx) +print(list_tx_heading) +print("---------------------") +i = 0 +while i < it_txs: + print(i, ":", block['tx'][i]) + i += 1 +print("---------------------------------------------------------------\n")