mmgen-xmrwallet: add 'list' operation (list addresses in wallets)

This commit is contained in:
The MMGen Project 2022-06-09 11:18:10 +00:00
commit b0d1a79468
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
4 changed files with 39 additions and 11 deletions

View file

@ -1 +1 @@
13.2.dev5
13.2.dev6

View file

@ -31,6 +31,7 @@ opts_data = {
'usage2': [
'[opts] create <xmr_keyaddrfile> [wallets]',
'[opts] sync <xmr_keyaddrfile> [wallets]',
'[opts] list <xmr_keyaddrfile> [wallets]',
'[opts] new <xmr_keyaddrfile> NEW_ADDRESS_SPEC',
'[opts] transfer <xmr_keyaddrfile> TRANSFER_SPEC',
'[opts] sweep <xmr_keyaddrfile> 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:

View file

@ -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'

View file

@ -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(