new module: swap.util

This commit is contained in:
The MMGen Project 2026-09-29 09:23:31 +00:00
commit 23dcf58b7d
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
5 changed files with 30 additions and 16 deletions

View file

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

View file

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

26
mmgen/swap/util.py Executable file
View file

@ -0,0 +1,26 @@
#!/usr/bin/env python3
#
# MMGen Wallet, a terminal-based cryptocurrency wallet
# Copyright (C)2013-2026 The MMGen Project <mmgen@tuta.io>
# 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)

View file

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

View file

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