From dda43d9dadbb3b80cb127cae0ae7d5764f85360a Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 18 May 2020 13:24:28 +0000 Subject: [PATCH] minor changes --- mmgen/altcoins/eth/tx.py | 2 +- mmgen/devtools.py | 11 ++++++++--- mmgen/main_txbump.py | 2 +- mmgen/tx.py | 18 +++++++++--------- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/mmgen/altcoins/eth/tx.py b/mmgen/altcoins/eth/tx.py index 156eda62..1398e68a 100755 --- a/mmgen/altcoins/eth/tx.py +++ b/mmgen/altcoins/eth/tx.py @@ -74,7 +74,7 @@ class EthereumMMGenTX(MMGenTX): def is_replaceable(self): return True - def get_fee_from_tx(self): + def get_fee(self): return self.fee def check_fee(self): diff --git a/mmgen/devtools.py b/mmgen/devtools.py index 922ae7e4..37e4ab31 100755 --- a/mmgen/devtools.py +++ b/mmgen/devtools.py @@ -9,7 +9,7 @@ if os.getenv('MMGEN_DEBUG') or os.getenv('MMGEN_TEST_SUITE') or os.getenv('MMGEN import sys,re,traceback,json,pprint from decimal import Decimal - from difflib import unified_diff + from difflib import unified_diff,ndiff def pmsg(*args,out=sys.stderr): d = args if len(args) > 1 else '' if not args else args[0] @@ -119,11 +119,16 @@ if os.getenv('MMGEN_DEBUG') or os.getenv('MMGEN_TEST_SUITE') or os.getenv('MMGEN fs = 'attribute {!r} of {} has not been initialized in constructor!' rdie(3,fs.format(attrname,cls.__name__)) - def print_diff(a,b,from_json=True): + def print_diff(a,b,from_file='',to_file='',from_json=True): if from_json: a = json.dumps(json.loads(a),indent=4).split('\n') if a else [] b = json.dumps(json.loads(b),indent=4).split('\n') if b else [] else: a = a.split('\n') b = b.split('\n') - sys.stderr.write(' DIFF:\n {}\n'.format('\n '.join(unified_diff(a,b)))) + sys.stderr.write(' DIFF:\n {}\n'.format('\n '.join(unified_diff(a,b,from_file,to_file)))) + + def get_ndiff(a,b): + a = a.split('\n') + b = b.split('\n') + return ndiff(a,b) diff --git a/mmgen/main_txbump.py b/mmgen/main_txbump.py index 65eabd2f..83eaee46 100755 --- a/mmgen/main_txbump.py +++ b/mmgen/main_txbump.py @@ -135,7 +135,7 @@ async def main(): tx.update_fee(op_idx,fee) - d = tx.get_fee_from_tx() + d = tx.get_fee() assert d == fee and d <= g.proto.max_tx_fee if g.proto.base_proto == 'Bitcoin': diff --git a/mmgen/tx.py b/mmgen/tx.py index 9dbcffce..4429e68f 100755 --- a/mmgen/tx.py +++ b/mmgen/tx.py @@ -305,8 +305,8 @@ class MMGenTX(MMGenObject): msg_non_mmgen_inputs = fmt(f""" NOTE: This transaction includes non-{g.proj_name} inputs, which makes the signing process more complicated. When signing the transaction, keys for non-{g.proj_name} - inputs must be supplied to '{g.proj_name.lower()}-txsign' in a file with the '--keys-from-file' - option. + inputs must be supplied using the '--keys-from-file' option. The key file + must contain exactly one key per line. Selected non-{g.proj_name} inputs: {{}} """).strip() @@ -322,7 +322,7 @@ class MMGenTX(MMGenObject): self.hex = '' # raw serialized hex transaction self.label = MMGenTxLabel('') self.txid = '' - self.coin_txid = '' + self.coin_txid = '' self.timestamp = '' self.chksum = '' self.fmt_data = '' @@ -438,7 +438,7 @@ class MMGenTX(MMGenObject): def edit_comment(self): return self.add_comment(self) - def get_fee_from_tx(self): + def get_fee(self): return self.sum_inputs() - self.sum_outputs() def has_segwit_inputs(self): @@ -902,9 +902,9 @@ class MMGenTX(MMGenObject): m = 'Transaction has MMGen Segwit outputs, but this blockchain does not support Segwit' die(2,m+' at the current height') - if self.get_fee_from_tx() > g.proto.max_tx_fee: + if self.get_fee() > g.proto.max_tx_fee: die(2,'Transaction fee ({}) greater than {} max_tx_fee ({} {})!'.format( - self.get_fee_from_tx(), + self.get_fee(), g.proto.name, g.proto.max_tx_fee, g.proto.coin )) @@ -960,7 +960,7 @@ class MMGenTX(MMGenObject): ('-'+g.dcoin,'')[g.coin=='BTC'], self.send_amt, ('',',{}'.format(self.fee_abs2rel( - self.get_fee_from_tx(),to_unit=self.fn_fee_unit)) + self.get_fee(),to_unit=self.fn_fee_unit)) )[self.is_replaceable()], ('',',tl={}'.format(tl))[bool(tl)], tn,self.ext, @@ -1082,11 +1082,11 @@ class MMGenTX(MMGenObject): def format_view_rel_fee(self,terse): return ' ({} {})\n'.format( - pink(str(self.fee_abs2rel(self.get_fee_from_tx()))), + pink(str(self.fee_abs2rel(self.get_fee()))), self.rel_fee_disp) def format_view_abs_fee(self): - return g.proto.coin_amt(self.get_fee_from_tx()).hl() + return g.proto.coin_amt(self.get_fee()).hl() def format_view_verbose_footer(self): tsize = len(self.hex)//2 if self.hex else 'unknown'