-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
80 lines (67 loc) · 2.39 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from parsers.erc20bridge import ERC20BridgeConfig
from parsers.catbridge import CATBridgeConfig
from dataclasses import dataclass, field
from typing import List, Optional
import json
import enum
import sys
import os
class NetworkType(enum.Enum):
CHIA = "chia"
EVM = "evm"
@dataclass
class Network:
id: str
type: NetworkType
rpc_url: str
min_height: int
# Chia
message_toll: Optional[int] = None
portal_launcher_id: Optional[str] = None
bridging_puzzle_hash: Optional[str] = None
# EVM
max_block_range: Optional[int] = None
portal_address: Optional[str] = None
@dataclass
class Config:
networks: List[Network] = field(default_factory=list)
parsers: List[ERC20BridgeConfig | CATBridgeConfig] = field(default_factory=list)
@staticmethod
def load() -> 'Config':
try:
json_data = json.loads(
open("config.json", "r").read()
)
except:
print("Could not load config from config.json")
sys.exit(1)
config = Config()
for par in json_data.get('parsers', []):
type = par['type']
if type == 'erc20bridge':
config.parsers.append(ERC20BridgeConfig.from_dict(par))
elif type == 'catbridge':
config.parsers.append(CATBridgeConfig.from_dict(par))
else:
print(f"Unknown parser type '{type}'")
sys.exit(1)
for net in json_data.get('networks', []):
network_id: str = net['id']
rpc_url_env_variable = f"{network_id.upper()}_RPC_URL"
rpc_url = os.environ.get(rpc_url_env_variable)
if rpc_url is None:
print(f"Could not load RPC URL for '{network_id}' from environment variable {rpc_url_env_variable}")
sys.exit(1)
network = Network(
id=net['id'],
type=NetworkType(net['type']),
rpc_url=rpc_url,
min_height=net['min_height'],
message_toll=net.get('message_toll'),
portal_launcher_id=net.get('portal_launcher_id'),
bridging_puzzle_hash=net.get('bridging_puzzle_hash'),
max_block_range=net.get('max_block_range'),
portal_address=net.get('portal_address')
)
config.networks.append(network)
return config