Created
April 16, 2019 19:14
-
-
Save jhodges10/a364a34f8b516ce98fff41b3375b8110 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException | |
import time, os, sys | |
import logging | |
from pprint import pprint | |
rpc_password = "admin" | |
rpc_user = "admin" | |
coinbase_tx_count = 0 | |
def rpc_conn(user=rpc_user, password=rpc_password): | |
rpc_conn = AuthServiceProxy("http://%s:%s@localhost:19998" % (user, password)) | |
return rpc_conn | |
def parse_tx(input_tx_list): | |
global coinbase_tx_count | |
for tx in input_tx_list: | |
tx1_info = rpc_conn().gettxout(tx, 0) | |
# tx2_info = rpc_conn().gettxout(tx, 1) | |
if tx1_info is not None: | |
coinbase_tx_count += 1 | |
else: | |
pass | |
return True | |
def scan_blocks(): | |
latest_block = rpc_conn().getblockcount() | |
# print(latest_block) | |
cur_block = latest_block - 2000 | |
while cur_block <= latest_block: | |
print("TX info for block {}".format(cur_block)) | |
try: | |
block_hash = rpc_conn().getblockhash(cur_block) | |
block_info = rpc_conn().getblock(str(block_hash)) | |
# pprint(block_info) | |
parse_tx(block_info['tx']) | |
except JSONRPCException as e: | |
print("Crashed because of {}".format(e)) | |
sys.exit(1) | |
cur_block += 1 | |
global coinbase_tx_count | |
print(coinbase_tx_count) | |
if __name__ == '__main__': | |
scan_blocks() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment