From dfc732ac5deb536583fde4a9c038c794de83aee4 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 1 Aug 2021 20:54:50 +0000 Subject: [PATCH] CoinDaemon: support multiple daemons per coin - specify the daemon via the --daemon-id option --- mmgen/daemon.py | 7 ++++++- mmgen/globalvars.py | 3 ++- mmgen/opts.py | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mmgen/daemon.py b/mmgen/daemon.py index 9f443103..ec0c66aa 100755 --- a/mmgen/daemon.py +++ b/mmgen/daemon.py @@ -345,7 +345,12 @@ class CoinDaemon(Daemon): coin,network = CoinProtocol.Base.parse_network_id(network_id) coin = coin.upper() - daemon_id = cls.coins[coin].daemon_ids[0] + daemon_ids = cls.coins[coin].daemon_ids + daemon_id = g.daemon_id or daemon_ids[0] + + if daemon_id not in daemon_ids: + die(1,f'{daemon_id!r}: invalid daemon_id - valid choices: {fmt_list(daemon_ids)}') + me = Daemon.__new__(globals()[daemon_id + '_daemon']) assert network in me.networks, f'{network!r}: unsupported network for daemon {daemon_id}' me.network = network diff --git a/mmgen/globalvars.py b/mmgen/globalvars.py index ac87bbfe..2c739973 100755 --- a/mmgen/globalvars.py +++ b/mmgen/globalvars.py @@ -151,6 +151,7 @@ class GlobalContext(Lockable): ) data_dir_root,data_dir,cfg_file = None,None,None daemon_data_dir = '' # set by user + daemon_id = '' # global var sets user opt: global_sets_opt = ( @@ -166,7 +167,7 @@ class GlobalContext(Lockable): 'rpc_host','rpc_port','rpc_user','rpc_password','rpc_backend','aiohttp_rpc_queue_len', 'monero_wallet_rpc_host','monero_wallet_rpc_user','monero_wallet_rpc_password', 'daemon_data_dir','force_256_color','regtest','coin','bob','alice', - 'accept_defaults','token','ignore_daemon_version' + 'accept_defaults','token','ignore_daemon_version','daemon_id' ) # opts initialized to None by opts.init() if not set by user required_opts = ( diff --git a/mmgen/opts.py b/mmgen/opts.py index 33db7d4e..ef9da5b8 100755 --- a/mmgen/opts.py +++ b/mmgen/opts.py @@ -188,6 +188,7 @@ common_opts_data = { --, --force-256-color Force 256-color output when color is enabled --, --data-dir=path Specify {pnm} data directory location --, --daemon-data-dir=path Specify {dn} data directory location +--, --daemon-id=ID Specify the coin daemon ID --, --ignore-daemon-version Ignore {dn} version check --, --no-license Suppress the GPL license prompt --, --rpc-host=host Communicate with {dn} running on host 'host'