Skip to content

Instantly share code, notes, and snippets.

@flatfly
Last active August 29, 2015 13:56
Show Gist options
  • Save flatfly/9151814 to your computer and use it in GitHub Desktop.
Save flatfly/9151814 to your computer and use it in GitHub Desktop.
chainsnort RPC (beta - to be refactored)
#chainsnort RPC 0.43.3beta by flatfly
from authproxy import AuthServiceProxy
import time, sys, datetime, os
def main():
global access
pwd=raw_input("Pwd:")
sys.tracebacklimit = 0
clr = os.system(['clear','cls'][os.name == 'nt'])
os.system('title chainsnort [mainnet] (RPC connector beta)')
print "Init RPC to [anonymized]:8999..." ,
access = AuthServiceProxy("http://rpc:"+pwd+"@12.34.56.78:8999")
pri = access.getconnectioncount()
print "Success! Capturing broadcasts from " + str(pri) + ' peers.\n'
mm1 = access.getrawmempool() ; TT1 = time.time() ; CC = 0
try:
while 1:
hh = access.getblockcount()
time.sleep(1.41)
mm2 = access.getrawmempool()
new_ = list(set(mm2) - set(mm1))
for item in new_:
val, max_addr, n_outputs, n_inputs = txdetails(item)
bigtag = ' '
if float(val) >= 10:
bigtag = '>>'
time.sleep(0.3)
print '\b'+ datetime.datetime.utcnow().strftime("%H:%M:%S.%f")[:-3], ' ', bigtag + ' {:11.4f}'.format(float(val)), 'B' , ' ' , max_addr, '\t\b['+n_inputs+':'+n_outputs+']'
mm1 = mm2
CC += len(new_)
except KeyboardInterrupt:
TT2 = time.time()
print
print "Closing threads..." , ' Captured',CC, 'events - Transaction density: %02.02f' % (CC/(TT2 - TT1)) , 'tx/sec'
sys.exit()
def txdetails(it):
rawtx = access.getrawtransaction(it)
decoded = access.decoderawtransaction(rawtx)
VV = str(sum(p['value'] for p in decoded['vout'])) # /1e8
LL = len (decoded['vout'])
NN = len (decoded['vin'])
return VV , decoded['vout'][0]['scriptPubKey']['addresses'][0] , str(LL) , str(NN)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment