Skip to content

Instantly share code, notes, and snippets.

@jwinterm
Last active March 2, 2017 02:36
Show Gist options
  • Save jwinterm/0352ebec30c363fcde374f9e8289e466 to your computer and use it in GitHub Desktop.
Save jwinterm/0352ebec30c363fcde374f9e8289e466 to your computer and use it in GitHub Desktop.
import bitcoin.rpc
import sys
import binascii
import bitcoin.core
import matplotlib.pyplot as plt
import datetime
# Setup proxy for communicating with daemon
rpc = bitcoin.rpc.Proxy(btc_conf_file="PATH_TO_YOUR_CONF_FILE")
# Get current block height
height = int(rpc.getinfo()['blocks'])
print("Current height is: {0}".format(height))
# Create set of lists for storing data
blockrange = int(sys.argv[1])
blocks = range(height-blockrange, height+1)
blockhashes = []
addresses = []
addresscounts = []
# Test address for Arubi
# print(rpc.validateaddress('VwryYPw9sT2BUJsCVmLkeoHBWHgw325qo7'))
for i in blocks:
blockhash = rpc.getblockhash(i)
blockhashes.append(blockhash)
block = rpc.getblock(blockhash)
blockheader = block.get_header()
version = blockheader.nVersion
tx = bitcoin.core.b2lx(block.vtx[0].GetHash())
hextx = rpc._call('getrawtransaction', tx)
address = rpc._call('decoderawtransaction',
hextx)['vout'][0]['scriptPubKey']['addresses']
amount = rpc._call('decoderawtransaction',
hextx)['vout'][0]['value']
# print(i, address, amount)
if float(amount) < 50:
addresses.append(('p2pool', version))
elif "Vhe4y3qia" in address[0]:
addresses.append(("GiveMeCoins", version))
elif "VqspNKCc3" in address[0]:
addresses.append(("MiningPoolHub", version))
elif "VeA2dmBhJ" in address[0]:
addresses.append(("AikaPool", version))
elif "VuPp8H4W3" in address[0]:
addresses.append(("Coinotron", version))
else:
addresses.append((address[0], version))
# print(addresses)
uniqueaddresses = list(set(addresses))
explode=[]
for i in uniqueaddresses:
addresscounts.append(addresses.count(i))
zipped = zip(addresscounts, uniqueaddresses)
zipped.sort()
print(zipped)
print("{0:12} {1:40} {2:12}".format("# of blocks", "Address/pool", "Version bits"))
for i in zipped:
print("{0:12} {1:40} {2:12}".format(i[0], i[1][0], i[1][1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment