proto.btc.tx.data_output -> tx.data_output

This commit is contained in:
The MMGen Project 2026-09-06 10:08:41 +00:00
commit 518b2f403f
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
6 changed files with 16 additions and 16 deletions

View file

@ -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

View file

@ -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'])

View file

@ -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

View file

@ -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)

View file

@ -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):

View file

@ -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'