Browse Source

autosign: minor fixes and cleanups

The MMGen Project 1 year ago
parent
commit
f1512484c9

+ 11 - 9
mmgen/autosign.py

@@ -80,22 +80,22 @@ class Signable:
 				b = '  {}\n'.format('\n  '.join(self.gen_bad_list(sorted(bad_files,key=lambda f: f.name))))
 			))
 
-		def die_wrong_num_txs(self, desc, msg=None, show_dir=False):
-			num_txs = len(getattr(self, desc))
+		def die_wrong_num_txs(self, tx_type, msg=None, desc=None, show_dir=False):
+			num_txs = len(getattr(self, tx_type))
 			die('AutosignTXError', "{m}{a} {b} transaction{c} {d} {e}!".format(
 				m = msg + '\n' if msg else '',
 				a = 'One' if num_txs == 1 else 'More than one' if num_txs else 'No',
-				b = desc,
+				b = desc or tx_type,
 				c = suf(num_txs),
 				d = 'already present' if num_txs else 'present',
 				e = f'in ‘{getattr(self.parent, self.dir_name)}’' if show_dir else 'on removable device',
 			))
 
-		def get_unsubmitted(self, desc='unsubmitted'):
+		def get_unsubmitted(self, tx_type='unsubmitted'):
 			if len(self.unsubmitted) == 1:
 				return self.unsubmitted[0]
 			else:
-				self.die_wrong_num_txs(desc)
+				self.die_wrong_num_txs(tx_type)
 
 		def get_submitted(self):
 			if len(self.submitted) == 0:
@@ -474,6 +474,8 @@ class Autosign:
 			for val in ret:
 				if isinstance(val,str):
 					msg(val)
+			if self.cfg.test_suite_autosign_threaded:
+				await asyncio.sleep(1)
 			self.do_umount()
 			self.led.set(('standby','off','error')[(not ret)*2 or bool(self.cfg.stealth_led)])
 			return all(ret)
@@ -641,8 +643,8 @@ class Autosign:
 	async def main_loop(self):
 		if not self.cfg.stealth_led:
 			self.led.set('standby')
-		silent = self.cfg.test_suite_autosign_threaded
-		n = 1 if silent else 0
+		threaded = self.cfg.test_suite_autosign_threaded
+		n = 1 if threaded else 0
 		prev_status = False
 		while True:
 			status = self.get_insert_status()
@@ -652,8 +654,8 @@ class Autosign:
 			prev_status = status
 			if not n % 10:
 				msg_r(f"\r{' '*17}\rWaiting")
-			await asyncio.sleep(1)
-			if not silent:
+			await asyncio.sleep(0.2 if threaded else 1)
+			if not threaded:
 				msg_r('.')
 				n += 1
 

+ 1 - 1
mmgen/data/version

@@ -1 +1 @@
-14.1.dev12
+14.1.dev13

+ 5 - 2
mmgen/main_txbump.py

@@ -134,7 +134,7 @@ async def main():
 	tx = await BumpTX(
 		cfg  = cfg,
 		data = orig_tx.__dict__,
-		send = sign_and_send,
+		check_sent = cfg.autosign or sign_and_send,
 		twctl = await TwCtl(cfg,orig_tx.proto) if orig_tx.proto.tokensym else None )
 
 	from .rpc import rpc_init
@@ -180,6 +180,9 @@ async def main():
 		else:
 			die(2,'Transaction could not be signed')
 	else:
-		tx.file.write(ask_write=not cfg.yes,ask_write_default_yes=False,ask_overwrite=not cfg.yes)
+		tx.file.write(
+			ask_write             = not cfg.yes,
+			ask_write_default_yes = False,
+			ask_overwrite         = not cfg.yes)
 
 async_run(main())

+ 1 - 2
mmgen/proto/btc/tx/unsigned.py

@@ -64,10 +64,9 @@ class Unsigned(Completed,TxBase.Unsigned):
 			ymsg(self.rpc.daemon.sigfail_errmsg(e))
 			return False
 
-		from ....tx import SignedTX
-
 		try:
 			self.update_serialized(ret['hex'])
+			from ....tx import SignedTX
 			new = await SignedTX(cfg=self.cfg,data=self.__dict__)
 			tx_decoded = await self.rpc.call( 'decoderawtransaction', ret['hex'] )
 			new.compare_size_and_estimated_size(tx_decoded)

+ 3 - 2
mmgen/tx/bump.py

@@ -21,7 +21,7 @@ class Bump(Completed,New):
 	ext  = 'rawtx'
 	bump_output_idx = None
 
-	def __init__(self,send,*args,**kwargs):
+	def __init__(self,check_sent,*args,**kwargs):
 
 		super().__init__(*args,**kwargs)
 
@@ -29,10 +29,11 @@ class Bump(Completed,New):
 			die(1,f'Transaction {self.txid} is not replaceable')
 
 		# If sending, require original tx to be sent
-		if send and not self.coin_txid:
+		if check_sent and not self.coin_txid:
 			die(1,'Transaction {self.txid!r} was not broadcast to the network')
 
 		self.coin_txid = ''
+		self.sent_timestamp = None
 
 	def check_sufficient_funds_for_bump(self):
 		if not [o.amt for o in self.outputs if o.amt >= self.min_fee]:

+ 3 - 1
mmgen/tx/completed.py

@@ -31,7 +31,7 @@ class Completed(Base):
 			self.name = type(self).__name__
 		else:
 			from .file import MMGenTxFile
