From bfc40fce4d4f513f2149002f2c077af44822090b Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Tue, 12 May 2020 16:37:59 +0000 Subject: [PATCH] halving-calculator.py: a few minor fixes --- README.md | 2 -- examples/halving-calculator.py | 15 ++++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e7f0553a..9a716a0c 100644 --- a/README.md +++ b/README.md @@ -137,8 +137,6 @@ Linux, Armbian, Raspbian, Windows/MSYS2 ### Download/Install -> #### [Install a prebuilt bootable image (MMGenLive) on a USB stick][8] - > #### [Install from source on Microsoft Windows][1] > #### [Install from source on Debian, Ubuntu, Raspbian or Armbian Linux][2] diff --git a/examples/halving-calculator.py b/examples/halving-calculator.py index 1f7b24f9..365a97c7 100755 --- a/examples/halving-calculator.py +++ b/examples/halving-calculator.py @@ -13,7 +13,6 @@ 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]) @@ -23,7 +22,7 @@ def dhms(t): def time_diff_warning(t_diff): if abs(t_diff) > 60*60: - print('Warning: block tip time is {} {} current time!'.format( + print('Warning: block tip time is {} {} clock time!'.format( dhms(abs(t_diff)), ('behind','ahead of')[t_diff<0])) @@ -31,24 +30,26 @@ async def main(): from mmgen.rpc import rpc_init c = await rpc_init() tip = await c.call('getblockcount') + remaining = HalvingInterval - tip % HalvingInterval + sample_size = max(remaining,144) # 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'])) + clock_time = int(time.time()) + time_diff_warning(clock_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") + 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'Current clock time (UTC): {date(clock_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()))}') + print(f'Est. time until halving: {dhms(cur["time"] + t_rem - clock_time)}') run_session(main(),do_rpc_init=False)