Browse Source

autosign,xmrwallet: cleanups, fixes

The MMGen Project 1 year ago
parent
commit
9a60393ebe
2 changed files with 38 additions and 30 deletions
  1. 34 28
      mmgen/autosign.py
  2. 4 2
      mmgen/xmrwallet.py

+ 34 - 28
mmgen/autosign.py

@@ -31,6 +31,8 @@ class Signable:
 
 
 	class base:
 	class base:
 
 
+		multiple_ok = True
+
 		def __init__(self,parent):
 		def __init__(self,parent):
 			self.parent = parent
 			self.parent = parent
 			self.cfg = parent.cfg
 			self.cfg = parent.cfg
@@ -125,11 +127,7 @@ class Signable:
 		dir_name = 'xmr_tx_dir'
 		dir_name = 'xmr_tx_dir'
 		desc = 'Monero transaction'
 		desc = 'Monero transaction'
 		subext = 'subtx'
 		subext = 'subtx'
-
-		def __init__(self,*args,**kwargs):
-			super().__init__(*args,**kwargs)
-			if len(self.unsigned) > 1:
-				die('AutosignTXError', 'Only one unsigned XMR transaction allowed at a time!')
+		multiple_ok = False
 
 
 		async def sign(self,f):
 		async def sign(self,f):
 			from .xmrwallet import MoneroMMGenTX,MoneroWalletOps,xmrwallet_uargs
 			from .xmrwallet import MoneroMMGenTX,MoneroWalletOps,xmrwallet_uargs
@@ -361,6 +359,8 @@ class Autosign:
 	async def sign_all(self,target_name):
 	async def sign_all(self,target_name):
 		target = getattr(Signable,target_name)(self)
 		target = getattr(Signable,target_name)(self)
 		if target.unsigned:
 		if target.unsigned:
+			if len(target.unsigned) > 1 and not target.multiple_ok:
+				die(f'AutosignTXError', 'Only one unsigned {target.desc} transaction allowed at a time!')
 			good = []
 			good = []
 			bad = []
 			bad = []
 			for f in target.unsigned:
 			for f in target.unsigned:
@@ -430,7 +430,6 @@ class Autosign:
 		msg('Wrote ' + desc)
 		msg('Wrote ' + desc)
 
 
 	def gen_key(self,no_unmount=False):
 	def gen_key(self,no_unmount=False):
-		self.create_wallet_dir()
 		if not self.get_insert_status():
 		if not self.get_insert_status():
 			die(1,'Removable device not present!')
 			die(1,'Removable device not present!')
 		self.do_mount(no_xmr_chk=True)
 		self.do_mount(no_xmr_chk=True)
@@ -439,20 +438,22 @@ class Autosign:
 		if not no_unmount:
 		if not no_unmount:
 			self.do_umount()
 			self.do_umount()
 
 
-	def remove_wallet_dir(self):
-		msg(f'Deleting {self.wallet_dir!r}')
-		import shutil
-		try: shutil.rmtree(self.wallet_dir)
-		except: pass
+	def setup(self):
 
 
-	def create_wallet_dir(self):
-		try: self.wallet_dir.mkdir(parents=True)
-		except: pass
-		try: self.wallet_dir.stat()
-		except: die(2,f"Unable to create wallet directory '{self.wallet_dir}'")
+		def remove_wallet_dir():
+			msg(f"Deleting '{self.wallet_dir}'")
+			import shutil
+			try: shutil.rmtree(self.wallet_dir)
+			except: pass
 
 
-	def setup(self):
-		self.remove_wallet_dir()
+		def create_wallet_dir():
+			try: self.wallet_dir.mkdir(parents=True)
+			except: pass
+			try: self.wallet_dir.stat()
+			except: die(2,f"Unable to create wallet directory '{self.wallet_dir}'")
+
+		remove_wallet_dir()
+		create_wallet_dir()
 		self.gen_key(no_unmount=True)
 		self.gen_key(no_unmount=True)
 		wf = find_file_in_dir( get_wallet_cls('mmgen'), self.cfg.data_dir )
 		wf = find_file_in_dir( get_wallet_cls('mmgen'), self.cfg.data_dir )
 		if wf and keypress_confirm(
 		if wf and keypress_confirm(
@@ -484,6 +485,20 @@ class Autosign:
 
 
 	def xmr_setup(self):
 	def xmr_setup(self):
 
 
+		def create_signing_wallets():
+			from .xmrwallet import MoneroWalletOps,xmrwallet_uargs
+			if len(self.wallet_files) > 1:
+				ymsg(f'Warning: more that one wallet file, using the first ({self.wallet_files[0]}) for xmrwallet generation')
+			m = MoneroWalletOps.create_offline(
+				self.xmrwallet_cfg,
+				xmrwallet_uargs(
+					infile  = str(self.wallet_files[0]), # MMGen wallet file
+					wallets = self.cfg.xmrwallets,  # XMR wallet idxs
+					spec    = None ),
+			)
+			async_run(m.main())
+			async_run(m.stop_wallet_daemon())
+
 		import shutil
 		import shutil
 		try: shutil.rmtree(self.xmr_outputs_dir)
 		try: shutil.rmtree(self.xmr_outputs_dir)
 		except: pass
 		except: pass
@@ -502,16 +517,7 @@ class Autosign:
 		if len(self.wallet_files) > 1:
 		if len(self.wallet_files) > 1:
 			ymsg(f'Warning: more that one wallet file, using the first ({self.wallet_files[0]}) for xmrwallet generation')
 			ymsg(f'Warning: more that one wallet file, using the first ({self.wallet_files[0]}) for xmrwallet generation')
 
 
-		from .xmrwallet import MoneroWalletOps,xmrwallet_uargs
-		m = MoneroWalletOps.create_offline(
-			self.xmrwallet_cfg,
-			xmrwallet_uargs(
-				infile  = self.wallet_files[0], # MMGen wallet file
-				wallets = self.cfg.xmrwallets,  # XMR wallet idxs
-				spec    = None ),
-		)
-		async_run(m.main())
-		async_run(m.stop_wallet_daemon())
+		create_signing_wallets()
 
 
 	def get_insert_status(self):
 	def get_insert_status(self):
 		if self.cfg.no_insert_check:
 		if self.cfg.no_insert_check:

+ 4 - 2
mmgen/xmrwallet.py

@@ -1115,10 +1115,12 @@ class MoneroWalletOps:
 				skip_chksum_msg = True )
 				skip_chksum_msg = True )
 			vkf = vkal.file
 			vkf = vkal.file
 
 
-			# before writing viewkey-address file, delete any old ones in the directory:
+			# before writing viewkey-address file, shred any old ones in the directory:
 			for f in Path(self.cfg.outdir or '.').iterdir():
 			for f in Path(self.cfg.outdir or '.').iterdir():
 				if f.name.endswith(vkf.ext):
 				if f.name.endswith(vkf.ext):
-					f.unlink()
+					from .fileutil import shred_file
+					msg(f"\nShredding old viewkey-address file '{f}'")
+					shred_file( f, verbose=self.cfg.verbose )
 
 
 			vkf.write() # write file to self.cfg.outdir
 			vkf.write() # write file to self.cfg.outdir