Browse Source

autosign,xmrwallet: minor fixes and cleanups

The MMGen Project 2 years ago
parent
commit
3988aa8c59

+ 3 - 0
mmgen/autosign.py

@@ -262,6 +262,8 @@ class Autosign:
 		if not os.path.ismount(self.mountpoint):
 		if not os.path.ismount(self.mountpoint):
 			if run( ['mount',self.mountpoint], stderr=DEVNULL, stdout=DEVNULL ).returncode == 0:
 			if run( ['mount',self.mountpoint], stderr=DEVNULL, stdout=DEVNULL ).returncode == 0:
 				msg(f'Mounting {self.mountpoint!r}')
 				msg(f'Mounting {self.mountpoint!r}')
+			elif not self.cfg.test_suite:
+				die(1,f'Unable to mount device at {self.mountpoint!r}')
 
 
 		self.have_msg_dir = os.path.isdir(self.msg_dir)
 		self.have_msg_dir = os.path.isdir(self.msg_dir)
 
 
@@ -275,6 +277,7 @@ class Autosign:
 			run( ['sync'], check=True )
 			run( ['sync'], check=True )
 			msg(f'Unmounting {self.mountpoint!r}')
 			msg(f'Unmounting {self.mountpoint!r}')
 			run( ['umount',self.mountpoint], check=True )
 			run( ['umount',self.mountpoint], check=True )
+		bmsg('It is now safe to extract the removable device')
 
 
 	def decrypt_wallets(self):
 	def decrypt_wallets(self):
 		msg(f'Unlocking wallet{suf(self.wallet_files)} with key from {self.cfg.passwd_file!r}')
 		msg(f'Unlocking wallet{suf(self.wallet_files)} with key from {self.cfg.passwd_file!r}')

+ 12 - 24
mmgen/help/xmrwallet.py

@@ -14,10 +14,16 @@ help.xmrwallet: xmrwallet help notes for MMGen suite
 
 
 def help(proto,cfg):
 def help(proto,cfg):
 
 
-	return f"""
-All operations except for ‘relay’ require a running Monero daemon.  Unless
---daemon is specified, the monerod is assumed to be listening on localhost at
-the default RPC port.
+	return """
+Many operations take an optional ‘wallets’ argument: one or more address
+indexes (expressed as a comma-separated list and/or hyphenated range) in
+the default or specified key-address file, each corresponding to a Monero
+wallet with the same index.  If the argument is omitted, all wallets are
+operated upon.
+
+All operations except for ‘relay’ require a running Monero daemon (monerod).
+Unless --daemon is specified, the daemon is assumed to be listening on
+localhost at the default RPC port.
 
 
 If --tx-relay-daemon is specified, the monerod at HOST:PORT will be used to
 If --tx-relay-daemon is specified, the monerod at HOST:PORT will be used to
 relay any created transactions.  PROXY_HOST:PROXY_PORT, if specified, may
 relay any created transactions.  PROXY_HOST:PROXY_PORT, if specified, may
@@ -44,14 +50,6 @@ txview    - view a transaction file or files created using ‘sweep’ or
             ‘transfer’ with the --no-relay option
             ‘transfer’ with the --no-relay option
 
 
 
 
-                 ‘CREATE’, ‘SYNC’ AND ‘LIST’ OPERATION NOTES
-
-These operations take an optional `wallets` argument: one or more address
-indexes (expressed as a comma-separated list, hyphenated range, or both)
-in the specified key-address file, each corresponding to a Monero wallet
-to be created, synced or listed.  If omitted, all wallets are operated upon.
-
-
                            ‘LABEL’ OPERATION NOTES
                            ‘LABEL’ OPERATION NOTES
 
 
 This operation takes a LABEL_SPEC arg with the following format:
 This operation takes a LABEL_SPEC arg with the following format:
@@ -105,24 +103,14 @@ Note that multiple sweep operations may be required to sweep all the funds
 in an account.
 in an account.
 
 
 
 
-                    ‘SUBMIT’ AND ‘RELAY’ OPERATION NOTES
+                           ‘RELAY’ OPERATION NOTES
 
 
 By default, transactions are relayed to a monerod running on localhost at the
 By default, transactions are relayed to a monerod running on localhost at the
 default RPC port.  To relay transactions to a remote or non-default monerod
 default RPC port.  To relay transactions to a remote or non-default monerod
 via optional SOCKS proxy, use the --tx-relay-daemon option described above.
 via optional SOCKS proxy, use the --tx-relay-daemon option described above.
 
 
