forked from Alex014/NessNodeTester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigen.py
97 lines (78 loc) · 2.78 KB
/
configen.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
import json
import os
import sys
import urllib.parse
from Crypto.Random import get_random_bytes
print('Configen')
print('Generates node config from previously generated node by Codegen')
class Configen:
def loadNode(node_url: str):
filename = urllib.parse.quote_plus(node_url) + ".key.json"
f = open("out/keys/node/" + filename, "r")
return json.loads(f.read())
def saveNode(node_url: str):
node = Configen.loadNode(node_url)
config_node = {
"nonce": node["nonce"],
"private": node["private"],
"public": node["public"],
"url": node["url"],
"tariff": node["tariff"],
"verify": node["verify"],
"master-user": node["master-user"],
"period" : "7200",
"delta" : "1200",
"slots" : "10",
}
filename = "out/config/node.json"
f = open(filename, "w")
f.write(json.dumps(config_node, indent=4, sort_keys=True))
config_emer = {
"host": "localhost",
"port": 8332,
"user": "user",
"password": "password"
}
filename = "out/config/emer.json"
f = open(filename, "w")
f.write(json.dumps(config_emer, indent=4, sort_keys=True))
config_ness = {
"host": "localhost",
"port": 6420,
"wallet_id": "wallet.wlt",
"password": "password"
}
filename = "out/config/ness.json"
f = open(filename, "w")
f.write(json.dumps(config_ness, indent=4, sort_keys=True))
config_prng = {
"seed": "/tmp/seed.txt",
"seed-big": "/tmp/seed-big.txt",
"numbers": "/tmp/numbers.json",
"numbers-big": "/tmp/numbers-big.json",
"numbers-i256": "/tmp/i256.json",
"numbers-h256": "/tmp/h256.json"
}
filename = "out/config/prng.json"
f = open(filename, "w")
f.write(json.dumps(config_prng, indent=4, sort_keys=True))
users_addresses = {}
filename = "out/config/users_addr.json"
f = open(filename, "w")
f.write(json.dumps(users_addresses, indent=4, sort_keys=True))
os.chmod(filename, 0o666)
config_files = {
"dir": "storage",
"quota": "100MB",
"salt": b64encode(get_random_bytes(16)).decode('utf-8'),
}
filename = "out/config/files.json"
f = open(filename, "w")
f.write(json.dumps(config_files, indent=4, sort_keys=True))
if len(sys.argv) == 2:
node_url = sys.argv[1]
Configen.saveNode(node_url)
print('Config generated !')
print('Move all generated *.json files from "out/config/*.json" to ~/.ness/*.json')
else:
print('Usage: python configen.py <node URL>')