CoinDaemon: support multiple instances

This commit is contained in:
The MMGen Project 2021-05-09 11:56:48 +00:00
commit d94e514445
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
2 changed files with 14 additions and 6 deletions

View file

@ -423,7 +423,9 @@ class CoinDaemon(Daemon):
test_suite = False,
flags = None,
proto = None,
opts = None ):
opts = None,
port_shift = None,
datadir = None ):
assert network_id or proto, 'CoinDaemon_chk1'
assert not (network_id and proto), 'CoinDaemon_chk2'
@ -450,7 +452,9 @@ class CoinDaemon(Daemon):
test_suite = False,
flags = None,
proto = None,
opts = None ):
opts = None,
port_shift = None,
datadir = None ):
super().__init__()
@ -495,8 +499,8 @@ class CoinDaemon(Daemon):
if test_suite:
dfl_datadir = os.path.join(os.getcwd(),rel_datadir)
# user-set value takes precedence
datadir = g.daemon_data_dir or dfl_datadir
# user-set values take precedence
datadir = datadir or g.daemon_data_dir or dfl_datadir
self.datadir = os.path.abspath(datadir)
@ -505,7 +509,7 @@ class CoinDaemon(Daemon):
if self.datadir_is_subdir:
self.datadir = os.path.join(self.datadir,self.testnet_dir)
self.port_shift = 1237 if test_suite else 0
self.port_shift = (1237 if test_suite else 0) + (port_shift or 0)
self.rpc_port = {
'mainnet': self.dfl_rpc,
'testnet': self.dfl_rpc_tn,

View file

@ -16,7 +16,9 @@ opts_data = {
-h, --help Print this help message
--, --longhelp Print help message for long options (common options)
-D, --debug Produce debugging output (implies --verbose)
-d, --datadir= Override the default datadir
-n, --no-daemonize Don't fork daemon to background
-p, --port-shift= Shift the RPC port by this number
-s, --get-state Get the state of the daemon(s) and exit
-t, --testing Testing mode. Print commands but don't execute them
-v, --verbose Produce more verbose output
@ -58,7 +60,9 @@ for network_id in ids:
d = CoinDaemon(
network_id,
test_suite = True,
opts = ['no_daemonize'] if opt.no_daemonize else None )
opts = ['no_daemonize'] if opt.no_daemonize else None,
port_shift = int(opt.port_shift or 0),
datadir = opt.datadir )
d.debug = opt.debug
d.wait = not opt.no_wait
if opt.get_state: