From a47e472078a0d0d70a7967277f6e6068e5678a15 Mon Sep 17 00:00:00 2001 From: MMGen Date: Thu, 17 Oct 2019 11:35:51 +0000 Subject: [PATCH] AddrList: new make_label() method --- mmgen/addr.py | 26 ++++++++++++++------------ test/test_py_d/ts_regtest.py | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/mmgen/addr.py b/mmgen/addr.py index a51f08ef..ee99fd8c 100755 --- a/mmgen/addr.py +++ b/mmgen/addr.py @@ -585,7 +585,15 @@ Removed {{}} duplicate WIF key{{}} from keylist (also in {pnm} key-address file Msg('generate_addrs_from_keys():\n{}'.format(e.pfmt())) qmsg('\rGenerated addresses from keylist: {}/{} '.format(n,len(d))) - def format(self,enable_comments=False): + def make_label(self): + bc,mt = g.proto.base_coin,self.al_id.mmtype + l_coin = [] if bc == 'BTC' else [g.coin] if bc == 'ETH' else [bc] + l_type = [] if mt == 'E' or (mt == 'L' and not g.proto.is_testnet()) else [mt.name.upper()] + l_tn = [] if not g.proto.is_testnet() else ['TESTNET'] + lbl_p2 = ':'.join(l_coin+l_type+l_tn) + return self.al_id.sid + ('',' ')[bool(lbl_p2)] + lbl_p2 + + def format(self,add_comments=False): out = [self.msgs['file_header']+'\n'] if self.chksum: @@ -593,22 +601,13 @@ Removed {{}} duplicate WIF key{{}} from keylist (also in {pnm} key-address file capfirst(self.data_desc),self.id_str,self.chksum)) out.append('# Record this value to a secure location.\n') - if type(self) == PasswordList: - lbl = '{} {} {}:{}'.format(self.al_id.sid,self.pw_id_str,self.pw_fmt_disp,self.pw_len) - else: - bc,mt = g.proto.base_coin,self.al_id.mmtype - l_coin = [] if bc == 'BTC' else [g.coin] if bc == 'ETH' else [bc] - l_type = [] if mt == 'E' or (mt == 'L' and not g.proto.is_testnet()) else [mt.name.upper()] - l_tn = [] if not g.proto.is_testnet() else ['TESTNET'] - lbl_p2 = ':'.join(l_coin+l_type+l_tn) - lbl = self.al_id.sid + ('',' ')[bool(lbl_p2)] + lbl_p2 - + lbl = self.make_label() dmsg_sc('lbl',lbl[9:]) out.append('{} {{'.format(lbl)) fs = ' {:<%s} {:<34}{}' % len(str(self.data[-1].idx)) for e in self.data: - c = ' '+e.label if enable_comments and e.label else '' + c = ' '+e.label if add_comments and e.label else '' if type(self) == KeyList: out.append(fs.format(e.idx,'{}: {}'.format(self.al_id.mmtype.wif_label,e.sec.wif),c)) elif type(self) == PasswordList: @@ -990,6 +989,9 @@ Record this checksum: it will be used to verify the password file in the future ret = lines.pop(0).split(None,2) return ret if len(ret) == 3 else ret + [''] + def make_label(self): + return '{} {} {}:{}'.format(self.al_id.sid,self.pw_id_str,self.pw_fmt_disp,self.pw_len) + class AddrData(MMGenObject): msgs = { 'too_many_acct_addresses': """ diff --git a/test/test_py_d/ts_regtest.py b/test/test_py_d/ts_regtest.py index 89f3ae58..e0d4a76d 100755 --- a/test/test_py_d/ts_regtest.py +++ b/test/test_py_d/ts_regtest.py @@ -243,7 +243,7 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared): a.set_comment(idx,get_label()) else: if n % 2: a.set_comment(idx,'Test address {}'.format(n)) - a.format(enable_comments=True) + a.format(add_comments=True) write_data_to_file(outfile,a.fmt_data,quiet=True,ignore_opt_outdir=True) end_silence()