From be025dc817262520c5cca1b6b4ef99c1cff33b3d Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 15 Feb 2025 09:54:20 +0000 Subject: [PATCH] tx.base: add `nondata_outputs` property --- mmgen/data/version | 2 +- mmgen/proto/btc/tx/base.py | 4 ++++ mmgen/proto/btc/tx/completed.py | 2 +- mmgen/proto/btc/tx/new.py | 2 +- mmgen/proto/eth/tx/base.py | 4 ++++ mmgen/tx/bump.py | 4 ++-- mmgen/tx/new.py | 8 ++++---- 7 files changed, 17 insertions(+), 9 deletions(-) diff --git a/mmgen/data/version b/mmgen/data/version index 98c29545..7e14326e 100644 --- a/mmgen/data/version +++ b/mmgen/data/version @@ -1 +1 @@ -15.1.dev14 +15.1.dev15 diff --git a/mmgen/proto/btc/tx/base.py b/mmgen/proto/btc/tx/base.py index 6320ae71..dd99dde5 100755 --- a/mmgen/proto/btc/tx/base.py +++ b/mmgen/proto/btc/tx/base.py @@ -295,6 +295,10 @@ class Base(TxBase): getattr(self.proto.coin_amt, to_unit) / self.estimate_size())) + @property + def nondata_outputs(self): + return [o for o in self.outputs if not o.data] + @property def deserialized(self): if not self._deserialized: diff --git a/mmgen/proto/btc/tx/completed.py b/mmgen/proto/btc/tx/completed.py index a154c12d..b4261aca 100755 --- a/mmgen/proto/btc/tx/completed.py +++ b/mmgen/proto/btc/tx/completed.py @@ -67,7 +67,7 @@ class Completed(Base, TxBase.Completed): @property def send_amt(self): return self.sum_outputs( - exclude = None if len(self.outputs) == 1 else self.chg_idx + exclude = None if len(self.nondata_outputs) == 1 else self.chg_idx ) def check_txfile_hex_data(self): diff --git a/mmgen/proto/btc/tx/new.py b/mmgen/proto/btc/tx/new.py index 6f0ad80a..464b0b3c 100755 --- a/mmgen/proto/btc/tx/new.py +++ b/mmgen/proto/btc/tx/new.py @@ -132,7 +132,7 @@ class New(Base, TxNew): cfg = self.cfg, message = yellow(message), action = 'Are you sure this is what you want?') - if len(self.outputs) > 1 and not self.chg_output.mmid: + if len(self.nondata_outputs) > 1 and not self.chg_output.mmid: do_err() async def create_serialized(self, locktime=None, bump=None): diff --git a/mmgen/proto/eth/tx/base.py b/mmgen/proto/eth/tx/base.py index a2581ef1..e0083a4d 100755 --- a/mmgen/proto/eth/tx/base.py +++ b/mmgen/proto/eth/tx/base.py @@ -29,6 +29,10 @@ class Base(TxBase.Base): usr_contract_data = HexStr('') disable_fee_check = False + @property + def nondata_outputs(self): + return self.outputs + def pretty_fmt_fee(self, fee): if fee < 1: ret = f'{fee:.8f}'.rstrip('0') diff --git a/mmgen/tx/bump.py b/mmgen/tx/bump.py index c5502ba4..d6020d9d 100755 --- a/mmgen/tx/bump.py +++ b/mmgen/tx/bump.py @@ -49,8 +49,8 @@ class Bump(Completed, New): return False return True - if len(self.outputs) == 1: - if check_sufficient_funds(self.outputs[0].amt): + if len(self.nondata_outputs) == 1: + if check_sufficient_funds(self.nondata_outputs[0].amt): self.bump_output_idx = 0 return 0 else: diff --git a/mmgen/tx/new.py b/mmgen/tx/new.py index 2d984657..50fdf55f 100755 --- a/mmgen/tx/new.py +++ b/mmgen/tx/new.py @@ -245,8 +245,8 @@ class New(Base): f'{gc.proj_name} Segwit address requested on the command line, ' 'but Segwit is not active on this chain') - if not self.outputs: - die(2, 'At least one output must be specified on the command line') + if not self.nondata_outputs: + die(2, 'At least one spending output must be specified on the command line') self.add_mmaddrs_to_outputs(ad_f, ad_w) @@ -255,7 +255,7 @@ class New(Base): if self.chg_output is not None: if self.chg_autoselected: self.confirm_autoselected_addr(self.chg_output.mmid, 'change address') - elif len(self.outputs) > 1: + elif len(self.nondata_outputs) > 1: await self.warn_addr_used(self.proto, self.chg_output, 'change address') def get_addrfiles_from_cmdline(self, cmd_args): @@ -289,7 +289,7 @@ class New(Base): self.cfg, 'Using {a} as {b}. OK?'.format( a = mmid.hl(), - b = 'single output address' if len(self.outputs) == 1 else desc), + b = 'single output address' if len(self.nondata_outputs) == 1 else desc), default_yes = True): die(1, 'Exiting at user request')