Last active
November 22, 2017 10:32
-
-
Save jinhwanlazy/1637ebc2118c05e96fab4aaeffdb3300 to your computer and use it in GitHub Desktop.
bos_distribution.py
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
import json | |
import signal | |
from operator import itemgetter | |
from decimal import Decimal | |
from boscoin_base.address import Address | |
def handle_timeout(signum, frame): | |
raise | |
if __name__ == "__main__": | |
src_addr = 'GAMX6BVPNPWWRGGAUZGT57YG4ZYNI3FO5UHXYSGYBODQVFWIEBWVFDRX' | |
bos = Address(src_addr, network='PUBLIC') | |
payments_stream = bos.payments(sse=True, limit='200') | |
res = {} | |
while True: | |
signal.signal(signal.SIGALRM, handle_timeout) | |
signal.alarm(3) | |
try: | |
msg = next(payments_stream) | |
except: | |
break | |
finally: | |
signal.alarm(0) | |
data = json.loads(msg.data) | |
if (data == 'hello'): | |
continue | |
if data['source_account'] != src_addr: | |
continue | |
if data['type'] == 'create_account': | |
time, addr, amount = data['created_at'], data['account'], data['starting_balance'] | |
else: | |
time, addr, amount = data['created_at'], data['to'], data['amount'] | |
prev = res.setdefault(addr, ["", Decimal('0')]) | |
prev[0] = time | |
prev[1] += Decimal(amount) | |
res = sorted(((t, a, d) for a, (t, d) in res.items()), reverse=True, key=itemgetter(2)) | |
print('time,address,balance') | |
print('\n'.join(','.join(map(str, l)) for l in res)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. It's too bad that the transaction history is no longer traceable so now this script is useless.