From 41d705ec6e38cd0291aeb0c89369785a4dd2203a Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 1 Feb 2026 09:11:08 +0000 Subject: [PATCH] xmrwallet create_offline: use existing key-address file if present --- mmgen/xmrwallet/ops/create.py | 12 +++++++++--- test/cmdtest_d/autosign.py | 6 ++++++ test/cmdtest_d/xmr_autosign.py | 13 +++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/mmgen/xmrwallet/ops/create.py b/mmgen/xmrwallet/ops/create.py index 5aa4a4d2..25f6031a 100755 --- a/mmgen/xmrwallet/ops/create.py +++ b/mmgen/xmrwallet/ops/create.py @@ -77,10 +77,16 @@ class OpCreateOffline(OpCreate): vkf = vkal.file # before writing viewkey-address file, shred any old ones in the directory: + do_write = True for f in Path(self.asi.xmr_dir).iterdir(): - if f.name.endswith(vkf.ext): + if f.name == vkf.filename: + do_write = False + elif f.name.endswith(vkf.ext): from ...fileutil import shred_file - msg(f'\nShredding old viewkey-address file ‘{f}’') + msg(f'Shredding old viewkey-address file ‘{f}’') shred_file(self.cfg, f, iterations=15) - vkf.write(outdir=self.asi.xmr_dir) + if do_write: + vkf.write(outdir=self.asi.xmr_dir) + else: + msg(f'Viewkey-address file ‘{vkf.filename}’ already exists, skipping creation') diff --git a/test/cmdtest_d/autosign.py b/test/cmdtest_d/autosign.py index 9cbb43ea..34ee93b5 100755 --- a/test/cmdtest_d/autosign.py +++ b/test/cmdtest_d/autosign.py @@ -189,6 +189,12 @@ class CmdTestAutosignBase(CmdTestBase): stop_test_daemons(*(self.network_ids + self.extra_daemons), remove_datadir=True) return 'ok' + def delete_setup(self): + self.spawn(msg_only=True) + imsg(f'Deleting ‘{self.asi.wallet_dir}’') + shutil.rmtree(self.asi.wallet_dir, ignore_errors=True) + return 'ok' + def run_setup( self, mn_type = None, diff --git a/test/cmdtest_d/xmr_autosign.py b/test/cmdtest_d/xmr_autosign.py index d51d6af6..1a772770 100755 --- a/test/cmdtest_d/xmr_autosign.py +++ b/test/cmdtest_d/xmr_autosign.py @@ -256,7 +256,10 @@ class CmdTestXMRAutosign(CmdTestXMRWallet, CmdTestAutosignThreaded): use_dfl_wallet = None, expect_args = ['Continue with Monero setup? (Y/n): ', 'n']) - def autosign_xmr_setup(self): + def autosign_xmr_setup_redo(self): + return self.autosign_xmr_setup(write_viewkeys=False) + + def autosign_xmr_setup(self, write_viewkeys=True): self.insert_device_online() self.do_mount_online() self.asi_online.xmr_dir.mkdir(exist_ok=True) @@ -266,7 +269,10 @@ class CmdTestXMRAutosign(CmdTestXMRWallet, CmdTestAutosignThreaded): self.insert_device() t = self.spawn('mmgen-autosign', self.opts + ['xmr_setup'], no_passthru_opts=True) - t.written_to_file('View keys') + if write_viewkeys: + t.written_to_file('View keys') + else: + t.expect('already exists, skipping') t.read() self.remove_device() return t @@ -514,6 +520,9 @@ class CmdTestXMRCompat(CmdTestXMRAutosign): cmd_group = ( ('autosign_setup', 'autosign setup with Alice’s seed'), ('autosign_xmr_setup', 'autosign setup (creation of Monero signing wallets)'), + ('delete_setup', 'deleting offline autosign setup'), + ('autosign_setup', 'autosign setup with Alice’s seed'), + ('autosign_xmr_setup_redo', 'autosign setup (creation of Monero signing wallets, redo)'), ('create_watchonly_wallets', 'creating Alice’s watch-only wallets'), ('gen_kafile_miner', 'generating key-address file for Miner'), ('create_wallet_miner', 'creating Monero wallet for Miner'),