-When ‘submit’ is used together with --autosign, the transaction filename may
-be omitted and the software will attempt to locate it automatically.
-
-
-                    ‘DUMP’ AND ‘RESTORE’ OPERATION NOTES
-
-These commands produce and read JSON wallet dump files located in the same
-directories as their corresponding wallets and having the same filenames,
-plus a .dump extension.
-
 
 
-                                   WARNING
+                              SECURITY WARNING
 
 
 To avoid exposing your private keys on a network-connected machine, you’re
 To avoid exposing your private keys on a network-connected machine, you’re
 strongly advised to create all transactions offline using the --no-relay
 strongly advised to create all transactions offline using the --no-relay

+ 4 - 4
mmgen/main_autosign.py

@@ -31,7 +31,7 @@ opts_data = {
 	'sets': [('stealth_led', True, 'led', True)],
 	'sets': [('stealth_led', True, 'led', True)],
 	'text': {
 	'text': {
 		'desc': 'Auto-sign MMGen transactions and message files',
 		'desc': 'Auto-sign MMGen transactions and message files',
-		'usage':'[opts] [command]',
+		'usage':'[opts] [operation]',
 		'options': """
 		'options': """
 -h, --help            Print this help message
 -h, --help            Print this help message
 --, --longhelp        Print help message for long options (common options)
 --, --longhelp        Print help message for long options (common options)
@@ -55,7 +55,7 @@ opts_data = {
 """,
 """,
 	'notes': """
 	'notes': """
 
 
-                               SUBCOMMANDS
+                               OPERATIONS
 
 
 gen_key - generate the wallet encryption key and copy it to the mountpoint
 gen_key - generate the wallet encryption key and copy it to the mountpoint
           {asi.mountpoint!r} (as currently configured)
           {asi.mountpoint!r} (as currently configured)
@@ -65,7 +65,7 @@ wait    - start in loop mode: wait-mount-sign-unmount-wait
 
 
                                USAGE NOTES
                                USAGE NOTES
 
 
-If invoked with no subcommand, this program mounts a removable device
+If no operation is specified, this program mounts a removable device
 (typically a USB flash drive) containing unsigned MMGen transactions and/or
 (typically a USB flash drive) containing unsigned MMGen transactions and/or
 message files, signs them, unmounts the removable device and exits.
 message files, signs them, unmounts the removable device and exits.
 
 
@@ -110,7 +110,7 @@ file path to the end of the command line.  Multiple temporary wallets may
 be created in this way and used for signing (note, however, that for XMR
 be created in this way and used for signing (note, however, that for XMR
 operations only one wallet is supported).
 operations only one wallet is supported).
 
 
-This command is currently available only on Linux-based platforms.
+Autosigning is currently available only on Linux-based platforms.
 
 
 
 
                                SECURITY NOTE
                                SECURITY NOTE

+ 7 - 7
mmgen/main_xmrwallet.py

@@ -17,8 +17,8 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
 """
 """
-mmgen-xmrwallet: Perform various Monero wallet operations for addresses
-                 in an MMGen XMR key-address file
+mmgen-xmrwallet: Perform various Monero wallet and transacting operations for
+                 addresses in an MMGen XMR key-address file
 """
 """
 
 
 from collections import namedtuple
 from collections import namedtuple
@@ -34,8 +34,8 @@ from .xmrwallet import (
 
 
 opts_data = {
 opts_data = {
 	'text': {
 	'text': {
-		'desc': """Perform various Monero wallet operations for addresses
-                   in an MMGen XMR key-address file""",
+		'desc': """Perform various Monero wallet and transacting operations for
+                   addresses in an MMGen XMR key-address file""",
 		'usage2': [
 		'usage2': [
 			'[opts] create | sync | list <xmr_keyaddrfile> [wallets]',
 			'[opts] create | sync | list <xmr_keyaddrfile> [wallets]',
 			'[opts] label    <xmr_keyaddrfile> LABEL_SPEC',
 			'[opts] label    <xmr_keyaddrfile> LABEL_SPEC',
@@ -66,9 +66,9 @@ opts_data = {
 -S, --no-stop-wallet-daemon      Don’t stop the wallet daemon at exit
 -S, --no-stop-wallet-daemon      Don’t stop the wallet daemon at exit
 -w, --wallet-dir=D               Output or operate on wallets in directory 'D'
 -w, --wallet-dir=D               Output or operate on wallets in directory 'D'
                                  instead of the working directory
                                  instead of the working directory
--H, --wallet-rpc-host=host       Wallet RPC hostname (default: {cfg.monero_wallet_rpc_host!r})
--U, --wallet-rpc-user=user       Wallet RPC username (default: {cfg.monero_wallet_rpc_user!r})
--P, --wallet-rpc-password=pass   Wallet RPC password (default: {cfg.monero_wallet_rpc_password!r})
+-H, --wallet-rpc-host=host       Wallet RPC hostname (currently: {cfg.monero_wallet_rpc_host!r})
+-U, --wallet-rpc-user=user       Wallet RPC username (currently: {cfg.monero_wallet_rpc_user!r})
+-P, --wallet-rpc-password=pass   Wallet RPC password (currently: [scrubbed])
 """,
 """,
 	'notes': """
 	'notes': """
 
 

+ 13 - 9
mmgen/xmrwallet.py

@@ -37,7 +37,7 @@ from .util import (
 	suf,
 	suf,
 	async_run,
 	async_run,
 	make_timestr,
 	make_timestr,
-	make_chksum_6,
+	make_chksum_N,
 	capfirst,
 	capfirst,
 )
 )
 from .fileutil import get_data_from_file
 from .fileutil import get_data_from_file
@@ -119,7 +119,7 @@ class MoneroMMGenFile:
 				dict( (k,v) for k,v in self.data._asdict().items() if (not keys or k in keys) ),
 				dict( (k,v) for k,v in self.data._asdict().items() if (not keys or k in keys) ),
 				cls = json_encoder
 				cls = json_encoder
 			)
 			)
-			return make_chksum_6(res)
+			return make_chksum_N( res, rounds=1, nchars=self.chksum_nchars, upper=False )
 
 
 		@property
 		@property
 		def base_chksum(self):
 		def base_chksum(self):
@@ -137,15 +137,18 @@ class MoneroMMGenFile:
 					assert a == b, f'{k} mismatch: {a} != {b}'
 					assert a == b, f'{k} mismatch: {a} != {b}'
 
 
 		def make_wrapped_data(self,in_data):
 		def make_wrapped_data(self,in_data):
+			out = {
+				'base_chksum': self.base_chksum,
+				'full_chksum': self.full_chksum,
+				'data': in_data,
+			} if self.full_chksum else {
+				'base_chksum': self.base_chksum,
+				'data': in_data,
+			}
 			return json.dumps(
 			return json.dumps(
-				{ self.data_label: {
-						'base_chksum': self.base_chksum,
-						'full_chksum': self.full_chksum,
-						'data': in_data,
-					}
-				},
+				{ self.data_label: out },
 				cls = json_encoder,
 				cls = json_encoder,
-				indent = 4,
+				indent = 2,
 			)
 			)
 
 
 		def extract_data_from_file(self,cfg,fn):
 		def extract_data_from_file(self,cfg,fn):
@@ -157,6 +160,7 @@ class MoneroMMGenTX:
 
 
 		data_label = 'MoneroMMGenTX'
 		data_label = 'MoneroMMGenTX'
 		base_chksum_fields = ('op','create_time','network','seed_id','source','dest','amount')
 		base_chksum_fields = ('op','create_time','network','seed_id','source','dest','amount')
+		chksum_nchars = 6
 		xmrwallet_tx_data = namedtuple('xmrwallet_tx_data',[
 		xmrwallet_tx_data = namedtuple('xmrwallet_tx_data',[
 			'op',
 			'op',
 			'create_time',
 			'create_time',

+ 0 - 1
test/test_py_d/ts_xmrwallet.py

@@ -320,7 +320,6 @@ class TestSuiteXMRWallet(TestSuiteBase):
 				stem_glob,
 				stem_glob,
 				stem_glob + '.keys',
 				stem_glob + '.keys',
 				stem_glob + '.address.txt' ):
 				stem_glob + '.address.txt' ):
-#			imsg(f'rm -f {glob}')
 			run( f'rm -f {glob}', shell=True )
 			run( f'rm -f {glob}', shell=True )
 		t = self.spawn(
 		t = self.spawn(
 			'mmgen-xmrwallet',
 			'mmgen-xmrwallet',