xmrwallet: use match statement where practicable (3 files)

This commit is contained in:
The MMGen Project 2025-09-23 09:20:54 +00:00
commit b9328d9a45
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
3 changed files with 23 additions and 21 deletions

View file

@ -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:')

View file

@ -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])

View file

@ -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)