Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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))
@spikeekips

This comment has been minimized.

Copy link

@spikeekips spikeekips commented Nov 7, 2017

Good job.

As I know, the base timezone of tokennet of BOSCoin is the Etc/UTC, it will be better to add the name of the timezone. :)

@jinhwanlazy

This comment has been minimized.

Copy link
Owner Author

@jinhwanlazy jinhwanlazy commented Nov 22, 2017

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