From b9328d9a45201ac0c100df714ee07d6178f53bf2 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Tue, 23 Sep 2025 09:20:54 +0000 Subject: [PATCH] xmrwallet: use match statement where practicable (3 files) --- mmgen/xmrwallet/ops/restore.py | 13 +++++++------ mmgen/xmrwallet/ops/spec.py | 21 +++++++++++---------- mmgen/xmrwallet/ops/wallet.py | 10 +++++----- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/mmgen/xmrwallet/ops/restore.py b/mmgen/xmrwallet/ops/restore.py index 71ca74ba..1225d8c9 100755 --- a/mmgen/xmrwallet/ops/restore.py +++ b/mmgen/xmrwallet/ops/restore.py @@ -36,15 +36,16 @@ class OpRestore(OpCreate): if ret.exists(): yield ret - dump_fns = tuple(gen()) - if not dump_fns: - die(1, f"No suitable dump file found for '{fn}'") - elif len(dump_fns) > 1: - ymsg(f"Warning: more than one dump file found for '{fn}' - using the first!") + match tuple(gen()): + case [dump_fn, *rest]: + if rest: + ymsg(f"Warning: more than one dump file found for '{fn}' - using the first!") + case _: + die(1, f"No suitable dump file found for '{fn}'") return MoneroWalletDumpFile.Completed( parent = self, - fn = dump_fns[0]).data._asdict()['wallet_metadata'] + fn = dump_fn).data._asdict()['wallet_metadata'] def restore_accounts(): bmsg(' Restoring accounts:') diff --git a/mmgen/xmrwallet/ops/spec.py b/mmgen/xmrwallet/ops/spec.py index ea26aea0..37a4c607 100755 --- a/mmgen/xmrwallet/ops/spec.py +++ b/mmgen/xmrwallet/ops/spec.py @@ -52,13 +52,14 @@ class OpMixinSpec: else: return s # None or empty string - if self.name in ('sweep', 'sweep_all'): - self.dest_acct = None if m[4] is None else int(m[4]) - elif self.name == 'transfer': - self.dest_addr = CoinAddr(self.proto, m[3]) - self.amount = self.proto.coin_amt(m[4]) - elif self.name == 'new': - self.label = strip_quotes(m[3]) - elif self.name == 'label': - self.address_idx = int(m[3]) - self.label = strip_quotes(m[4]) + match self.name: + case 'sweep' | 'sweep_all': + self.dest_acct = None if m[4] is None else int(m[4]) + case 'transfer': + self.dest_addr = CoinAddr(self.proto, m[3]) + self.amount = self.proto.coin_amt(m[4]) + case 'new': + self.label = strip_quotes(m[3]) + case 'label': + self.address_idx = int(m[3]) + self.label = strip_quotes(m[4]) diff --git a/mmgen/xmrwallet/ops/wallet.py b/mmgen/xmrwallet/ops/wallet.py index 407c49f2..6127c2ff 100755 --- a/mmgen/xmrwallet/ops/wallet.py +++ b/mmgen/xmrwallet/ops/wallet.py @@ -52,11 +52,11 @@ class OpWallet(OpBase): def check_wallets(): for d in self.addr_data: fn = self.get_wallet_fn(d) - exists = wallet_exists(fn) - if exists and not self.wallet_exists: - die(1, f'Wallet ‘{fn}’ already exists!') - elif not exists and self.wallet_exists: - die(1, f'Wallet ‘{fn}’ not found!') + match wallet_exists(fn): + case True if not self.wallet_exists: + die(1, f'Wallet ‘{fn}’ already exists!') + case False if self.wallet_exists: + die(1, f'Wallet ‘{fn}’ not found!') super().__init__(cfg, uarg_tuple)