Created
January 15, 2014 05:40
-
-
Save arowser/8431378 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#chainsnort 0.43.3 by flatfly | |
#requires websocket-client! | |
import json, os, sys, datetime, time, urllib, websocket, operator, random, re | |
clr = os.system(['clear','cls'][os.name == 'nt']) | |
t0 = time.time() ; Z = 0 | |
print 'chainsnort 0.43.3: ' , | |
class Plex(object): | |
def __init__(self, name): | |
self.file = open(name, 'w') | |
self.stdout = sys.stdout | |
sys.stdout = self | |
def __del__(self): | |
sys.stdout = self.stdout | |
self.file.close() | |
def write(self, data): | |
self.stdout.write(data) | |
data=data.replace(chr(8),'') | |
data=data.replace(chr(0x1B),'') | |
data=re.sub('\[.*m','',data) | |
self.file.write(data) | |
def main(): | |
global Z | |
while (1): | |
bigtag = ' ' | |
result = ws.recv() | |
time.sleep(0.05) | |
result = json.loads(result) | |
if result['op'] == 'block' : | |
reward = result['x']['reward']/1e8 | |
print datetime.datetime.utcnow().strftime("%H:%M:%S.%f")[:-3] , 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) | |
feetag = '' | |
if feepaid < 0.0001 or feepaid >= 0.01: | |
feetag = '' | |
print '\b'+ datetime.datetime.utcnow().strftime("%H:%M:%S.%f")[:-3], bigtag + ' {:11.4f}'.format(val) ,'B ' + '' , max_addr , '\t' , feetag , '\b'*6 + '{:12.8f}'.format(feepaid) + '' | |
Z += 1 | |
try: | |
sys.tracebacklimit = 0 | |
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' | |
print '\nEstablishing TLS tunnel...', | |
ws = websocket.create_connection("wss://ws."+domain+"/inv") | |
ws.send('{"op":"unconfirmed_sub"}') ; | |
ws.send('{"op":"blocks_sub"}') | |
print 'Done. Waiting for new transactions...\r', | |
if '-o' in sys.argv: | |
Plex('txtrace.log') | |
time.sleep(0.3) | |
main() | |
except KeyboardInterrupt: | |
t1 = time.time() | |
print "Closing threads..." , ' Captured',Z, 'events - Transaction density: %02.02f' % (Z/(t1 - t0)) , 'tx/sec' | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment