From 23dcf58b7d17a66742e1a74f181a1d01bf9c530c Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Tue, 29 Sep 2026 09:23:31 +0000 Subject: [PATCH] new module: `swap.util` --- mmgen/help/help_notes.py | 2 +- mmgen/main_txcreate.py | 2 +- mmgen/swap/util.py | 26 ++++++++++++++++++++++++++ mmgen/tx/base.py | 2 +- mmgen/tx/new_swap.py | 14 +------------- 5 files changed, 30 insertions(+), 16 deletions(-) create mode 100755 mmgen/swap/util.py diff --git a/mmgen/help/help_notes.py b/mmgen/help/help_notes.py index 4c859da3..e23bd4d4 100755 --- a/mmgen/help/help_notes.py +++ b/mmgen/help/help_notes.py @@ -62,7 +62,7 @@ class help_notes: return pfx + sep.join(u[0] for u in cu[:-1]) + ('', conj)[len(cu)>1] + cu[-1][0] + sfx def stream_interval(self): - from ..tx.new_swap import get_swap_proto_mod + from ..swap.util import get_swap_proto_mod return get_swap_proto_mod(self.cfg.swap_proto).SwapCfg(self.cfg).si.dfl def fee_spec_names(self, *, proto=None, linebreak=' '): diff --git a/mmgen/main_txcreate.py b/mmgen/main_txcreate.py index 561f1bb2..8c48de4e 100755 --- a/mmgen/main_txcreate.py +++ b/mmgen/main_txcreate.py @@ -126,7 +126,7 @@ cfg = Config(opts_data=opts_data) if cfg.list_assets: import sys - from .tx.new_swap import get_swap_proto_mod + from .swap.util import get_swap_proto_mod sp = get_swap_proto_mod(cfg.swap_proto) Msg('AVAILABLE SWAP ASSETS:\n' + sp.SwapAsset('BTC', 'send').fmt_assets_data(indent=' ')) sys.exit(0) diff --git a/mmgen/swap/util.py b/mmgen/swap/util.py new file mode 100755 index 00000000..08b79fe9 --- /dev/null +++ b/mmgen/swap/util.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +# +# MMGen Wallet, a terminal-based cryptocurrency wallet +# Copyright (C)2013-2026 The MMGen Project +# Licensed under the GNU General Public License, Version 3: +# https://www.gnu.org/licenses +# Public project repositories: +# https://github.com/mmgen/mmgen-wallet +# https://gitlab.com/mmgen/mmgen-wallet + +""" +swap.util: swap utilities for the MMGen Wallet suite +""" + +def get_swap_proto_mod(swap_proto_name): + import importlib + return importlib.import_module(f'mmgen.swap.proto.{swap_proto_name}') + +def init_swap_proto(cfg, asset): + from ..protocol import init_proto + return init_proto( + cfg, + asset.coin, + network = cfg._proto.network, + tokensym = asset.tokensym, + need_amt = True) diff --git a/mmgen/tx/base.py b/mmgen/tx/base.py index b605d0c7..2ca80396 100755 --- a/mmgen/tx/base.py +++ b/mmgen/tx/base.py @@ -225,7 +225,7 @@ class Base(MMGenObject): # swap methods: @cached_property def swap_proto_mod(self): - from .new_swap import get_swap_proto_mod + from ..swap.util import get_swap_proto_mod return get_swap_proto_mod(self.swap_proto) @cached_property diff --git a/mmgen/tx/new_swap.py b/mmgen/tx/new_swap.py index 4685dbba..ac2f4d3a 100755 --- a/mmgen/tx/new_swap.py +++ b/mmgen/tx/new_swap.py @@ -16,19 +16,7 @@ from collections import namedtuple from .new import New from ..amt import UniAmt - -def get_swap_proto_mod(swap_proto_name): - import importlib - return importlib.import_module(f'mmgen.swap.proto.{swap_proto_name}') - -def init_swap_proto(cfg, asset): - from ..protocol import init_proto - return init_proto( - cfg, - asset.coin, - network = cfg._proto.network, - tokensym = asset.tokensym, - need_amt = True) +from ..swap.util import get_swap_proto_mod, init_swap_proto def get_send_proto(cfg): try: