Browse Source

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

The MMGen Project 2 years ago
parent
commit
b0d1a794
4 changed files with 39 additions and 11 deletions
  1. 1 1
      mmgen/data/version
  2. 5 3
      mmgen/main_xmrwallet.py
  3. 27 5
      mmgen/xmrwallet.py
  4. 6 2
      test/test_py_d/ts_xmrwallet.py

+ 1 - 1
mmgen/data/version

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

+ 5 - 3
mmgen/main_xmrwallet.py

@@ -31,6 +31,7 @@ opts_data = {
 		'usage2': [
 		'usage2': [
 			'[opts] create   <xmr_keyaddrfile> [wallets]',
 			'[opts] create   <xmr_keyaddrfile> [wallets]',
 			'[opts] sync     <xmr_keyaddrfile> [wallets]',
 			'[opts] sync     <xmr_keyaddrfile> [wallets]',
+			'[opts] list     <xmr_keyaddrfile> [wallets]',
 			'[opts] new      <xmr_keyaddrfile> NEW_ADDRESS_SPEC',
 			'[opts] new      <xmr_keyaddrfile> NEW_ADDRESS_SPEC',
 			'[opts] transfer <xmr_keyaddrfile> TRANSFER_SPEC',
 			'[opts] transfer <xmr_keyaddrfile> TRANSFER_SPEC',
 			'[opts] sweep    <xmr_keyaddrfile> SWEEP_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
 create    - create wallet for all or specified addresses in key-address file
 sync      - sync 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
 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
 transfer  - transfer specified XMR amount to specified address from specified
             wallet:account
             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
             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
 These operations take an optional `wallets` argument: one or more address
 indexes (expressed as a comma-separated list, hyphenated range, or both)
 indexes (expressed as a comma-separated list, hyphenated range, or both)
 in the specified key-address file, each corresponding to a Monero wallet
 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
                            'NEW' OPERATION NOTES
@@ -214,7 +216,7 @@ wallets = spec = ''
 if op == 'relay':
 if op == 'relay':
 	if len(cmd_args) != 0:
 	if len(cmd_args) != 0:
 		opts.usage()
 		opts.usage()
-elif op in ('create','sync'):
+elif op in ('create','sync','list'):
 	if len(cmd_args) not in (0,1):
 	if len(cmd_args) not in (0,1):
 		opts.usage()
 		opts.usage()
 	if cmd_args:
 	if cmd_args:

+ 27 - 5
mmgen/xmrwallet.py

@@ -222,7 +222,7 @@ class MoneroMMGenTX:
 
 
 class MoneroWalletOps:
 class MoneroWalletOps:
 
 
-	ops = ('create','sync','new','transfer','sweep','relay')
+	ops = ('create','sync','list','new','transfer','sweep','relay')
 	opts = (
 	opts = (
 		'wallet_dir',
 		'wallet_dir',
 		'daemon',
 		'daemon',
@@ -684,10 +684,29 @@ class MoneroWalletOps:
 
 
 		def post_main(self):
 		def post_main(self):
 			d = self.accts_data
 			d = self.accts_data
-
-			for n,k in enumerate(d):
-				ad = self.addr_data[n]
-				self.rpc(self,ad).print_accts( d[k]['accts'], d[k]['addrs'], indent='')
+			op = type(self).__name__
+
+			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
 			col1_w = max(map(len,d)) + 1
 			fs = '{:%s} {} {}' % col1_w
 			fs = '{:%s} {} {}' % col1_w
@@ -704,6 +723,9 @@ class MoneroWalletOps:
 			msg(fs.format( '-'*col1_w, '-'*18, '-'*18 ))
 			msg(fs.format( '-'*col1_w, '-'*18, '-'*18 ))
 			msg(fs.format( 'TOTAL:', fmt_amt(tbals[0]), fmt_amt(tbals[1]) ))
 			msg(fs.format( 'TOTAL:', fmt_amt(tbals[0]), fmt_amt(tbals[1]) ))
 
 
+	class list(sync):
+		pass
+
 	class sweep(wallet):
 	class sweep(wallet):
 		name     = 'sweep'
 		name     = 'sweep'
 		desc     = 'Sweep'
 		desc     = 'Sweep'

+ 6 - 2
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)'),
 		('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)'),
 		('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):
 	def __init__(self,trunner,cfgs,spawn):
@@ -372,7 +373,10 @@ class TestSuiteXMRWallet(TestSuiteBase):
 	def sync_wallets_selected(self):
 	def sync_wallets_selected(self):
 		return self.sync_wallets('alice',wallets='1-2,4')
 		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]
 		data = self.users[user]
 		cmd_opts = list_gen(
 		cmd_opts = list_gen(
 			[f'--wallet-dir={data.udir}'],
 			[f'--wallet-dir={data.udir}'],
@@ -380,7 +384,7 @@ class TestSuiteXMRWallet(TestSuiteBase):
 		)
 		)
 		t = self.spawn(
 		t = self.spawn(
 			'mmgen-xmrwallet',
 			'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
 		wlist = AddrIdxList(wallets) if wallets else MMGenRange(data.kal_range).items
 		for n,wnum in enumerate(wlist):
 		for n,wnum in enumerate(wlist):
 			t.expect('Syncing wallet {}/{} ({})'.format(
 			t.expect('Syncing wallet {}/{} ({})'.format(