refactor: Introduce get_chain_conf_names

This commit is contained in:
UdjinM6 2024-11-01 15:25:14 +03:00
parent 519966efff
commit efc8c99139
No known key found for this signature in database
GPG Key ID: 83592BD1400D58D9
2 changed files with 21 additions and 26 deletions

View File

@ -48,6 +48,7 @@ from .util import (
check_json_precision, check_json_precision,
copy_datadir, copy_datadir,
force_finish_mnsync, force_finish_mnsync,
get_chain_conf_names,
get_datadir_path, get_datadir_path,
initialize_datadir, initialize_datadir,
p2p_port, p2p_port,
@ -610,19 +611,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
if entry not in ['chainstate', 'blocks', 'indexes', 'evodb']: if entry not in ['chainstate', 'blocks', 'indexes', 'evodb']:
os.remove(os.path.join(new_data_dir, self.chain, entry)) os.remove(os.path.join(new_data_dir, self.chain, entry))
# Translate chain name to config name (chain_name_conf_arg, chain_name_conf_arg_value, chain_name_conf_section) = get_chain_conf_names(self.chain)
if self.chain == 'testnet3':
chain_name_conf_arg = 'testnet'
chain_name_conf_section = 'test'
chain_name_conf_arg_value = '1'
elif self.chain == 'devnet':
chain_name_conf_arg = 'devnet'
chain_name_conf_section = 'devnet'
chain_name_conf_arg_value = 'devnet1'
else:
chain_name_conf_arg = self.chain
chain_name_conf_section = self.chain
chain_name_conf_arg_value = '1'
with open(os.path.join(new_data_dir, "dash.conf"), 'w', encoding='utf8') as f: with open(os.path.join(new_data_dir, "dash.conf"), 'w', encoding='utf8') as f:
f.write("{}={}\n".format(chain_name_conf_arg, chain_name_conf_arg_value)) f.write("{}={}\n".format(chain_name_conf_arg, chain_name_conf_arg_value))

View File

@ -381,19 +381,7 @@ def initialize_datadir(dirname, n, chain):
def write_config(config_path, *, n, chain, extra_config=""): def write_config(config_path, *, n, chain, extra_config=""):
# Translate chain subdirectory name to config name (chain_name_conf_arg, chain_name_conf_arg_value, chain_name_conf_section) = get_chain_conf_names(chain)
if chain == 'testnet3':
chain_name_conf_arg = 'testnet'
chain_name_conf_section = 'test'
chain_name_conf_arg_value = '1'
elif chain == 'devnet':
chain_name_conf_arg = 'devnet'
chain_name_conf_section = 'devnet'
chain_name_conf_arg_value = 'devnet1'
else:
chain_name_conf_arg = chain
chain_name_conf_section = chain
chain_name_conf_arg_value = '1'
with open(config_path, 'w', encoding='utf8') as f: with open(config_path, 'w', encoding='utf8') as f:
if chain_name_conf_arg: if chain_name_conf_arg:
f.write("{}={}\n".format(chain_name_conf_arg, chain_name_conf_arg_value)) f.write("{}={}\n".format(chain_name_conf_arg, chain_name_conf_arg_value))
@ -494,6 +482,24 @@ def get_chain_folder(datadir, chain):
pass pass
return chain return chain
def get_chain_conf_names(chain):
"""
Translate chain name to config names
"""
if chain == 'testnet3':
arg = 'testnet'
value = '1'
section = 'test'
elif chain == 'devnet':
arg = 'devnet'
value = 'devnet1'
section = 'devnet'
else:
arg = chain
value = '1'
section = chain
return (arg, value, section)
def get_bip9_details(node, key): def get_bip9_details(node, key):
"""Return extra info about bip9 softfork""" """Return extra info about bip9 softfork"""
return node.getblockchaininfo()['softforks'][key]['bip9'] return node.getblockchaininfo()['softforks'][key]['bip9']