Last active
January 23, 2019 21:30
-
-
Save banteg/a58e972a72e3f23b71bac699c7119690 to your computer and use it in GitHub Desktop.
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 os | |
from operator import itemgetter | |
from json import JSONDecodeError | |
from time import sleep | |
import click | |
import requests | |
import pendulum | |
LTO_NODE = 'http://127.0.0.1:6869' | |
LTO_API_KEY = os.environ['LTO_API_KEY'] | |
BRIDGE_TROLL_FEES = '3JrGV6TeEV3ovVjsh9SPqQL48EDLET47B9U' | |
BRIDGE_TROLL = '3JugjxT51cTjWAsgnQK4SpmMqK6qua1VpXH' | |
INITIAL_SUPPLY = 500_000_000 | |
CROWDSALE_BURNED = 39_267_891.526_663_22 | |
s = requests.session() | |
s.headers['X-API-Key'] = LTO_API_KEY | |
class ApiException(Exception): | |
pass | |
def lto(request): | |
r = s.get(f'{LTO_NODE}{request}') | |
r.raise_for_status() | |
try: | |
return r.json() | |
except JSONDecodeError: | |
raise ApiException(r.text) | |
def get_transactions(limit): | |
bridge_txs = lto(f'/transactions/address/{BRIDGE_TROLL}/limit/{limit}')[0] | |
fees_txs = lto(f'/transactions/address/{BRIDGE_TROLL_FEES}/limit/{limit}')[0] | |
return list(sorted(bridge_txs + fees_txs, key=itemgetter('height'))) | |
def tokens(value): | |
return value / 1e8 | |
def pretty_tx(tx): | |
if tx['sender'] == BRIDGE_TROLL: | |
symbol, message = '🌝', 'to mainnet' | |
if tx['recipient'] == BRIDGE_TROLL: | |
symbol, message = '🐬', 'to erc20' | |
if tx['recipient'] == BRIDGE_TROLL_FEES: | |
symbol, message = '🔥', 'burned' | |
ts = pendulum.from_timestamp(tx['timestamp'] / 1000) | |
value = tokens(tx['amount']) | |
print( | |
ts.to_datetime_string(), | |
symbol, | |
f'{value:12,.0f}', | |
message, | |
sep=' ', | |
) | |
@click.command() | |
@click.option('--watch', is_flag=True) | |
def main(watch): | |
seen = set() | |
burned = 0 | |
mainnet = 0 | |
for tx in get_transactions(10000): | |
pretty_tx(tx) | |
seen.add(tx['id']) | |
if tx['recipient'] == BRIDGE_TROLL_FEES: | |
burned += tokens(tx['amount']) | |
if tx['sender'] == BRIDGE_TROLL: | |
mainnet += tokens(tx['amount']) | |
supply = INITIAL_SUPPLY - CROWDSALE_BURNED - burned | |
print(f'-- burned = {burned:,.0f} from bridge + {CROWDSALE_BURNED:,.0f} from crowdsale') | |
print(f'-- moved to mainnet = {mainnet:,.0f}') | |
print(f'-- total supply = {supply:,.0f}') | |
if watch: | |
loop(seen) | |
def loop(seen): | |
while True: | |
for tx in get_transactions(100): | |
if tx['id'] in seen: | |
continue | |
pretty_tx(tx) | |
seen.add(tx['id']) | |
sleep(60) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment