Skip to content

Instantly share code, notes, and snippets.

@jwinterm
Last active March 5, 2017 02:13
Show Gist options
  • Save jwinterm/27cbe440d697d025963b3034123e73a0 to your computer and use it in GitHub Desktop.
Save jwinterm/27cbe440d697d025963b3034123e73a0 to your computer and use it in GitHub Desktop.
Count blocks mined by version in current signalling period for Vertcoin segwit update
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_VERTCOIN.CONF_FILE_GOES_HERE")
# Starting height for signalling
startheight = 675360
# Get current block height
height = int(rpc.getinfo()['blocks'])
print("Current height is: {0}".format(height))
# Calculate current window and blocks in current window
blocksfromstart = height-startheight
signallingperiod = blocksfromstart/2016
blocksintoperiod = blocksfromstart%2016
# print(blocksfromstart, signallingperiod, blocksintoperiod)
# Create set of lists for storing data
blockrange = int(sys.argv[1])
blocks = range(height-blocksintoperiod, height+1)
blockhashes = []
addresses = []
addresscounts = []
versions = []
versioncounts = []
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)
try:
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])
except: addresses.append("OP_return")
versions.append(version)
# print(addresses)
uniqueaddresses = list(set(addresses))
uniqueversions = list(set(versions))
for i in uniqueaddresses:
addresscounts.append(addresses.count(i))
for i in uniqueversions:
versioncounts.append(versions.count(i))
zipped = zip(addresscounts, uniqueaddresses)
zipped.sort()
print("{0:12} {1:40}".format("# of blocks", "Address/pool"))
for i in zipped:
print("{0:12} {1:40}".format(i[0], i[1]))
zipped = zip(versioncounts, uniqueversions)
zipped.sort()
print("{0:12} {1:40}".format("# of blocks", "Version"))
for i in zipped:
print("{0:12} {1:40}".format(i[0], i[1]))
print("""We are {0} blocks into the #{1} signalling period.
{2} out of {0} blocks are signalling for CSV etc BIPs.
{3} out of {0} blocks are signalling for segwit and other BIPS.
This represents {4:.2f}% signalling for CSV etc BIPs and {5:.2f}% signalling segwit.""".format(
blocksintoperiod, signallingperiod+1,
versioncounts[uniqueversions.index(536870917)], versioncounts[uniqueversions.index(536870919)],
(versioncounts[uniqueversions.index(536870917)]/float(blocksintoperiod)*100),
(versioncounts[uniqueversions.index(536870919)]/float(blocksintoperiod)*100)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment