Last active
December 13, 2016 14:36
-
-
Save jwinterm/52f95fc7f34e28e3216cba2107e86578 to your computer and use it in GitHub Desktop.
Script to get block distribution over last 'x' blocks on Bitcoin clone
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
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="YOUR_CONF_FILE_LOCATION_HERE") | |
# 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 = [] | |
for i in blocks: | |
blockhash = rpc.getblockhash(i) | |
blockhashes.append(blockhash) | |
block = rpc.getblock(blockhash) | |
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') | |
elif "Vhe4y3qia" in address[0]: | |
addresses.append("GiveMeCoins") | |
elif "VqspNKCc3" in address[0]: | |
addresses.append("MiningPoolHub") | |
elif "VeA2dmBhJ" in address[0]: | |
addresses.append("AikaPool") | |
elif "VuPp8H4W3" in address[0]: | |
addresses.append("Coinotron") | |
else: | |
addresses.append(address[0]) | |
# print(addresses) | |
uniqueaddresses = list(set(addresses)) | |
explode=[] | |
for i in uniqueaddresses: | |
addresscounts.append(addresses.count(i)) | |
explode.append(0.05) | |
print(i, addresses.count(i)) | |
colors = ('b', 'g', 'r', 'c', 'm', 'y', 'w') | |
ax1 = plt.axes([0.25, 0.2, 0.5, 0.5]) | |
pie_wedge_collection = ax1.pie( | |
addresscounts, | |
labels=uniqueaddresses, | |
labeldistance=1.07, | |
explode=explode, | |
autopct='%1.1f%%', | |
shadow=True, | |
startangle=90, | |
colors=colors | |
) | |
for pie_wedge in pie_wedge_collection[0]: | |
pie_wedge.set_edgecolor('0.3') | |
for i in pie_wedge_collection[1]: | |
i.set_fontsize('xx-small') | |
for i in pie_wedge_collection[2]: | |
i.set_fontsize('xx-small') | |
plt.title("Vertcoin network snapshot of the last {0:.0f} blocks\nRecorded at block # {1} and time {2} UTC".format( | |
blockrange, height, datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"))) | |
plt.savefig('vtcpools.png', dpi=300) | |
plt.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment