From 67e88021024425fca01c73ed187d8c9f16e2a2af Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 3 Mar 2024 09:59:00 +0000 Subject: [PATCH] autosign.Signable: new `shred_abortable()` method --- mmgen/autosign.py | 15 +++++++++++++++ mmgen/main_txsend.py | 17 ++--------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/mmgen/autosign.py b/mmgen/autosign.py index 43271ca4..0cc4f29e 100755 --- a/mmgen/autosign.py +++ b/mmgen/autosign.py @@ -128,6 +128,21 @@ class Signable: die(1, f'{self.unsent[0]}, {self.unsent_raw[0]}: file mismatch') return self.unsent_raw + self.unsent + def shred_abortable(self): + files = self.get_abortable() # raises AutosignTXError if no unsent TXs available + if keypress_confirm( + self.cfg, + 'The following file{} will be securely deleted:\n{}\nOK?'.format( + suf(files), + fmt_list(map(str, files), fmt='col', indent=' '))): + for f in files: + msg(f'Shredding file ‘{f}’') + from .fileutil import shred_file + shred_file(f) + sys.exit(0) + else: + die(1, 'Exiting at user request') + async def get_last_created(self): from .tx import CompletedTX ext = '.' + Signable.automount_transaction.subext diff --git a/mmgen/main_txsend.py b/mmgen/main_txsend.py index 560c32e9..3ecc4e22 100755 --- a/mmgen/main_txsend.py +++ b/mmgen/main_txsend.py @@ -23,8 +23,7 @@ mmgen-txsend: Broadcast a transaction signed by 'mmgen-txsign' to the network import sys from .cfg import gc,Config -from .util import async_run, msg, suf, die, fmt_list -from .fileutil import shred_file +from .util import async_run, die opts_data = { 'sets': [ @@ -70,19 +69,7 @@ elif not cfg._args and cfg.autosign: asi.do_mount() si = Signable.automount_transaction(asi) if cfg.abort: - files = si.get_abortable() # raises AutosignTXError if no unsent TXs available - from .ui import keypress_confirm - if keypress_confirm( - cfg, - 'The following file{} will be securely deleted:\n{}\nOK?'.format( - suf(files), - fmt_list(map(str, files), fmt='col', indent=' '))): - for f in files: - msg(f'Shredding file ‘{f}’') - shred_file(f) - sys.exit(0) - else: - die(1, 'Exiting at user request') + si.shred_abortable() # prompts user, then raises exception or exits elif cfg.status: if si.unsent: die(1, 'Transaction is unsent')