2024-08-22 02:47:16 +03:00
|
|
|
from network import Network
|
|
|
|
from sequencer import Sequencer
|
|
|
|
import toml
|
|
|
|
|
|
|
|
|
|
|
|
def read_config(config_path: str) -> tuple[dict[str, Sequencer], str]:
|
|
|
|
config = toml.load(config_path)
|
|
|
|
|
|
|
|
cert_path = config.get('cert_path', "")
|
2024-08-23 00:08:06 +03:00
|
|
|
# if cert path is relative, pre-pend the config path
|
|
|
|
if not cert_path.startswith('/'):
|
|
|
|
cert_path = f"{config_path.rsplit('/', 1)[0]}/{cert_path}"
|
2024-08-22 02:47:16 +03:00
|
|
|
|
|
|
|
# load sequencers into a map
|
|
|
|
sequencers = {}
|
|
|
|
for name, seq_config in config['sequencers'].items():
|
|
|
|
sequencers[name] = Sequencer(
|
|
|
|
sequencer_id=name,
|
|
|
|
raft_addr=seq_config['raft_addr'],
|
|
|
|
conductor_rpc_url=seq_config['conductor_rpc_url'],
|
|
|
|
node_rpc_url=seq_config['node_rpc_url'],
|
|
|
|
voting=seq_config['voting']
|
|
|
|
)
|
|
|
|
|
|
|
|
# Initialize network, with list of sequencers
|
|
|
|
networks = {}
|
|
|
|
for network_name, network_config in config['networks'].items():
|
|
|
|
network_sequencers = [sequencers[seq_name]
|
|
|
|
for seq_name in network_config['sequencers']]
|
|
|
|
networks[network_name] = Network(network_name, network_sequencers)
|
|
|
|
|
|
|
|
return networks, cert_path
|