From 86fd45566dd87a3917f5cfbbb2c21ff46d1a9210 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 11 May 2020 18:07:58 +0000 Subject: [PATCH] new file: examples/halving-calculator.py --- MANIFEST.in | 2 ++ examples/halving-calculator.py | 54 ++++++++++++++++++++++++++++++++++ mmgen/altcoins/eth/tw.py | 3 -- 3 files changed, 56 insertions(+), 3 deletions(-) create mode 100755 examples/halving-calculator.py diff --git a/MANIFEST.in b/MANIFEST.in index 4cb3459a..cb276dfc 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -26,4 +26,6 @@ include scripts/create-token.py include scripts/traceback_run.py include scripts/uninstall-mmgen.py +include examples/halving-calculator.py + prune test/ref/__db* diff --git a/examples/halving-calculator.py b/examples/halving-calculator.py new file mode 100755 index 00000000..1f7b24f9 --- /dev/null +++ b/examples/halving-calculator.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 + +# Demonstrates use of the MMGen asyncio/aiohttp JSON-RPC interface +# https://github.com/mmgen/mmgen +# Requires a running Bitcoin Core node +# If necessary, invoke with --rpc-host/--rpc-port/--rpc-user/--rpc-password +# Specify aiohttp backend with --rpc-backend=aiohttp (Linux only) + +import time +from decimal import Decimal +from mmgen.common import * + +opts.init({ 'text': { 'desc':'', 'usage':'', 'options':'' }}) + +HalvingInterval = 210000 # src/chainparams.cpp +sample_size = 6 * 24 # about a day's worth of blocks + +def date(t): + return '{}-{:02}-{:02} {:02}:{:02}:{:02}'.format(*time.gmtime(t)[:6]) + +def dhms(t): + return f'{t//60//60//24} days, {t//60//60%24:02}:{t//60%60:02}:{t%60:02} h/m/s' + +def time_diff_warning(t_diff): + if abs(t_diff) > 60*60: + print('Warning: block tip time is {} {} current time!'.format( + dhms(abs(t_diff)), + ('behind','ahead of')[t_diff<0])) + +async def main(): + from mmgen.rpc import rpc_init + c = await rpc_init() + tip = await c.call('getblockcount') + + # aiohttp backend will perform these two calls concurrently: + cur,old = await c.gathered_call('getblockstats',((tip,),(tip - sample_size,))) + + time_diff_warning(int(time.time() - cur['time'])) + + remaining = HalvingInterval - tip % HalvingInterval + bdr = (cur['time'] - old['time']) / sample_size + t_rem = remaining * int(bdr) + sub = cur['subsidy'] * Decimal("0.00000001") + + print(f'Current block: {tip}') + print(f'Next halving block: {tip + remaining}') + print(f'Blocks until halving: {remaining}') + print('Current block subsidy: {} BTC'.format(str(sub).rstrip('0'))) + print(f'Current block discovery rate (over last {sample_size} blocks): {bdr/60:0.1f} minutes') + print(f'Current clock time (UTC): {date(time.time())}') + print(f'Est. halving date (UTC): {date(cur["time"] + t_rem)}') + print(f'Est. time until halving: {dhms(cur["time"] + t_rem - int(time.time()))}') + +run_session(main(),do_rpc_init=False) diff --git a/mmgen/altcoins/eth/tw.py b/mmgen/altcoins/eth/tw.py index 28daa69b..41dfd461 100755 --- a/mmgen/altcoins/eth/tw.py +++ b/mmgen/altcoins/eth/tw.py @@ -276,9 +276,6 @@ Actions: [q]uit view, [p]rint to file, pager [v]iew, [w]ide view, def age_disp(self,o,age_fmt): # TODO return None - def age_disp(self,o,age_fmt): # TODO - return None - class EthereumTokenTwUnspentOutputs(EthereumTwUnspentOutputs): disp_type = 'token'