From 1356325bf4a6345c62c56a586cf6a2ef06334cb5 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 7 Oct 2026 16:40:39 +0000 Subject: [PATCH] init_proto(): remove `testnet` and `regtest` params --- mmgen/altcoin/params.py | 6 +++--- mmgen/autosign/__init__.py | 2 +- mmgen/proto/btc/regtest.py | 4 ++-- mmgen/protocol.py | 16 +++++----------- mmgen/swap/proto/thorchain/thornode.py | 3 +-- mmgen/swap/util.py | 1 - mmgen/tx/base.py | 2 +- mmgen/tx/completed.py | 1 - mmgen/xmrwallet/ops/__init__.py | 2 +- test/gentest.py | 4 ++-- 10 files changed, 16 insertions(+), 25 deletions(-) diff --git a/mmgen/altcoin/params.py b/mmgen/altcoin/params.py index 1522c299..feb56987 100644 --- a/mmgen/altcoin/params.py +++ b/mmgen/altcoin/params.py @@ -288,7 +288,7 @@ def make_proto(e, *, testnet=False): 'dfl_mmtype': 'L', 'mmcaps': ()})) -def init_genonly_altcoins(usr_coin=None, *, testnet=False): +def init_genonly_altcoins(usr_coin=None, *, network=None): """ Initialize altcoin protocol class or classes for current network. If usr_coin is a core coin, initialization is skipped. @@ -298,8 +298,8 @@ def init_genonly_altcoins(usr_coin=None, *, testnet=False): """ data = {'mainnet': (), 'testnet': ()} - networks = ['mainnet'] + (['testnet'] if testnet else []) - network = 'testnet' if testnet else 'mainnet' + network = 'testnet' if network in ('testnet', 'regtest') else 'mainnet' + networks = ['mainnet'] + (['testnet'] if network == 'testnet' else []) if usr_coin is None: for network in networks: diff --git a/mmgen/autosign/__init__.py b/mmgen/autosign/__init__.py index bfd4a3fc..981d9ed9 100644 --- a/mmgen/autosign/__init__.py +++ b/mmgen/autosign/__init__.py @@ -165,7 +165,7 @@ class Autosign: async def check_daemons_running(self): from ..protocol import init_proto for coin in self.coins: - proto = init_proto(self.cfg, coin, network=self.cfg.network, need_amt=True) + proto = init_proto(self.cfg, coin, need_amt=True) if proto.sign_mode == 'daemon': self.cfg._util.vmsg(f'Checking {coin} daemon') from ..rpc import rpc_init diff --git a/mmgen/proto/btc/regtest.py b/mmgen/proto/btc/regtest.py index 2d3bbd43..6be6c1db 100644 --- a/mmgen/proto/btc/regtest.py +++ b/mmgen/proto/btc/regtest.py @@ -81,7 +81,7 @@ class MMGenRegtest(MMGenObject): assert self.coin in self.coins, f'{coin!r}: invalid coin for regtest' - self.proto = init_proto(cfg, self.coin, regtest=True, need_amt=True) + self.proto = init_proto(cfg, self.coin, network='regtest', need_amt=True) self.d = CoinDaemon( cfg, network_id = self.coin + '_rt', @@ -305,7 +305,7 @@ class MMGenRegtest(MMGenObject): async def fork(self, coin): # currently disabled - proto = init_proto(self.cfg, coin, testnet=False) + proto = init_proto(self.cfg, coin) if not [f for f in proto.forks if f[2] == proto.coin.lower() and f[3] is True]: die(1, f'Coin {proto.coin} is not a replayable fork of coin {coin}') diff --git a/mmgen/protocol.py b/mmgen/protocol.py index 80da03d3..83ce6f38 100644 --- a/mmgen/protocol.py +++ b/mmgen/protocol.py @@ -301,33 +301,27 @@ def init_proto( cfg, coin = None, *, - testnet = False, - regtest = False, network = None, network_id = None, tokensym = None, need_amt = False, return_cls = False): - assert type(testnet) is bool, 'init_proto_chk1' - assert type(regtest) is bool, 'init_proto_chk2' - assert coin or network_id, 'init_proto_chk3' - assert not (coin and network_id), 'init_proto_chk4' + assert coin or network_id, 'init_proto_chk1' + assert not (coin and network_id), 'init_proto_chk2' if network_id: coin, network = CoinProtocol.Base.parse_network_id(network_id) elif network: - assert network in CoinProtocol.Base.networks, f'init_proto_chk5 - {network!r}: invalid network' - assert testnet is False, 'init_proto_chk6' - assert regtest is False, 'init_proto_chk7' + assert network in CoinProtocol.Base.networks, f'init_proto_chk3 - {network!r}: invalid network' else: - network = 'regtest' if regtest else 'testnet' if testnet else 'mainnet' + network = cfg.network coin = coin.lower() if coin not in CoinProtocol.coins: from .altcoin.params import init_genonly_altcoins - init_genonly_altcoins(coin, testnet=testnet) # raises exception on failure + init_genonly_altcoins(coin, network=network) # raises exception on failure name = CoinProtocol.coins[coin].name proto_name = name + ('' if network == 'mainnet' else network.capitalize()) diff --git a/mmgen/swap/proto/thorchain/thornode.py b/mmgen/swap/proto/thorchain/thornode.py index 089392e0..2f38286c 100644 --- a/mmgen/swap/proto/thorchain/thornode.py +++ b/mmgen/swap/proto/thorchain/thornode.py @@ -32,8 +32,7 @@ class Thornode: def __init__(self, tx, amt): self.tx = tx self.in_amt = UniAmt(f'{amt:.8f}') - proto = init_proto(tx.cfg, 'rune', network=tx.cfg._proto.network) - self.rpc = ThornodeSwapClient(tx.cfg, proto) + self.rpc = ThornodeSwapClient(tx.cfg, init_proto(tx.cfg, 'rune')) def get_quote(self, swap_cfg): diff --git a/mmgen/swap/util.py b/mmgen/swap/util.py index a0fb5a40..c3282f85 100644 --- a/mmgen/swap/util.py +++ b/mmgen/swap/util.py @@ -19,6 +19,5 @@ def init_swap_proto(cfg, asset): 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 377db79b..c487b6fc 100644 --- a/mmgen/tx/base.py +++ b/mmgen/tx/base.py @@ -246,7 +246,7 @@ class Base(MMGenObject): async def check_swap_network(self): from ..protocol import init_proto from ..rpc import rpc_init - proto = init_proto(self.cfg, self.swap_proto_mod.coin, network=self.cfg.network) + proto = init_proto(self.cfg, self.swap_proto_mod.coin) rpc = await rpc_init(self.cfg, proto) data = rpc.inbound_addrs() for asset in (self.send_asset, self.recv_asset): diff --git a/mmgen/tx/completed.py b/mmgen/tx/completed.py index 484b66fb..80b7abcb 100644 --- a/mmgen/tx/completed.py +++ b/mmgen/tx/completed.py @@ -87,7 +87,6 @@ class Completed(Base): proto = init_proto( self.cfg, r.coin, - network = self.cfg.network, tokensym = r.tokensym, need_amt = True) if mmid := getattr(self, 'swap_recv_addr_mmid', None): diff --git a/mmgen/xmrwallet/ops/__init__.py b/mmgen/xmrwallet/ops/__init__.py index 42923ba4..d3e4b9c8 100644 --- a/mmgen/xmrwallet/ops/__init__.py +++ b/mmgen/xmrwallet/ops/__init__.py @@ -62,7 +62,7 @@ class OpBase: hdr_addr_width = 95 if self.cfg.full_address else short_addr_width - self.proto = init_proto(cfg, 'xmr', network=self.cfg.network, need_amt=True) + self.proto = init_proto(cfg, 'xmr', need_amt=True) id_cur = None for cls in classes: diff --git a/test/gentest.py b/test/gentest.py index cf7413b4..732815f1 100755 --- a/test/gentest.py +++ b/test/gentest.py @@ -476,12 +476,12 @@ def dump_test(proto, kg, ag, filename): def get_protos(proto, addr_type, toolname): - init_genonly_altcoins(testnet=proto.testnet) + init_genonly_altcoins(network=proto.network) for coin in cinfo.external_tests[proto.network][toolname]: if coin.lower() not in CoinProtocol.coins: continue - ret = init_proto(cfg, coin, testnet=proto.testnet) + ret = init_proto(cfg, coin, network=proto.network) if addr_type not in ret.mmtypes: continue yield ret