From cf5f7204c7447d1cb414bf701f4b0d0ed96d4e6d Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 6 Feb 2026 10:14:20 +0000 Subject: [PATCH] xmrwallet.ops.wallet, mmgen-addrimport: cleanups --- mmgen/main_addrimport.py | 6 +++--- mmgen/xmrwallet/ops/create.py | 1 - mmgen/xmrwallet/ops/wallet.py | 28 +++++++++++++++------------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/mmgen/main_addrimport.py b/mmgen/main_addrimport.py index 80f932f1..f538ad0d 100755 --- a/mmgen/main_addrimport.py +++ b/mmgen/main_addrimport.py @@ -33,7 +33,7 @@ opts_data = { 'options': """ -h, --help Print this help message --, --longhelp Print help message for long (global) options --a, --address=a Import the single coin address 'a' +-A, --address=ADDR Import the single coin address ADDR -b, --batch Import all addresses in one RPC call -l, --addrlist Address source is a flat list of non-MMGen coin addresses -k, --keyaddr-file Address source is a key-address file @@ -42,7 +42,7 @@ opts_data = { blockchain for unspent outputs that include the imported address(es). Required if any of the imported addresses are already in the blockchain and have a balance. --t, --token-addr=A Import addresses for ERC20 token with address 'A' +-t, --token-addr=ADDR Import addresses for ERC20 token with address ADDR """, 'notes': """ @@ -131,8 +131,8 @@ def check_opts(twctl): return batch, rescan async def main(): - from .tw.ctl import TwCtl + from .tw.ctl import TwCtl twctl = await TwCtl( cfg = cfg, proto = proto, diff --git a/mmgen/xmrwallet/ops/create.py b/mmgen/xmrwallet/ops/create.py index 25f6031a..e9098d7f 100755 --- a/mmgen/xmrwallet/ops/create.py +++ b/mmgen/xmrwallet/ops/create.py @@ -21,7 +21,6 @@ from .wallet import OpWallet class OpCreate(OpWallet): stem = 'creat' - wallet_exists = False opts = ('restore_height',) def check_uopts(self): diff --git a/mmgen/xmrwallet/ops/wallet.py b/mmgen/xmrwallet/ops/wallet.py index 5a0278bf..1cb7381e 100755 --- a/mmgen/xmrwallet/ops/wallet.py +++ b/mmgen/xmrwallet/ops/wallet.py @@ -34,32 +34,25 @@ class OpWallet(OpBase): 'autosign', 'watch_only') wallet_offline = False - wallet_exists = True start_daemon = True skip_wallet_check = False # for debugging def __init__(self, cfg, uarg_tuple): - def wallet_exists(fn): - try: - fn.stat() - except: - return False - else: - return True - def check_wallets(): for d in self.addr_data: fn = self.get_wallet_fn(d) - match wallet_exists(fn): - case True if not self.wallet_exists: + match self.stat_wallet(fn): + case True if self.is_create: die(1, f'Wallet ‘{fn}’ already exists!') - case False if self.wallet_exists: + case False: die(1, f'Wallet ‘{fn}’ not found!') super().__init__(cfg, uarg_tuple) - if self.cfg.offline or (self.name == 'create' and self.cfg.restore_height is None): + self.is_create = self.name in ('create', 'create_offline', 'restore') + + if self.cfg.offline or (self.is_create and self.cfg.restore_height is None): self.wallet_offline = True self.wd = MoneroWalletDaemon( @@ -122,6 +115,15 @@ class OpWallet(OpBase): if self.start_daemon and not self.cfg.no_start_wallet_daemon: asyncio.run(self.restart_wallet_daemon()) + @staticmethod + def stat_wallet(fn): + try: + fn.stat() + except: + return False + else: + return True + @classmethod def get_idx_from_fn(cls, fn): return int(re.match(r'[0-9a-fA-F]{8}-(\d+)-Monero(WatchOnly)?Wallet.*', fn.name)[1])