Skip to content

Instantly share code, notes, and snippets.

@jinhwanlazy
Last active November 22, 2017 10:32
Show Gist options
  • Save jinhwanlazy/1637ebc2118c05e96fab4aaeffdb3300 to your computer and use it in GitHub Desktop.
Save jinhwanlazy/1637ebc2118c05e96fab4aaeffdb3300 to your computer and use it in GitHub Desktop.
bos_distribution.py
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))
@jinhwanlazy
Copy link
Author

Thanks. It's too bad that the transaction history is no longer traceable so now this script is useless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment