From b0d1a794685e80d55f5f94451f2cdf8b3708fff8 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Thu, 9 Jun 2022 11:18:10 +0000 Subject: [PATCH] mmgen-xmrwallet: add 'list' operation (list addresses in wallets) --- mmgen/data/version | 2 +- mmgen/main_xmrwallet.py | 8 +++++--- mmgen/xmrwallet.py | 30 ++++++++++++++++++++++++++---- test/test_py_d/ts_xmrwallet.py | 8 ++++++-- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/mmgen/data/version b/mmgen/data/version index 5b10a639..49a804d9 100644 --- a/mmgen/data/version +++ b/mmgen/data/version @@ -1 +1 @@ -13.2.dev5 +13.2.dev6 diff --git a/mmgen/main_xmrwallet.py b/mmgen/main_xmrwallet.py index e236aa5d..4d7deb9b 100755 --- a/mmgen/main_xmrwallet.py +++ b/mmgen/main_xmrwallet.py @@ -31,6 +31,7 @@ opts_data = { 'usage2': [ '[opts] create [wallets]', '[opts] sync [wallets]', + '[opts] list [wallets]', '[opts] new NEW_ADDRESS_SPEC', '[opts] transfer TRANSFER_SPEC', '[opts] sweep SWEEP_SPEC', @@ -76,6 +77,7 @@ plain HTTP is not supported. create - create wallet for all or specified addresses in key-address file sync - sync wallet for all or specified addresses in key-address file +list - same as 'sync', but also list detailed address info for accounts new - create a new account in a wallet, or a new address in an account transfer - transfer specified XMR amount to specified address from specified wallet:account @@ -85,12 +87,12 @@ relay - relay a transaction from a transaction file created using 'sweep' or 'transfer' with the --do-not-relay option - 'CREATE' AND 'SYNC' OPERATION NOTES + '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 or synced. If omitted, all wallets are operated upon. +to be created, synced or listed. If omitted, all wallets are operated upon. 'NEW' OPERATION NOTES @@ -214,7 +216,7 @@ wallets = spec = '' if op == 'relay': if len(cmd_args) != 0: opts.usage() -elif op in ('create','sync'): +elif op in ('create','sync','list'): if len(cmd_args) not in (0,1): opts.usage() if cmd_args: diff --git a/mmgen/xmrwallet.py b/mmgen/xmrwallet.py index d1900bc2..58dccf89 100755 --- a/mmgen/xmrwallet.py +++ b/mmgen/xmrwallet.py @@ -222,7 +222,7 @@ class MoneroMMGenTX: class MoneroWalletOps: - ops = ('create','sync','new','transfer','sweep','relay') + ops = ('create','sync','list','new','transfer','sweep','relay') opts = ( 'wallet_dir', 'daemon', @@ -684,10 +684,29 @@ class MoneroWalletOps: def post_main(self): d = self.accts_data + op = type(self).__name__ - for n,k in enumerate(d): - ad = self.addr_data[n] - self.rpc(self,ad).print_accts( d[k]['accts'], d[k]['addrs'], indent='') + for wnum,k in enumerate(d): + if op == 'sync': + self.rpc(self,self.addr_data[wnum]).print_accts( d[k]['accts'], d[k]['addrs'], indent='') + elif op == 'list': + fs = ' {:2} {} {} {}' + msg('\n' + green(f'Wallet {k}:')) + for acct_num,acct in enumerate(d[k]['addrs']): + msg('\n Account #{} [{} {}]'.format( + acct_num, + self.proto.coin_amt( + d[k]['accts']['subaddress_accounts'][acct_num]['unlocked_balance'], + from_unit='atomic').hl(), + self.proto.coin_amt.hlc('XMR') + )) + msg(fs.format('','Address'.ljust(95),'Used ','Label')) + for addr in acct['addresses']: + msg(fs.format( + addr['address_index'], + CoinAddr(self.proto,addr['address']).hl(), + ( yellow('True ') if addr['used'] else green('False') ), + pink(addr['label']) )) col1_w = max(map(len,d)) + 1 fs = '{:%s} {} {}' % col1_w @@ -704,6 +723,9 @@ class MoneroWalletOps: msg(fs.format( '-'*col1_w, '-'*18, '-'*18 )) msg(fs.format( 'TOTAL:', fmt_amt(tbals[0]), fmt_amt(tbals[1]) )) + class list(sync): + pass + class sweep(wallet): name = 'sweep' desc = 'Sweep' diff --git a/test/test_py_d/ts_xmrwallet.py b/test/test_py_d/ts_xmrwallet.py index f490f9a8..94c618c9 100755 --- a/test/test_py_d/ts_xmrwallet.py +++ b/test/test_py_d/ts_xmrwallet.py @@ -71,6 +71,7 @@ class TestSuiteXMRWallet(TestSuiteBase): ('transfer_to_miner_send2', 'transferring funds to Miner (send TX, no proxy)'), ('sweep_create_and_send', 'sweeping to new account (create TX + send TX, in stages)'), + ('list_wallets_all', 'listing wallets'), ) def __init__(self,trunner,cfgs,spawn): @@ -372,7 +373,10 @@ class TestSuiteXMRWallet(TestSuiteBase): def sync_wallets_selected(self): return self.sync_wallets('alice',wallets='1-2,4') - def sync_wallets(self,user,wallets=None,add_opts=None): + def list_wallets_all(self): + return self.sync_wallets('alice',op='list') + + def sync_wallets(self,user,op='sync',wallets=None,add_opts=None): data = self.users[user] cmd_opts = list_gen( [f'--wallet-dir={data.udir}'], @@ -380,7 +384,7 @@ class TestSuiteXMRWallet(TestSuiteBase): ) t = self.spawn( 'mmgen-xmrwallet', - self.extra_opts + cmd_opts + (add_opts or []) + [ 'sync', data.kafile ] + ([wallets] if wallets else []) ) + self.extra_opts + cmd_opts + (add_opts or []) + [ op, data.kafile ] + ([wallets] if wallets else []) ) wlist = AddrIdxList(wallets) if wallets else MMGenRange(data.kal_range).items for n,wnum in enumerate(wlist): t.expect('Syncing wallet {}/{} ({})'.format(