From 518b2f403f5833bfa9d0154d2b50308e96102bc7 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 6 Sep 2026 10:08:41 +0000 Subject: [PATCH] `proto.btc.tx.data_output` -> `tx.data_output` --- mmgen/proto/btc/tx/base.py | 2 +- mmgen/proto/btc/tx/new.py | 9 --------- mmgen/proto/eth/tx/new.py | 3 +++ mmgen/{proto/btc => }/tx/data_output.py | 8 ++++---- mmgen/tx/new.py | 8 +++++++- test/modtest_d/tx.py | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) rename mmgen/{proto/btc => }/tx/data_output.py (93%) diff --git a/mmgen/proto/btc/tx/base.py b/mmgen/proto/btc/tx/base.py index b496c83f..c824ada0 100755 --- a/mmgen/proto/btc/tx/base.py +++ b/mmgen/proto/btc/tx/base.py @@ -18,7 +18,7 @@ from ....tx.base import Base as TxBase from ....obj import MMGenList, HexStr, ListItemAttr from ....util import msg, make_chksum_6, die, pp_fmt -from .data_output import DataOutput +from ....tx.data_output import DataOutput def data2scriptPubKey(data): return '6a' + '{:02x}'.format(len(data)) + data.hex() # OP_RETURN data diff --git a/mmgen/proto/btc/tx/new.py b/mmgen/proto/btc/tx/new.py index a7272ca8..eaa19e88 100755 --- a/mmgen/proto/btc/tx/new.py +++ b/mmgen/proto/btc/tx/new.py @@ -27,15 +27,6 @@ class New(Base, TxNew): async def set_gas(self, *, to_addr=None, force=False): return None - def process_data_output_arg(self, arg): - if any(arg.startswith(pfx) for pfx in ('data:', 'hexdata:')): - if hasattr(self, '_have_op_return_data'): - die(1, 'Transaction may have at most one OP_RETURN data output!') - self._have_op_return_data = True - from .data_output import DataOutput - DataOutput(self.proto, arg) # test data for validity - return arg - @property def relay_fee(self): kb_fee = self.proto.coin_amt(self.rpc.cached['networkinfo']['relayfee']) diff --git a/mmgen/proto/eth/tx/new.py b/mmgen/proto/eth/tx/new.py index c41fa68a..46ee7cc6 100755 --- a/mmgen/proto/eth/tx/new.py +++ b/mmgen/proto/eth/tx/new.py @@ -39,6 +39,9 @@ class New(VmNew, Base, TxBase.New): self.usr_contract_data = bytes.fromhex(fp.read().strip()) self.disable_fee_check = True + def process_data_output_arg(self, arg): + pass + async def get_gas_estimateGas(self, *, to_addr): return self.dfl_gas diff --git a/mmgen/proto/btc/tx/data_output.py b/mmgen/tx/data_output.py similarity index 93% rename from mmgen/proto/btc/tx/data_output.py rename to mmgen/tx/data_output.py index a4261d0c..b155e21a 100755 --- a/mmgen/proto/btc/tx/data_output.py +++ b/mmgen/tx/data_output.py @@ -9,10 +9,10 @@ # https://gitlab.com/mmgen/mmgen-wallet """ -proto.btc.tx.data_output: Bitcoin data output class +tx.data_output: transaction data output class """ -from ....obj import InitErrors +from ..obj import InitErrors class DataOutput(bytes, InitErrors): @@ -28,7 +28,7 @@ class DataOutput(bytes, InitErrors): if data_spec.startswith('hexdata:'): hexdata = data_spec[8:] - from ....util import is_hex_str + from ..util import is_hex_str assert is_hex_str(hexdata), f'{hexdata!r}: {cls.desc} hexdata not in hexadecimal format' assert not len(hexdata) % 2, f'{len(hexdata)}: {cls.desc} hexdata of non-even length' ret = bytes.fromhex(hexdata) @@ -71,7 +71,7 @@ class DataOutput(bytes, InitErrors): def hl(self, *, add_label=False): 'colorize and optionally label the result of str()' - from ....color import blue, pink + from ..color import blue, pink ret = str(self) if add_label: return blue(self.desc + (' (hex): ' if self.display_hex else ': ')) + pink(ret) diff --git a/mmgen/tx/new.py b/mmgen/tx/new.py index a34fd75f..db8e6451 100755 --- a/mmgen/tx/new.py +++ b/mmgen/tx/new.py @@ -172,7 +172,13 @@ class New(Base): self.Output(self.proto, addr=coinaddr, amt=amt, is_chg=is_chg, is_vault=is_vault, data=data)) def process_data_output_arg(self, arg): - return None + if any(arg.startswith(pfx) for pfx in ('data:', 'hexdata:')): + if hasattr(self, '_have_data_output'): + die(1, 'Transaction may have at most one data output!') + self._have_data_output = True + from .data_output import DataOutput + DataOutput(self.proto, arg) # test data for validity + return arg def parse_cmdline_arg(self, proto, arg_in, ad_f, ad_w): diff --git a/test/modtest_d/tx.py b/test/modtest_d/tx.py index ab70004b..55b3737e 100755 --- a/test/modtest_d/tx.py +++ b/test/modtest_d/tx.py @@ -114,7 +114,7 @@ class unit_tests: def data_output(self, name, ut, desc='DataOutput class'): max_len = cfg._proto.max_op_return_data_len - from mmgen.proto.btc.tx.data_output import DataOutput + from mmgen.tx.data_output import DataOutput vecs = [ 'data:=:ETH.ETH:0x86d526d6624AbC0178cF7296cD538Ecc080A95F1:0/1/0', 'hexdata:3d3a4554482e4554483a30783836643532366436363234416243303137'