From 9482ecc705f5235eb744cafe064a254e06c6bebe Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Tue, 15 Sep 2026 10:50:57 +0000 Subject: [PATCH] new `CR` global constant --- mmgen/cfg.py | 4 +++- mmgen/proto/btc/misc.py | 4 ++-- mmgen/proto/btc/tw/ctl.py | 7 +++---- mmgen/wallet/dieroll.py | 6 +++--- mmgen/wallet/unenc.py | 3 ++- test/overlay/fakemods/mmgen/cfg.py | 2 ++ 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/mmgen/cfg.py b/mmgen/cfg.py index 5c23f847..9a681464 100755 --- a/mmgen/cfg.py +++ b/mmgen/cfg.py @@ -59,6 +59,8 @@ class GlobalConstants(Lockable): min_screen_width = 80 min_time_precision = 18 + CR = '\r' + # core_coins must match CoinProtocol.coins core_coins = ('btc', 'bch', 'ltc', 'eth', 'etc', 'zec', 'xmr', 'rune') rpc_coins = ('btc', 'bch', 'ltc', 'eth', 'etc', 'xmr', 'rune') @@ -258,7 +260,7 @@ class Config(Lockable): xmrwallet_compat = False priority = 0 - test_suite = False # 30 references + test_suite = False # 25 references # external use: _opts = None diff --git a/mmgen/proto/btc/misc.py b/mmgen/proto/btc/misc.py index d67f7f33..febc0a1c 100755 --- a/mmgen/proto/btc/misc.py +++ b/mmgen/proto/btc/misc.py @@ -12,6 +12,7 @@ proto.btc.misc: miscellaneous functions for Bitcoin base protocol """ +from ...cfg import gc from ...util import msg, msg_r async def scantxoutset(cfg, rpc, descriptor_list): @@ -27,9 +28,8 @@ async def scantxoutset(cfg, rpc, descriptor_list): async def do_status(): - CR = '\n' if cfg.test_suite else '\r' sleep_secs = 0.1 if cfg.test_suite else 2 - m = f'{CR}Scanning UTXO set: ' + m = f'{gc.CR}Scanning UTXO set: ' msg_r(m + '0% completed ') while True: diff --git a/mmgen/proto/btc/tw/ctl.py b/mmgen/proto/btc/tw/ctl.py index 888f7512..cb2df6bd 100755 --- a/mmgen/proto/btc/tw/ctl.py +++ b/mmgen/proto/btc/tw/ctl.py @@ -12,6 +12,7 @@ proto.btc.tw.ctl: Bitcoin base protocol tracking wallet control class """ +from ....cfg import gc from ....tw.ctl import TwCtl, write_mode from ....util import msg, msg_r, rmsg, die, suf, fmt_list @@ -61,7 +62,6 @@ class BitcoinTwCtl(TwCtl): start = start or 0 endless = stop is None - CR = '\n' if self.cfg.test_suite else '\r' if not (start >= 0 and (stop if stop is not None else start) >= start): die(1, f'{start} {stop}: invalid range') @@ -69,7 +69,7 @@ class BitcoinTwCtl(TwCtl): async def do_scan(chunks, tip): res = None for a, b in chunks: - msg_r(f'{CR}Scanning blocks {a}-{b} ') + msg_r(f'{gc.CR}Scanning blocks {a}-{b} ') res = await self.rpc.call('rescanblockchain', a, b, timeout=7200) if res['start_height'] != a or res['stop_height'] != b: die(1, f'\nAn error occurred in block range {a}-{b}') @@ -119,9 +119,8 @@ class BitcoinTwCtl(TwCtl): len(blocks), suf(blocks))) self.cfg._util.vmsg(f'Blocks to rescan: {fmt_list(blocks, fmt="bare")}') - CR = '\n' if self.cfg.test_suite else '\r' for n, block in enumerate(blocks): - msg_r(f'{CR}Rescanning block: {block} ({n+1}/{len(blocks)})') + msg_r(f'{gc.CR}Rescanning block: {block} ({n+1}/{len(blocks)})') # httplib seems to require fresh connection here, so specify timeout await self.rpc.call('rescanblockchain', block, block, timeout=60) msg(f'\nAddress balance{suf(coin_addrs)} updated successfully') diff --git a/mmgen/wallet/dieroll.py b/mmgen/wallet/dieroll.py index f12d9858..bfd605c8 100755 --- a/mmgen/wallet/dieroll.py +++ b/mmgen/wallet/dieroll.py @@ -13,6 +13,7 @@ wallet.dieroll: dieroll wallet class """ import time +from ..cfg import gc from ..util import msg, msg_r, die, fmt, remove_whitespace from ..util2 import block_format from ..seed import Seed @@ -97,10 +98,9 @@ class wallet(wallet): CUR_HIDE = '\033[?25l' CUR_SHOW = '\033[?25h' - cr = '\n' if self.cfg.test_suite else '\r' - prompt_fs = f'\b\b\b {cr}Enter die roll #{{}}: {CUR_SHOW}' + prompt_fs = f'\b\b\b {gc.CR}Enter die roll #{{}}: {CUR_SHOW}' clear_line = '' if self.cfg.test_suite else '\r' + ' ' * 25 - invalid_msg = CUR_HIDE + cr + 'Invalid entry' + ' ' * 11 + invalid_msg = CUR_HIDE + gc.CR + 'Invalid entry' + ' ' * 11 from ..term import get_char def get_digit(n): diff --git a/mmgen/wallet/unenc.py b/mmgen/wallet/unenc.py index affb2b85..f3585625 100755 --- a/mmgen/wallet/unenc.py +++ b/mmgen/wallet/unenc.py @@ -12,6 +12,7 @@ wallet.unenc: unencrypted wallet base class """ +from ..cfg import gc from ..color import blue, yellow from ..util import msg, msg_r, capfirst, is_int from .base import wallet @@ -43,7 +44,7 @@ class wallet(wallet): r = get_char('\r'+prompt) if is_int(r) and 1 <= int(r) <= len(ok_lens): break - msg_r(('\r', '\n')[self.cfg.test_suite] + ' '*len(prompt) + '\r') + msg_r(gc.CR + ' ' * len(prompt) + '\r') return ok_lens[int(r)-1] while True: diff --git a/test/overlay/fakemods/mmgen/cfg.py b/test/overlay/fakemods/mmgen/cfg.py index 5448d300..4ac24b0a 100644 --- a/test/overlay/fakemods/mmgen/cfg.py +++ b/test/overlay/fakemods/mmgen/cfg.py @@ -12,6 +12,8 @@ test.overlay.fakemods.mmgen.cfg: overlay setup for cfg.py from .cfg_orig import * +GlobalConstants.CR = '\n' + for k, v in { # NB: check carefully that none of these attrs are required by Config(), Opts() # or anything they import or call before the lock is set in Config()