From 81e11f3405ddbd5a77119a90298f129f293b4536 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Tue, 4 Mar 2025 09:51:05 +0000 Subject: [PATCH] tx.new_swap: add initializer, `swap_proto_mod` attribute --- mmgen/proto/btc/tx/new_swap.py | 6 ++---- mmgen/tx/bump.py | 3 +++ mmgen/tx/new.py | 6 ------ mmgen/tx/new_swap.py | 10 ++++++++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/mmgen/proto/btc/tx/new_swap.py b/mmgen/proto/btc/tx/new_swap.py index e40cef5e..c7367846 100755 --- a/mmgen/proto/btc/tx/new_swap.py +++ b/mmgen/proto/btc/tx/new_swap.py @@ -41,10 +41,6 @@ class NewSwap(New, TxNewSwap): async def process_swap_cmdline_args(self, cmd_args, addrfiles): - from ....protocol import init_proto - import importlib - sp = importlib.import_module(f'mmgen.swap.proto.{self.swap_proto}') - class CmdlineArgs: # listed in command-line order # send_coin # required: uppercase coin symbol send_amt = None # optional: Omit to skip change addr and send value of all inputs minus fees to vault @@ -102,6 +98,8 @@ class NewSwap(New, TxNewSwap): if args_in: # done parsing, all args consumed self.cfg._usage() + from ....protocol import init_proto + sp = self.swap_proto_mod args_in = list(cmd_args) args = CmdlineArgs() parse() diff --git a/mmgen/tx/bump.py b/mmgen/tx/bump.py index 327b0279..5a454cc4 100755 --- a/mmgen/tx/bump.py +++ b/mmgen/tx/bump.py @@ -42,6 +42,9 @@ class Bump(Completed, NewSwap): setattr(self, attr, getattr(Base, attr)) self.outputs = self.OutputList(self) self.cfg = kwargs['cfg'] # must use current cfg opts, not those from orig_tx + elif self.is_swap: + import importlib + self.swap_proto_mod = importlib.import_module(f'mmgen.swap.proto.{self.swap_proto}') if not self.is_replaceable(): die(1, f'Transaction {self.txid} is not replaceable') diff --git a/mmgen/tx/new.py b/mmgen/tx/new.py index 77cd1e6f..a147a791 100755 --- a/mmgen/tx/new.py +++ b/mmgen/tx/new.py @@ -82,12 +82,6 @@ class New(Base): chg_autoselected = False _funds_available = namedtuple('funds_available', ['is_positive', 'amt']) - def __init__(self, *args, target=None, **kwargs): - if target == 'swaptx': - self.is_swap = True - self.swap_proto = kwargs['cfg'].swap_proto - super().__init__(*args, **kwargs) - def warn_insufficient_funds(self, amt, coin): msg(self.msg_insufficient_funds.format(amt.hl(), coin)) diff --git a/mmgen/tx/new_swap.py b/mmgen/tx/new_swap.py index 14e2a97c..55501f0e 100755 --- a/mmgen/tx/new_swap.py +++ b/mmgen/tx/new_swap.py @@ -17,9 +17,15 @@ from .new import New class NewSwap(New): desc = 'swap transaction' - def update_vault_output(self, amt): + def __init__(self, *args, **kwargs): import importlib - sp = importlib.import_module(f'mmgen.swap.proto.{self.swap_proto}') + self.is_swap = True + self.swap_proto = kwargs['cfg'].swap_proto + self.swap_proto_mod = importlib.import_module(f'mmgen.swap.proto.{self.swap_proto}') + New.__init__(self, *args, **kwargs) + + def update_vault_output(self, amt): + sp = self.swap_proto_mod c = sp.rpc_client(self, amt) from ..util import msg