mmgen-xmrwallet: minor fixes and changes

This commit is contained in:
The MMGen Project 2021-06-11 13:19:46 +00:00
commit 95e1354f69
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
2 changed files with 42 additions and 41 deletions

View file

@ -147,30 +147,34 @@ class MoneroWalletOps:
blue(self.parent.wd2.proxy or 'None')
))
def display_sweep_tx(self,data):
def display_tx(self,txid,amt,fee):
from .obj import CoinTxID
msg(' TxID: {}\n Amount: {}\n Fee: {}'.format(
CoinTxID(data['tx_hash_list'][0]).hl(),
hl_amt(data['amount_list'][0]),
hl_amt(data['fee_list'][0]),
CoinTxID(txid).hl(),
hl_amt(amt),
hl_amt(fee),
))
async def make_sweep_tx(self,account,addr):
ret = await self.c.call(
res = await self.c.call(
'sweep_all',
address = addr,
account_index = account,
do_not_relay = True,
get_tx_metadata = True
)
self.display_sweep_tx(ret)
return ret
if len(res['tx_hash_list']) > 1:
die(3,'More than one TX required. Cannot perform this sweep')
self.display_tx( res['tx_hash_list'][0], res['amount_list'][0], res['fee_list'][0] )
return res['tx_metadata_list'][0]
def display_txid(self,data):
from .obj import CoinTxID
msg('\n Relayed {}'.format( CoinTxID(data['tx_hash']).hl() ))
async def relay_sweep_tx(self,tx_hex):
async def relay_tx(self,tx_hex):
ret = await self.c.call('relay_tx',hex=tx_hex)
try:
self.display_txid(ret)
@ -406,15 +410,17 @@ class MoneroWalletOps:
desc = 'Sweep'
past = 'swept'
tx_relay = True
spec_id = 'sweep_spec'
spec_key = ( (1,'source'), (3,'dest') )
def create_addr_data(self):
m = re.fullmatch(uarg_info['sweep_spec'].pat,uarg.spec,re.ASCII)
m = re.fullmatch(uarg_info[self.spec_id].pat,uarg.spec,re.ASCII)
if not m:
fs = "{!r}: invalid 'sweep_spec' arg: for sweep operation, it must have format {!r}"
die(1,fs.format( uarg.spec, uarg_info['sweep_spec'].annot ))
fs = "{!r}: invalid {!r} arg: for {} operation, it must have format {!r}"
die(1,fs.format( uarg.spec, self.spec_id, self.name, uarg_info[self.spec_id].annot ))
def gen():
for i,k in ( (1,'source'), (3,'dest') ):
for i,k in self.spec_key:
if m[i] == None:
setattr(self,k,None)
else:
@ -460,9 +466,9 @@ class MoneroWalletOps:
)
async def process_wallets(self):
gmsg(f'\nSweeping account #{self.account} of wallet {self.source.idx}' + (
' to new address' if self.dest is None else
f' to new account in wallet {self.dest.idx}' ))
gmsg(f'\n{self.desc}ing account #{self.account} of wallet {self.source.idx}' + (
' to new address' if self.dest is None
else f' to new account in wallet {self.dest.idx}' ))
h = self.rpc(self,self.source)
@ -506,9 +512,9 @@ class MoneroWalletOps:
self.account,
cyan(new_addr),
))
sweep_tx = await h.make_sweep_tx(self.account,new_addr)
tx_metadata = await h.make_sweep_tx(self.account,new_addr)
if keypress_confirm('Relay sweep transaction?'):
if keypress_confirm(f'\nRelay {self.name} transaction?'):
w_desc = 'source'
if uarg.tx_relay_daemon:
await h.close_wallet('source')
@ -517,8 +523,8 @@ class MoneroWalletOps:
w_desc = 'TX relay source'
await h.open_wallet(w_desc)
h.display_tx_relay_info()
msg_r(f' Relaying sweep transaction...')
await h.relay_sweep_tx( sweep_tx['tx_metadata_list'][0] )
msg_r(f'\n Relaying {self.name} transaction...')
await h.relay_tx(tx_metadata)
await h.close_wallet(w_desc)
gmsg('\n\nAll done')

View file

@ -80,6 +80,11 @@ class TestSuiteXMRWallet(TestSuiteBase):
self.init_proxy()
self.tx_relay_daemon_parm = 'localhost:{}'.format(self.users['bob'].md.rpc_port)
self.tx_relay_daemon_proxy_parm = (
self.tx_relay_daemon_parm + f':127.0.0.1:{self.socks_port}' # proxy must be IP, not 'localhost'
if self.use_proxy else None )
if not opt.no_daemon_autostart:
self.start_daemons()
self.start_wallet_daemons()
@ -309,7 +314,7 @@ class TestSuiteXMRWallet(TestSuiteBase):
1234567891234,
read_from_file(self.users['alice'].addrfile_fs.format(1)),
)
self.set_dest('alice',1,0,lambda x: x > 1,'unlocked balance > 1')
self.set_dest('alice',1,0,lambda x: str(x) == '1.234567891234','unlocked balance == 1.234567891234')
return 'ok'
def sync_wallets_selected(self):
@ -336,48 +341,38 @@ class TestSuiteXMRWallet(TestSuiteBase):
t.read()
return t
def _sweep_user(self,user,spec,tx_relay_daemon=None):
def do_op(self,op,user,spec,tx_relay_parm):
data = self.users[user]
dir_opt = [f'--outdir={data.udir}']
cmd_opts = list_gen(
[f'--daemon=localhost:{data.md.rpc_port}'],
[f'--tx-relay-daemon={tx_relay_daemon}', tx_relay_daemon]
[f'--tx-relay-daemon={tx_relay_parm}', tx_relay_parm]
)
t = self.spawn(
'mmgen-xmrwallet',
self.long_opts + dir_opt + cmd_opts + [ 'sweep', data.kafile, spec ],
self.long_opts + dir_opt + cmd_opts + [ op, data.kafile, spec ],
extra_desc = f'({capfirst(user)})' )
t.expect('Check key-to-address validity? (y/N): ','n')
t.expect(
'Create new {} .* \(y/N\): '.format('account' if ',' in spec else 'address'),
'y', regex=True )
t.expect('Relay sweep transaction? (y/N): ','y')
if op == 'sweep':
t.expect(
'Create new {} .* \(y/N\): '.format('account' if ',' in spec else 'address'),
'y', regex=True )
t.expect(f'Relay {op} transaction? (y/N): ','y')
t.read()
return t
def sweep_to_address_proxy(self):
ret = self._sweep_user(
'alice',
'1:0',
tx_relay_daemon = 'localhost:{}:127.0.0.1:{}'.format( # proxy must be IP, not 'localhost'
self.users['bob'].md.rpc_port,
self.socks_port
) if self.use_proxy else None
)
ret = self.do_op('sweep','alice','1:0',self.tx_relay_daemon_proxy_parm)
self.set_dest('alice',1,0,lambda x: x > 1,'unlocked balance > 1')
return ret
def sweep_to_account(self):
ret = self._sweep_user('alice','1:0,2')
ret = self.do_op('sweep','alice','1:0,2',None)
self.set_dest('alice',2,1,lambda x: x > 1,'unlocked balance > 1')
return ret
def sweep_to_address_noproxy(self):
ret = self._sweep_user(
'alice',
'2:1',
tx_relay_daemon = 'localhost:{}'.format(self.users['bob'].md.rpc_port)
)
ret = self.do_op('sweep','alice','2:1',self.tx_relay_daemon_parm)
self.set_dest('alice',2,1,lambda x: x > 1,'unlocked balance > 1')
return ret