mmgen-autosign: use default wallet as autosign wallet by default

This commit is contained in:
The MMGen Project 2023-04-18 18:35:59 +00:00
commit 686fdfcc72
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
3 changed files with 50 additions and 18 deletions

View file

@ -19,7 +19,9 @@ from collections import namedtuple
from .cfg import Config
from .util import msg,msg_r,ymsg,rmsg,gmsg,bmsg,die,suf,fmt,fmt_list
from .color import yellow,red,orange
from .wallet import Wallet
from .wallet import Wallet,get_wallet_cls
from .filename import find_file_in_dir
from .ui import keypress_confirm
class AutosignConfig(Config):
_set_ok = ('usr_randchars','_proto','outdir','passwd_file')
@ -368,7 +370,15 @@ class Autosign:
def setup(self):
self.remove_wallet_dir()
self.gen_key(no_unmount=True)
ss_in = Wallet( self.cfg, in_fmt=self.mn_fmts[self.cfg.mnemonic_fmt or self.dfl_mn_fmt] )
wf = find_file_in_dir( get_wallet_cls('mmgen'), self.cfg.data_dir )
if wf and keypress_confirm(
cfg = self.cfg,
prompt = f'Default wallet {wf!r} found.\nUse default wallet for autosigning?',
default_yes = True ):
from .cfg import Config
ss_in = Wallet( Config(), wf )
else:
ss_in = Wallet( self.cfg, in_fmt=self.mn_fmts[self.cfg.mnemonic_fmt or self.dfl_mn_fmt] )
ss_out = Wallet( self.cfg, ss=ss_in )
ss_out.write_to_file( desc='autosign wallet', outdir=self.wallet_dir )

View file

@ -1 +1 @@
13.3.dev45
13.3.dev46

View file

@ -163,13 +163,24 @@ class TestSuiteAutosignBase(TestSuiteBase):
t.expect_getend('Wrote key file ')
return t
def make_wallet_mmgen(self):
return self.make_wallet(mn_type='mmgen')
def create_dfl_wallet(self):
t = self.spawn( 'mmgen-walletconv', [
f'--outdir={cfg.data_dir}',
'--usr-randchars=0', '--quiet', '--hash-preset=1', '--label=foo',
'test/ref/98831F3A.hex'
]
)
t.passphrase_new('new MMGen wallet','abc')
t.written_to_file('MMGen wallet')
return t
def make_wallet_from_dfl_wallet(self):
return self.make_wallet(mn_type='default',use_dfl_wallet=True)
def make_wallet_bip39(self):
return self.make_wallet(mn_type='bip39')
def make_wallet(self,mn_type=None,mn_file=None):
def make_wallet(self,mn_type=None,mn_file=None,use_dfl_wallet=False):
mn_desc = mn_type or 'default'
mn_type = mn_type or 'mmgen'
@ -179,16 +190,23 @@ class TestSuiteAutosignBase(TestSuiteBase):
([] if mn_desc == 'default' else [f'--mnemonic-fmt={mn_type}']) +
['setup'] )
mn_file = mn_file or { 'mmgen': dfl_words_file, 'bip39': dfl_bip39_file }[mn_type]
mn = read_from_file(mn_file).strip().split()
from mmgen.mn_entry import mn_entry
entry_mode = 'full'
mne = mn_entry( cfg, mn_type, entry_mode )
if use_dfl_wallet:
t.expect( 'Use default wallet for autosigning? (Y/n): ', 'y' )
t.passphrase( 'MMGen wallet', 'abc' )
else:
if use_dfl_wallet is not None: # None => no dfl wallet present
t.expect( 'Use default wallet for autosigning? (Y/n): ', 'n' )
mn_file = mn_file or { 'mmgen': dfl_words_file, 'bip39': dfl_bip39_file }[mn_type]
mn = read_from_file(mn_file).strip().split()
from mmgen.mn_entry import mn_entry
entry_mode = 'full'
mne = mn_entry( cfg, mn_type, entry_mode )
t.expect('words: ',{ 12:'1', 18:'2', 24:'3' }[len(mn)])
t.expect('OK? (Y/n): ','\n')
t.expect('Type a number.*: ',str(mne.entry_modes.index(entry_mode)+1),regex=True)
stealth_mnemonic_entry(t,mne,mn,entry_mode)
t.expect('words: ',{ 12:'1', 18:'2', 24:'3' }[len(mn)])
t.expect('OK? (Y/n): ','\n')
t.expect('Type a number.*: ',str(mne.entry_modes.index(entry_mode)+1),regex=True)
stealth_mnemonic_entry(t,mne,mn,entry_mode)
wf = t.written_to_file('Autosign wallet')
return t
@ -341,10 +359,11 @@ class TestSuiteAutosign(TestSuiteAutosignBase):
('start_daemons', 'starting daemons'),
('copy_tx_files', 'copying transaction files'),
('gen_key', 'generating key'),
('make_wallet_mmgen', 'making wallet (MMGen native)'),
('create_dfl_wallet', 'creating default MMGen wallet'),
('make_wallet_from_dfl_wallet','making autosign wallet (from user’s default wallet)'),
('sign_quiet', 'signing transactions (--quiet)'),
('remove_signed_txfiles', 'removing signed transaction files'),
('make_wallet_bip39', 'making wallet (BIP39)'),
('make_wallet_bip39', 'making autosign wallet (from BIP39 mnemonic)'),
('create_bad_txfiles', 'creating bad transaction files'),
('sign_full_summary', 'signing transactions (--full-summary)'),
('remove_signed_txfiles_btc','removing transaction files (BTC only)'),
@ -403,7 +422,7 @@ class TestSuiteAutosignLive(TestSuiteAutosignBTC):
('start_daemons', 'starting daemons'),
('copy_tx_files', 'copying transaction files'),
('gen_key', 'generating key'),
('make_wallet_bip39', 'making wallet (BIP39)'),
('make_wallet_mmgen', 'making autosign wallet (from MMGen native mnemonic)'),
('sign_live', 'signing transactions'),
('create_bad_txfiles', 'creating bad transaction files'),
('sign_live_led', 'signing transactions (--led)'),
@ -412,6 +431,9 @@ class TestSuiteAutosignLive(TestSuiteAutosignBTC):
('stop_daemons', 'stopping daemons'),
)
def make_wallet_mmgen(self):
return self.make_wallet(mn_type='mmgen',use_dfl_wallet=None)
def sign_live(self):
return self.do_sign_live([])