-
-
Save lessmore92/ece19de56afddc268cb74add34927d99 to your computer and use it in GitHub Desktop.
chainsnort (cross-platform console transaction monitor)
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 json, sys, time, urllib, websocket, operator | |
sys.tracebacklimit = 0 | |
t0 = time.ctime() ; Z = 0 | |
print 'chainsnort 0.410: ' , | |
def main(): | |
global Z | |
while (1): | |
bigtag = ' ' | |
result = ws.recv() | |
result = json.loads(result) | |
if result['op'] == 'block' : | |
reward = result['x']['reward']/1e8 | |
print '\b' + time.ctime()[11:-5] , bigtag + ' {:11.4f}'.format(reward) ,'B [NEW BLOCK SOLVED] ' , | |
print str(result['x']['height']) | |
continue | |
inputs = sum(p['prev_out']['value'] for p in result['x']['inputs'] ) | |
outputs = sum(p['value'] for p in result['x']['out'] ) | |
feepaid = (inputs-outputs)/1e8 | |
val = sum(p['value'] for p in result['x']['out'])/1e8 | |
max_addr = sorted(result['x']['out'], key=operator.itemgetter('value'), reverse=True)[0]['addr'] | |
if val >= 50: | |
if val >= 5000: | |
print '\a' , | |
bigtag = '>>' | |
time.sleep(0.3) | |
print '\b' + time.ctime()[11:-5], bigtag + ' {:11.4f}'.format(val) ,'B ' , max_addr , '\t ' , | |
if feepaid < 0.0001 or feepaid >= 0.01: | |
print '\b' , | |
print '{:12.8f}'.format(feepaid) | |
Z += 1 | |
try: | |
domain='blockchain.info' | |
stat = int(urllib.urlopen('https://'+domain+'/q/24hrtransactioncount').read().decode("utf8")) | |
print '\b' + str(stat) + ' new transactions in the last 24 hours - ' + '%02.02f' % (stat/86400.0) + ' tx/sec' | |
ws = websocket.create_connection("ws://ws."+domain+":8335/inv") | |
ws.send('{"op":"unconfirmed_sub"}') ; | |
ws.send('{"op":"blocks_sub"}') ; time.clock() | |
main() | |
except KeyboardInterrupt: | |
deltaT = time.clock() | |
print "Closing threads..." , ' (Captured',Z, 'events)' # Transaction density: %02.02f' % (Z/deltaT) , 'tx/s)' | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment