Browse Source

autosign: pass `passwd_file` and `outdir` to methods directly

The MMGen Project 1 year ago
parent
commit
02959677bc
3 changed files with 20 additions and 24 deletions
  1. 13 18
      mmgen/autosign.py
  2. 2 2
      mmgen/msg.py
  3. 5 4
      mmgen/tx/sign.py

+ 13 - 18
mmgen/autosign.py

@@ -112,9 +112,15 @@ class Signable:
 				from .rpc import rpc_init
 				tx1.rpc = await rpc_init( self.cfg, tx1.proto, ignore_wallet=True )
 			from .tx.sign import txsign
-			tx2 = await txsign( self.cfg, tx1, self.parent.wallet_files[:], None, None )
+			tx2 = await txsign(
+					cfg_parm    = self.cfg,
+					tx          = tx1,
+					seed_files  = self.parent.wallet_files[:],
+					kl          = None,
+					kal         = None,
+					passwd_file = str(self.parent.keyfile))
 			if tx2:
-				tx2.file.write(ask_write=False)
+				tx2.file.write(ask_write=False, outdir=self.dir)
 				return tx2
 			else:
 				return False
@@ -221,7 +227,7 @@ class Signable:
 		async def sign(self,f):
 			from .msg import UnsignedMsg,SignedMsg
 			m = UnsignedMsg( self.cfg, infile=f )
-			await m.sign( wallet_files=self.parent.wallet_files[:] )
+			await m.sign(wallet_files=self.parent.wallet_files[:], passwd_file=str(self.parent.keyfile))
 			m = SignedMsg( self.cfg, data=m.__dict__ )
 			m.write_to_file(
 				outdir = self.dir.resolve(),
@@ -405,11 +411,11 @@ class Autosign:
 			bmsg('It is now safe to extract the removable device')
 
 	def decrypt_wallets(self):
-		msg(f"Unlocking wallet{suf(self.wallet_files)} with key from '{self.cfg.passwd_file}'")
+		msg(f"Unlocking wallet{suf(self.wallet_files)} with key from ‘{self.keyfile}’")
 		fails = 0
 		for wf in self.wallet_files:
 			try:
-				Wallet( self.cfg, wf, ignore_in_fmt=True )
+				Wallet(self.cfg, wf, ignore_in_fmt=True, passwd_file=str(self.keyfile))
 			except SystemExit as e:
 				if e.code != 0:
 					fails += 1
@@ -449,20 +455,10 @@ class Autosign:
 			await asyncio.sleep(0.5)
 			return True
 
-	def update_cfg(self):
-		if not hasattr(self,'_cfg_updated'):
-			self.cfg = Config({
-				'_clone': self.cfg,
-				'outdir': str(self.tx_dir),
-				'passwd_file': str(self.keyfile),
-			})
-			self._cfg_updated = True
-
 	async def do_sign(self):
 		if not self.cfg.stealth_led:
 			self.led.set('busy')
 		self.do_mount()
-		self.update_cfg()
 		key_ok = self.decrypt_wallets()
 		if key_ok:
 			if self.cfg.stealth_led:
@@ -491,7 +487,7 @@ class Autosign:
 		else:
 			from .fileutil import shred_file
 			msg(f"\nShredding existing key '{self.keyfile}'")
-			shred_file( self.keyfile, verbose=self.cfg.verbose )
+			shred_file(str(self.keyfile), verbose=self.cfg.verbose)
 
 	def create_key(self):
 		desc = f"key file '{self.keyfile}'"
@@ -560,6 +556,7 @@ class Autosign:
 				'autosign_mountpoint': str(self.mountpoint),
 				'outdir': str(self.xmr_dir), # required by vkal.write()
 				'offline': True,
+				'passwd_file': str(self.keyfile),
 			})
 		return self._xmrwallet_cfg
 
@@ -585,8 +582,6 @@ class Autosign:
 		except:
 			pass
 
-		self.update_cfg()
-
 		self.xmr_outputs_dir.mkdir(parents=True)
 
 		self.xmr_tx_dir.mkdir(exist_ok=True)

+ 2 - 2
mmgen/msg.py

@@ -210,7 +210,7 @@ class coin_msg:
 
 	class unsigned(completed):
 
-		async def sign(self,wallet_files):
+		async def sign(self, wallet_files, passwd_file=None):
 
 			from .addrlist import KeyAddrList
 
@@ -248,7 +248,7 @@ class coin_msg:
 				self.rpc = await rpc_init( self.cfg, self.proto, ignore_wallet=True )
 
 			from .wallet import Wallet
-			wallet_seeds = [Wallet(cfg=self.cfg,fn=fn).seed for fn in wallet_files]
+			wallet_seeds = [Wallet(cfg=self.cfg, fn=fn, passwd_file=passwd_file).seed for fn in wallet_files]
 			need_sids = remove_dups([al.sid for al in self.addrlists], quiet=True)
 			saved_seeds = []
 

+ 5 - 4
mmgen/tx/sign.py

@@ -37,7 +37,7 @@ def get_seed_for_seed_id(sid,infiles,saved_seeds):
 	subseeds_checked = False
 	while True:
 		if infiles:
-			seed = Wallet(cfg,infiles.pop(0),ignore_in_fmt=True).seed
+			seed = Wallet(cfg, infiles.pop(0), ignore_in_fmt=True, passwd_file=global_passwd_file).seed
 		elif subseeds_checked is False:
 			seed = saved_seeds[list(saved_seeds)[0]].subseed_by_seed_id(sid,print_msg=True)
 			subseeds_checked = True
@@ -45,7 +45,7 @@ def get_seed_for_seed_id(sid,infiles,saved_seeds):
 				continue
 		elif cfg.in_fmt:
 			cfg._util.qmsg(f'Need seed data for Seed ID {sid}')
-			seed = Wallet(cfg).seed
+			seed = Wallet(cfg, passwd_file=global_passwd_file).seed
 			msg(f'User input produced Seed ID {seed.sid}')
 			if not seed.sid == sid: # TODO: add test
 				seed = seed.subseed_by_seed_id(sid,print_msg=True)
@@ -141,13 +141,14 @@ def get_keylist(cfg):
 		return get_lines_from_file( cfg, cfg.keys_from_file, 'key-address data', trim_comments=True )
 	return None
 
-async def txsign(cfg_parm,tx,seed_files,kl,kal,tx_num_str=''):
+async def txsign(cfg_parm, tx, seed_files, kl, kal, tx_num_str='', passwd_file=None):
 
 	keys = MMGenList() # list of AddrListEntry objects
 	non_mmaddrs = tx.get_non_mmaddrs('inputs')
 
-	global cfg
+	global cfg, global_passwd_file
 	cfg = cfg_parm
+	global_passwd_file = passwd_file
 
 	if non_mmaddrs:
 		tx.check_non_mmgen_inputs(caller='txsign',non_mmaddrs=non_mmaddrs)