mmgen-xmrwallet label: prompt user to add timestamp

This commit is contained in:
The MMGen Project 2025-11-22 09:04:09 +00:00
commit 937f0af9c9
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
2 changed files with 13 additions and 3 deletions

View file

@ -15,6 +15,7 @@ xmrwallet.ops.label: Monero wallet ops for the MMGen Suite
from ...color import pink, cyan, gray
from ...util import msg, ymsg, gmsg, die, make_timestr
from ...ui import keypress_confirm
from ...obj import TwComment
from ...addr import CoinAddr
from ..rpc import MoneroWalletRPC
@ -28,7 +29,7 @@ class OpLabel(OpMixinSpec, OpWallet):
opts = ()
wallet_offline = True
async def main(self):
async def main(self, add_timestr='ask'):
gmsg('\n{a} label for wallet {b}, account #{c}, address #{d}'.format(
a = 'Setting' if self.label else 'Removing',
@ -53,7 +54,11 @@ class OpLabel(OpMixinSpec, OpWallet):
len(ret) - 1))
addr = ret[self.address_idx]
new_label = f'{self.label} [{make_timestr()}]' if self.label else ''
if self.label and add_timestr == 'ask':
add_timestr = keypress_confirm(self.cfg, '\n Add timestamp to label?')
new_label = TwComment(
(self.label + (f' [{make_timestr()}]' if add_timestr else '')) if self.label
else '')
ca = CoinAddr(self.proto, addr['address'])
from . import addr_width

View file

@ -379,12 +379,14 @@ class CmdTestXMRWallet(CmdTestBase):
return self.set_label_user(
'miner',
'1:0:0,"Miner’s new primary account label [1:0:0]"',
'y',
'updated')
def remove_label_alice(self):
return self.set_label_user(
'alice',
'4:2:2,""',
None,
'removed',
add_opts = ['--full-address'])
@ -392,9 +394,10 @@ class CmdTestXMRWallet(CmdTestBase):
return self.set_label_user(
'alice',
'4:2:2,"Alice’s new subaddress label [4:2:2]"',
'n',
'set')
def set_label_user(self, user, label_spec, expect, add_opts=[]):
def set_label_user(self, user, label_spec, add_timestr_resp, expect, add_opts=[]):
data = self.users[user]
cmd_opts = [f'--wallet-dir={data.udir}', f'--daemon=localhost:{data.md.rpc_port}']
t = self.spawn(
@ -403,6 +406,8 @@ class CmdTestXMRWallet(CmdTestBase):
+ add_opts
+ cmd_opts
+ ['label', data.kafile, label_spec])
if add_timestr_resp:
t.expect('(y/N): ', add_timestr_resp)
t.expect('(y/N): ', 'y')
t.expect(f'Label successfully {expect}')
return t