-			MMGenTxFile(self).parse(filename,quiet_open=quiet_open)
+			MMGenTxFile(self).parse(str(filename), quiet_open=quiet_open)
 
 			self.check_serialized_integrity()
 
@@ -42,6 +42,8 @@ class Completed(Base):
 				from ..util import die
 				die(1,'Transaction is {}signed!'.format('not ' if self.signed else ''))
 
+			self.infile = filename
+
 	@property
 	def file(self):
 		from .file import MMGenTxFile

+ 1 - 0
pyproject.toml

@@ -23,6 +23,7 @@ ignore = [
 ]
 ignored-modules = [ # ignored for no-member, otherwise checked
 	"mmgen.proto.secp256k1.secp256k1",
+	"mmgen.autosign", # tx_dir, etc. created dynamically
 	"mmgen.term",
 	"msvcrt",
 	"gmpy2",

+ 2 - 2
test/cmdtest_py_d/common.py

@@ -124,9 +124,9 @@ def get_file_with_ext(tdir,ext,delete=True,no_dot=False,return_list=False,delete
 		if delete or delete_all:
 			if (cfg.exact_output or cfg.verbose) and not cfg.quiet:
 				if delete_all:
-					msg(f'Deleting all *{dot}{ext} files in {tdir!r}')
+					msg(f'Deleting all *{dot}{ext} files in {tdir}')
 				else:
-					msg(f'Multiple *{dot}{ext} files in {tdir!r} - deleting')
+					msg(f'Multiple *{dot}{ext} files in {tdir} - deleting')
 			for f in flist:
 				os.unlink(f)
 		return False

+ 12 - 6
test/cmdtest_py_d/ct_autosign.py

@@ -334,22 +334,22 @@ class CmdTestAutosignThreaded(CmdTestAutosignBase):
 		return 'ok'
 
 	def _wait_signed(self,desc):
-		oqmsg_r(gray(f'→ offline wallet{"s" if desc.endswith("s") else ""} signing {desc}'))
+		oqmsg_r(gray(f'→ offline wallet{"s" if desc.endswith("s") else ""} waiting for {desc}'))
 		assert not self.device_inserted, f'‘{self.asi.dev_label_path}’ is inserted!'
 		assert not self.asi.mountpoint.is_mount(), f'‘{self.asi.mountpoint}’ is mounted!'
 		self.insert_device()
 		while True:
 			oqmsg_r(gray('.'))
 			if self.asi.mountpoint.is_mount():
-				oqmsg_r(gray('..working..'))
+				oqmsg_r(gray(' signing '))
 				break
-			time.sleep(0.5)
+			time.sleep(0.2)
 		while True:
-			oqmsg_r(gray('.'))
+			oqmsg_r(gray('>'))
 			if not self.asi.mountpoint.is_mount():
-				oqmsg(gray('..done'))
+				oqmsg(gray(' done'))
 				break
-			time.sleep(0.5)
+			time.sleep(0.2)
 		imsg('')
 		self.remove_device()
 		return 'ok'
@@ -365,6 +365,12 @@ class CmdTestAutosignThreaded(CmdTestAutosignBase):
 		if self.asi_online.dev_label_path.exists():
 			self.asi_online.dev_label_path.unlink()
 
+	def do_mount_online(self, *args, **kwargs):
+		return self._mount_ops('asi_online', 'do_mount', *args, **kwargs)
+
+	def do_umount_online(self, *args, **kwargs):
+		return self._mount_ops('asi_online', 'do_umount', *args, **kwargs)
+
 class CmdTestAutosign(CmdTestAutosignBase):
 	'autosigning transactions for all supported coins'
 	coins           = ['btc','bch','ltc','eth']

+ 7 - 5
test/cmdtest_py_d/ct_xmr_autosign.py

@@ -83,9 +83,9 @@ class CmdTestXMRAutosign(CmdTestXMRWallet,CmdTestAutosignThreaded):
 		('import_key_images2',       'importing signed key images into Alice’s online wallets'),
 		('sync_chkbal3',             'syncing Alice’s wallets and checking balance'),
 		('txlist',                   'listing Alice’s submitted transactions'),
-		('check_tx_dirs',            'cleaning and checking signable file directories'),
 		('autosign_kill_thread',     'stopping autosign wait loop'),
 		('stop_daemons',             'stopping all wallet and coin daemons'),
+		('check_tx_dirs',            'cleaning and checking signable file directories'),
 		('view',                     'viewing Alice’s wallet in offline mode (wallet #1)'),
 		('listview',                 'list-viewing Alice’s wallet in offline mode (wallet #2)'),
 	)
@@ -382,16 +382,18 @@ class CmdTestXMRAutosign(CmdTestXMRWallet,CmdTestAutosignThreaded):
 
 	def check_tx_dirs(self):
 
-		self.do_mount_online()
+		self.insert_device()
+		self.do_mount()
 		before = '\n'.join(self._gen_listing())
-		self.do_umount_online()
+		self.do_umount()
 
 		t = self.spawn('mmgen-autosign', self.opts + ['clean'])
 		t.read()
 
-		self.do_mount_online()
+		self.do_mount()
 		after = '\n'.join(self._gen_listing())
-		self.do_umount_online()
+		self.do_umount()
+		self.remove_device()
 
 		imsg(f'\nBefore cleaning:\n{before}')
 		imsg(f'\nAfter cleaning:\n{after}')