-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.py
executable file
·176 lines (142 loc) · 6.29 KB
/
init.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env python3
import json
import os
import pathlib
import shutil
import subprocess
import argparse
def check_if_already_initialized():
if os.path.isdir(NUCLEUS_SYSROOT):
answer = input(NUCLEUS_SYSROOT + " already exists.\n" +
"Type 'yes' if you want to remove it and create fresh configurations: ")
if answer.lower() == "yes":
shutil.rmtree(NUCLEUS_SYSROOT)
else:
print("Aborting!")
quit()
def init_genesis():
subprocess.run([NUCLEUS_BIN, "init", MONIKER,
"--chain-id="+CHAIN_ID, "--home="+NUCLEUS_SYSROOT])
subprocess.run([NUCLEUS_BIN, "config", "chain-id",
CHAIN_ID, "--home="+NUCLEUS_SYSROOT])
subprocess.run([NUCLEUS_BIN, "config", "keyring-backend",
"test", "--home="+NUCLEUS_SYSROOT])
process_1 = subprocess.Popen(
["echo", PAIR1_MNEMONIC], stdout=subprocess.PIPE)
process_2 = subprocess.Popen([NUCLEUS_BIN, "keys", "add", PAIR1, "--keyring-backend=test",
"--recover", "--home="+NUCLEUS_SYSROOT], stdin=process_1.stdout)
process_2.communicate()
process_1 = subprocess.Popen(
["echo", PAIR2_MNEMONIC], stdout=subprocess.PIPE)
process_2 = subprocess.Popen([NUCLEUS_BIN, "keys", "add", PAIR2, "--keyring-backend=test",
"--recover", "--home="+NUCLEUS_SYSROOT], stdin=process_1.stdout)
process_2.communicate()
process_1 = subprocess.run([NUCLEUS_BIN, "keys", "show", "-a", PAIR1, "--keyring-backend=test",
"--home="+NUCLEUS_SYSROOT], capture_output=True, text=True, encoding="utf-8")
subprocess.run([NUCLEUS_BIN, "add-genesis-account", process_1.stdout.strip(),
"10000000000unucl", "--home="+NUCLEUS_SYSROOT])
process_1 = subprocess.run([NUCLEUS_BIN, "keys", "show", "-a", PAIR2, "--keyring-backend=test",
"--home="+NUCLEUS_SYSROOT], capture_output=True, text=True, encoding="utf-8")
subprocess.run([NUCLEUS_BIN, "add-genesis-account", process_1.stdout.strip(),
"10000000000unucl", "--home="+NUCLEUS_SYSROOT])
subprocess.run([NUCLEUS_BIN, "add-genesis-account", DEV_ADDRESS,
"10000000000unucl", "--home="+NUCLEUS_SYSROOT])
subprocess.run([NUCLEUS_BIN,
"gentx",
PAIR1,
"200000000unucl",
"--chain-id="+CHAIN_ID,
"--moniker="+MONIKER,
"--commission-max-change-rate=0.01",
"--commission-max-rate=0.20",
"--commission-rate=0.05",
"--fees=2500unucl",
"--from="+PAIR1,
"--keyring-backend=test",
"--home="+NUCLEUS_SYSROOT])
subprocess.run([NUCLEUS_BIN, "collect-gentxs", "--home="+NUCLEUS_SYSROOT])
with open(NUCLEUS_SYSROOT + "/config/genesis.json") as r:
text = r.read().replace("stake", "unucl")
with open(NUCLEUS_SYSROOT + "/config/genesis.json", "w") as w:
w.write(text)
def update_app_toml():
os.remove(NUCLEUS_SYSROOT + "/config/app.toml")
shutil.copyfile("app.toml", NUCLEUS_SYSROOT + "/config/app.toml")
def update_rpc_host():
with open(NUCLEUS_SYSROOT + "/config/config.toml") as r:
text = r.read().replace("127.0.0.1:26657", "0.0.0.0:26657")
with open(NUCLEUS_SYSROOT + "/config/config.toml", "w") as w:
w.write(text)
def add_denom_metadata(data):
denom_metadata = [{
"description": "The native staking token of Nucleus.",
"denom_units": [
{
"denom": "unucl",
"exponent": 0,
"aliases": [
"micronucl"
]
},
{
"denom": "mnucl",
"exponent": 3,
"aliases": [
"millinucl"
]
},
{
"denom": "nucl",
"exponent": 6,
"aliases": []
}
],
"base": "unucl",
"display": "nucl",
"name": "",
"symbol": "",
"uri": "",
"uri_hash": ""
}]
data["app_state"]["bank"]["denom_metadata"] = denom_metadata
def add_htlc_genesis_config(data):
htlc_genesis_config = {
"params": {
"asset_params": []
},
"htlcs": [],
"supplies": [],
"previous_block_time": "1970-01-01T00:00:01Z"
}
data["app_state"]["htlc"] = htlc_genesis_config
if __name__ == "__main__":
CHAIN_ID = "nucleus-1"
PAIR1 = "alice"
PAIR2 = "bob"
MONIKER = "nimda"
DEV_ADDRESS = "nuc1llp0f6qxemgh4g4m5ewk0ew0hxj76avukahzwu"
PAIR1_MNEMONIC = "explain chalk inch snake snack fade news bus horn grant stereo surface panic sister absurd lens speed never inhale element junk senior bubble return"
# PAIR1_ADDRESS="nuc15d4sf4z6y0vk9dnum8yzkvr9c3wq4q89hzvgjk"
PAIR2_MNEMONIC = "young twist cube soldier sorry false dry actor assault roast mosquito brain fix seat wrong sauce impact smoke expect donkey hard decline polar dinosaur"
# PAIR2_ADDRESS="nuc1yfygf0zr5s69ces9r0h72hqv23nkqz9nej732n"
parser = argparse.ArgumentParser(description="Download API module file for specified version and platform.")
# Optional arguments
parser.add_argument("-b", "--bin", help="path to nucleusd binary", default="nucleusd")
parser.add_argument("-c", "--config", help="path to nucleusd configs", default=str(pathlib.Path.home().joinpath(".nucleus")))
parser.add_argument("--overwrite", help="overwrites existing configs", action="store_true")
args = parser.parse_args()
NUCLEUS_BIN = args.bin
NUCLEUS_SYSROOT = args.config
# TODO: Add argparse support for custom chain id, moniker, mnemonic, dev address
if not args.overwrite:
check_if_already_initialized()
init_genesis()
update_app_toml()
update_rpc_host()
with open(NUCLEUS_SYSROOT + "/config/genesis.json", "r+") as genesis_file:
data = json.load(genesis_file)
add_denom_metadata(data)
add_htlc_genesis_config(data)
genesis_file.seek(0)
json.dump(data, genesis_file, indent=2)
print("\nConfigurations files generated under " + NUCLEUS_SYSROOT)