Browse Source

xmrwallet: use match statement where practicable (3 files)

The MMGen Project 2 months ago
parent
commit
b9328d9a45
3 changed files with 23 additions and 21 deletions
  1. 7 6
      mmgen/xmrwallet/ops/restore.py
  2. 11 10
      mmgen/xmrwallet/ops/spec.py
  3. 5 5
      mmgen/xmrwallet/ops/wallet.py

+ 7 - 6
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:')

+ 11 - 10
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])

+ 5 - 5
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)