From c7266f171f8beca46bdcfe99df0880732bdd4744 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 10 Feb 2024 15:10:44 +0000 Subject: [PATCH] mmgen-xmrwallet new: improve UI + cleanups --- mmgen/xmrwallet.py | 46 ++++++++++++++++++---------- test/cmdtest_py_d/ct_xmr_autosign.py | 6 ++-- test/cmdtest_py_d/ct_xmrwallet.py | 11 +++---- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/mmgen/xmrwallet.py b/mmgen/xmrwallet.py index d9cab827..5aa54fd4 100755 --- a/mmgen/xmrwallet.py +++ b/mmgen/xmrwallet.py @@ -997,12 +997,7 @@ class MoneroWalletOps: def create_acct(self,label=None): msg('\n Creating new account...') - ret = self.c.call( - 'create_account', - label = label or 'Sweep from {}:{} [{}]'.format( - self.parent.source.idx, - self.parent.account, - make_timestr() )) + ret = self.c.call('create_account', label=label) msg(' Index: {}'.format( pink(str(ret['account_index'])) )) msg(' Address: {}'.format( cyan(ret['address']) )) return (ret['account_index'], ret['address']) @@ -1508,7 +1503,8 @@ class MoneroWalletOps: accts_data = h2.get_accts()[0] if keypress_confirm( self.cfg, f'\nCreate new account for wallet {wf.name!r}?' ): - dest_acct,dest_addr = h2.create_acct() + dest_acct,dest_addr = h2.create_acct( + label = f'Sweep from {self.source.idx}:{self.account} [{make_timestr()}]') dest_addr_idx = 0 h2.get_accts() elif keypress_confirm( self.cfg, f'Sweep to last existing account of wallet {wf.name!r}?' ): @@ -1565,20 +1561,36 @@ class MoneroWalletOps: async def main(self): h = self.rpc(self,self.source) h.open_wallet('Monero') - label = '{a} [{b}]'.format( - a = self.label or f"xmrwallet new {'account' if self.account is None else 'address'}", - b = make_timestr() ) - if self.account is None: - h.create_acct(label=label) - else: - msg_r(f'\n Account index: {pink(str(self.account))}') - h.create_new_addr(self.account,label=label) + + desc = 'account' if self.account is None else 'address' + label = ( + None if self.label == '' else + '{} [{}]'.format(self.label or f'xmrwallet new {desc}', make_timestr())) accts_data = h.get_accts()[0] - - if self.account is not None: + if desc == 'address': h.print_addrs(accts_data,self.account) + if keypress_confirm( + self.cfg, + '\nCreating new {a} for wallet {b}{c} with {d}\nOK?'.format( + a = desc, + b = red(str(self.source.idx)), + c = '' if desc == 'account' else f', account {red("#"+str(self.account))}', + d = 'label ' + pink('‘'+label+'’') if label else 'empty label') + ): + + if desc == 'address': + h.create_new_addr(self.account,label=label) + else: + h.create_acct(label=label) + + accts_data = h.get_accts()[0] + if desc == 'address': + h.print_addrs(accts_data,self.account) + else: + ymsg('\nOperation cancelled by user request') + # wallet must be left open: otherwise the 'stop_wallet' RPC call used to stop the daemon will fail if self.cfg.no_stop_wallet_daemon: h.close_wallet('Monero') diff --git a/test/cmdtest_py_d/ct_xmr_autosign.py b/test/cmdtest_py_d/ct_xmr_autosign.py index 427a10b2..38001d4e 100755 --- a/test/cmdtest_py_d/ct_xmr_autosign.py +++ b/test/cmdtest_py_d/ct_xmr_autosign.py @@ -162,19 +162,19 @@ class CmdTestXMRAutosign(CmdTestXMRWallet,CmdTestAutosignBase): return self._new_addr_alice( '2', 'start', - fr'Creating new account.*Index:\s+{self.na_idx}\s') + r'Creating new account for wallet .*2.* with label .*‘xmrwallet new account .*y/N\): ') def new_address_alice(self): return self._new_addr_alice( '2:1', 'continue', - r'Account index:\s+1\s+Creating new address' ) + r'Creating new address for wallet .*2.*, account .*#1.* with label .*‘xmrwallet new address .*y/N\): ') def new_address_alice_label(self): return self._new_addr_alice( '2:1,Alice’s new address', 'stop', - r'Account index:\s+1\s+Creating new address.*Alice’s new address' ) + r'Creating new address for wallet .*2.*, account .*#1.* with label .*‘Alice’s new address .*y/N\): ') def dump_tmp_wallets(self): return self._dump_wallets(autosign=False) diff --git a/test/cmdtest_py_d/ct_xmrwallet.py b/test/cmdtest_py_d/ct_xmrwallet.py index d302050a..7d4cce7b 100755 --- a/test/cmdtest_py_d/ct_xmrwallet.py +++ b/test/cmdtest_py_d/ct_xmrwallet.py @@ -400,8 +400,7 @@ class CmdTestXMRWallet(CmdTestBase): (['--no-start-wallet-daemon'] if cfg in ('continue','stop') else []) + (['--no-stop-wallet-daemon'] if cfg in ('start','continue') else []) + ['new', (kafile or data.kafile), spec] ) - m = re.search( expect, t.read(strip_color=True), re.DOTALL ) - assert m, f'no match found for {expect!r}' + t.expect(expect, 'y', regex=True) return t na_idx = 1 @@ -410,25 +409,25 @@ class CmdTestXMRWallet(CmdTestBase): return self.new_addr_alice( '4', 'start', - fr'Creating new account.*Index:\s+{self.na_idx}\s') + r'Creating new account for wallet .*4.* with label .*‘xmrwallet new account .*y/N\): ') def new_account_alice_label(self): return self.new_addr_alice( '4,Alice’s new account', 'continue', - fr'Creating new account.*Index:\s+{self.na_idx+1}\s.*Alice’s new account') + r'Creating new account for wallet .*4.* with label .*‘Alice’s new account .*y/N\): ') def new_address_alice(self): return self.new_addr_alice( '4:2', 'continue', - r'Account index:\s+2\s+Creating new address' ) + r'Creating new address for wallet .*4.*, account .*#2.* with label .*‘xmrwallet new address .*y/N\): ') def new_address_alice_label(self): return self.new_addr_alice( '4:2,Alice’s new address', 'stop', - r'Account index:\s+2\s+Creating new address.*Alice’s new address' ) + r'Creating new address for wallet .*4.*, account .*#2.* with label .*‘Alice’s new address .*y/N\): ') async def mine_initial_coins(self): self.spawn('', msg_only=True, extra_desc='(opening wallet)')