From 0f7e51e49975146786e1126f849cfbbc36e79ac9 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 15 Feb 2025 09:54:19 +0000 Subject: [PATCH] tx.new: add `is_swap` attribute --- mmgen/proto/btc/tx/new.py | 5 +++-- mmgen/tx/base.py | 1 + mmgen/tx/file.py | 1 + mmgen/tx/info.py | 3 +++ mmgen/tx/new.py | 6 +++--- mmgen/tx/new_swap.py | 1 + 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/mmgen/proto/btc/tx/new.py b/mmgen/proto/btc/tx/new.py index e2affba3..89efb2c1 100755 --- a/mmgen/proto/btc/tx/new.py +++ b/mmgen/proto/btc/tx/new.py @@ -135,7 +135,7 @@ class New(Base, TxNew): async def create_serialized(self, locktime=None, bump=None): - if not bump: + if not (bump or self.is_swap): self.inputs.sort_bip69() # Set all sequence numbers to the same value, in conformity with the behavior of most modern wallets: do_rbf = self.proto.cap('rbf') and not self.cfg.no_rbf @@ -143,7 +143,8 @@ class New(Base, TxNew): for i in self.inputs: i.sequence = seqnum_val - self.outputs.sort_bip69() + if not self.is_swap: + self.outputs.sort_bip69() inputs_list = [{ 'txid': e.txid, diff --git a/mmgen/tx/base.py b/mmgen/tx/base.py index c6998e10..196b08e9 100755 --- a/mmgen/tx/base.py +++ b/mmgen/tx/base.py @@ -79,6 +79,7 @@ class Base(MMGenObject): locktime = None chain = None signed = False + is_swap = False file_format = 'json' non_mmgen_inputs_msg = f""" This transaction includes inputs with non-{gc.proj_name} addresses. When diff --git a/mmgen/tx/file.py b/mmgen/tx/file.py index bd301d06..aa52e826 100755 --- a/mmgen/tx/file.py +++ b/mmgen/tx/file.py @@ -71,6 +71,7 @@ class MMGenTxFile(MMGenObject): 'comment': MMGenTxComment, 'coin_txid': CoinTxID, 'sent_timestamp': None, + 'is_swap': False, } def __init__(self, tx): diff --git a/mmgen/tx/info.py b/mmgen/tx/info.py index 3157a5c6..a4079eb6 100755 --- a/mmgen/tx/info.py +++ b/mmgen/tx/info.py @@ -29,6 +29,9 @@ class TxInfo: tx = self.tx + if tx.is_swap: + sort = 'raw' + if tx.proto.base_proto == 'Ethereum': blockcount = None else: diff --git a/mmgen/tx/new.py b/mmgen/tx/new.py index 6b3a8ef1..2d984657 100755 --- a/mmgen/tx/new.py +++ b/mmgen/tx/new.py @@ -83,7 +83,7 @@ class New(Base): _funds_available = namedtuple('funds_available', ['is_positive', 'amt']) def __init__(self, *args, target=None, **kwargs): - self.target = target + self.is_swap = target == 'swaptx' super().__init__(*args, **kwargs) def warn_insufficient_funds(self, amt, coin): @@ -266,7 +266,7 @@ class New(Base): edesc = 'argument', ) cmd_args = tuple(a for a in cmd_args if a not in addrfile_args) - if self.target == 'tx': + if not self.is_swap: cmd_args = remove_dups(cmd_args, desc='command line', edesc='argument') return cmd_args, addrfile_args @@ -415,7 +415,7 @@ class New(Base): if not do_info: cmd_args, addrfile_args = self.get_addrfiles_from_cmdline(cmd_args) - if self.target == 'swaptx': + if self.is_swap: # updates self.proto! self.proto, cmd_args = await self.process_swap_cmdline_args(cmd_args, addrfile_args) from ..rpc import rpc_init diff --git a/mmgen/tx/new_swap.py b/mmgen/tx/new_swap.py index d43ff8a3..c03f1560 100755 --- a/mmgen/tx/new_swap.py +++ b/mmgen/tx/new_swap.py @@ -16,6 +16,7 @@ from .new import New class NewSwap(New): desc = 'swap transaction' + is_swap = True async def process_swap_cmdline_args(self, cmd_args): raise NotImplementedError(f'Swap not implemented for protocol {self.proto.__name__}')