From 70810aff695caefd146af438e31f4af340ec317b Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 7 Jun 2025 10:38:09 +0300 Subject: [PATCH] CoinProtocol.base: new `rpc_type` attribute --- mmgen/proto/rune/params.py | 3 ++- mmgen/protocol.py | 1 + mmgen/rpc/__init__.py | 52 ++++++++++++++++++-------------------- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/mmgen/proto/rune/params.py b/mmgen/proto/rune/params.py index 41d7cdbb..6abcb9c9 100755 --- a/mmgen/proto/rune/params.py +++ b/mmgen/proto/rune/params.py @@ -28,12 +28,13 @@ class mainnet(CoinProtocol.Secp256k1): coin_amt = 'UniAmt' max_tx_fee = 1 # TODO caps = () - mmcaps = ('tw', 'rpc_init', 'rpc_remote') + mmcaps = ('tw', 'rpc', 'rpc_init') base_proto = 'THORChain' base_proto_coin = 'RUNE' base_coin = 'RUNE' bech32_hrp = 'thor' sign_mode = 'standalone' + rpc_type = 'remote' avg_bdi = 6 # TODO address_reuse_ok = False diff --git a/mmgen/protocol.py b/mmgen/protocol.py index ae574bf2..e76d4c8f 100755 --- a/mmgen/protocol.py +++ b/mmgen/protocol.py @@ -57,6 +57,7 @@ class CoinProtocol(MMGenObject): is_fork_of = None chain_names = None is_evm = False + rpc_type = 'local' networks = ('mainnet', 'testnet', 'regtest') decimal_prec = 28 _set_ok = ('tokensym',) diff --git a/mmgen/rpc/__init__.py b/mmgen/rpc/__init__.py index c3bba3dc..ec6dfa32 100755 --- a/mmgen/rpc/__init__.py +++ b/mmgen/rpc/__init__.py @@ -31,38 +31,34 @@ async def rpc_init( if not 'rpc_init' in proto.mmcaps: die(1, f'rpc_init() not supported for {proto.name} protocol!') - mod, clsname = ( - ('local', 'RPCClient') if 'rpc' in proto.mmcaps else - ('remote', 'RemoteRPCClient') if 'rpc_remote' in proto.mmcaps else - (None, None)) + if proto.rpc_type == 'remote': + return getattr(importlib.import_module( + f'mmgen.proto.{proto.base_proto_coin.lower()}.rpc.remote'), + proto.base_proto + 'RemoteRPCClient')(cfg=cfg, proto=proto) - cls = getattr( - importlib.import_module(f'mmgen.proto.{proto.base_proto_coin.lower()}.rpc.{mod}'), - proto.base_proto + clsname) + from ..daemon import CoinDaemon - if mod == 'local': - from ..daemon import CoinDaemon - rpc = await cls( - cfg = cfg, - proto = proto, - daemon = daemon or CoinDaemon(cfg, proto=proto, test_suite=cfg.test_suite), - backend = backend or cfg.rpc_backend, - ignore_wallet = ignore_wallet) + rpc = await getattr(importlib.import_module( + f'mmgen.proto.{proto.base_proto_coin.lower()}.rpc.local'), + proto.base_proto + 'RPCClient')( + cfg = cfg, + proto = proto, + daemon = daemon or CoinDaemon(cfg, proto=proto, test_suite=cfg.test_suite), + backend = backend or cfg.rpc_backend, + ignore_wallet = ignore_wallet) - if rpc.daemon_version > rpc.daemon.coind_version: - rpc.handle_unsupported_daemon_version( - proto.name, - ignore_daemon_version or proto.ignore_daemon_version or cfg.ignore_daemon_version) + if rpc.daemon_version > rpc.daemon.coind_version: + rpc.handle_unsupported_daemon_version( + proto.name, + ignore_daemon_version or proto.ignore_daemon_version or cfg.ignore_daemon_version) - if rpc.chain not in proto.chain_names: - die('RPCChainMismatch', '\n' + fmt(f""" - Protocol: {proto.cls_name} - Valid chain names: {fmt_list(proto.chain_names, fmt='bare')} - RPC client chain: {rpc.chain} - """, indent=' ').rstrip()) + if rpc.chain not in proto.chain_names: + die('RPCChainMismatch', '\n' + fmt(f""" + Protocol: {proto.cls_name} + Valid chain names: {fmt_list(proto.chain_names, fmt='bare')} + RPC client chain: {rpc.chain} + """, indent=' ').rstrip()) - rpc.blockcount = NonNegativeInt(rpc.blockcount) - else: - rpc = cls(cfg=cfg, proto=proto) + rpc.blockcount = NonNegativeInt(rpc.blockcount) return rpc