-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal_config.py
63 lines (57 loc) · 1.58 KB
/
global_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
import base64
from config import *
GLOBAL_CONFIG_TEMPLATE = """
{
"@type": "config.global",
"dht": {
"@type": "dht.config.global",
"k": 3,
"a": 3,
"static_nodes": {
"@type": "dht.nodes",
"nodes": []
}
},
"validator": {
"@type": "validator.config.global",
"zero_state": {
"workchain": -1,
"shard": -9223372036854775808,
"seqno": 0,
"root_hash": "",
"file_hash": ""
},
"init_block": {
"workchain": -1,
"shard": -9223372036854775808,
"seqno": 0,
"root_hash": "",
"file_hash": ""
}
}
}
"""
GLOBAL_CONFIG_FILENAME = "my.global.config.json"
def init(zerostate_rhash_hex: str, zerostate_fhash_hex: str):
cfg = json.loads(GLOBAL_CONFIG_TEMPLATE)
block_id = cfg["validator"]["zero_state"]
block_id["root_hash"] = str(base64.b64encode(bytes.fromhex(zerostate_rhash_hex)), "utf-8")
block_id["file_hash"] = str(base64.b64encode(bytes.fromhex(zerostate_fhash_hex)), "utf-8")
cfg["validator"]["init_block"] = block_id
with open(GLOBAL_CONFIG_FILENAME, "w") as f:
print(json.dumps(cfg, indent=2), file=f)
def add_liteserver(key_base64: str):
with open(GLOBAL_CONFIG_FILENAME, "r") as f:
cfg = json.loads(f.read())
cfg["liteservers"] = [
{
"id": {
"@type": "pub.ed25519",
"key": key_base64
},
"ip": 2130706433, # 127.0.0.1
"port": str(LITESERVER_PORT)
}
]
with open(GLOBAL_CONFIG_FILENAME, "w") as f:
print(json.dumps(cfg, indent=2), file=f)