Skip to content

Commit be50b49

Browse files
committed
add xdpos gen
1 parent c8f6b5f commit be50b49

File tree

14 files changed

+958
-9
lines changed

14 files changed

+958
-9
lines changed

container-manager/src/express.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ app.get("/gen", (req, res) => {
119119
res.render("generator/index.pug", {});
120120
});
121121

122+
app.get("/gen_xdpos", (req, res) => {
123+
res.render("xdpos_generator/index.pug", {});
124+
});
125+
122126
app.post("/submit", (req, res) => {
123127
console.log("/submit called");
124128
const [valid, genOut] = exec.generate(req.body);
@@ -136,6 +140,23 @@ app.post("/submit", (req, res) => {
136140
}
137141
});
138142

143+
app.post("/submit_xdpos", (req, res) => {
144+
console.log("/submit_xdpos called");
145+
const [valid, genOut] = exec.generateXdpos(req.body);
146+
if (!valid) {
147+
res.render("xdpos_generator/submit.pug", {
148+
message: "failed, please try again",
149+
error: genOut,
150+
});
151+
} else {
152+
res.render("xdpos_generator/submit.pug", {
153+
message:
154+
"Config generation success, please continue with 'cd generated;' then './docker-up.sh machine1;'",
155+
});
156+
process.exit(0);
157+
}
158+
});
159+
139160
app.post("/submit_preconfig", (req, res) => {
140161
console.log("/submit called");
141162
const [valid, genOut] = exec.generate(req.body);

container-manager/src/gen/config_gen.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ const config = {
5454
generator: {
5555
output_path: `${__dirname}/../../mount/generated/`,
5656
},
57+
xdpos: {
58+
xdposnode: process.env.VERSION_NODE || "v2.6.4-beta",
59+
stake_threshold: parseInt(process.env.MASTERNODE_MINIMUM_STAKE) || "",
60+
reward_yield: parseInt(process.env.REWARDS_YIELD) || "",
61+
foundation_address: process.env.FOUNDATION_ADDRESS || ""
62+
}
5763
};
5864

5965
// if (configSanityCheck(config) === true) {

container-manager/src/gen/gen_compose.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,25 @@ module.exports = {
1212
genExplorer,
1313
};
1414

15-
function genSubnetNodes(machine_id, num, start_num = 1) {
15+
function genSubnetNodes(machine_id, num, start_num = 1, isXdpos = false) {
1616
let subnet_nodes = {};
1717
for (let i = start_num; i < start_num + num; i++) {
1818
const node_name = "subnet" + i.toString();
1919
const volume = "${HOSTPWD}/xdcchain" + i.toString() + ":/work/xdcchain";
20-
const config_path = "subnet" + i.toString() + ".env";
2120
const compose_profile = "machine" + machine_id.toString();
2221
const port = 20302 + i;
2322
const rpcport = 8544 + i;
2423
const wsport = 9554 + i;
24+
25+
imageName = `xinfinorg/xdcsubnets:${config.version.subnet}`;
26+
config_path = "subnet" + i.toString() + ".env";
27+
if (isXdpos) {
28+
imageName = `xinfinorg/xdposchain:${config.xdpos.xdposnode}`;
29+
config_path = "masternode" + i.toString() + ".env";
30+
}
31+
2532
subnet_nodes[node_name] = {
26-
image: `xinfinorg/xdcsubnets:${config.version.subnet}`,
33+
image: imageName,
2734
volumes: [volume, "${HOSTPWD}/genesis.json:/work/genesis.json"],
2835
restart: "always",
2936
network_mode: "host",

container-manager/src/gen/gen_other.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,40 @@ Object.freeze(config);
44

55
module.exports = {
66
genSubnetKeys,
7+
genXdposKeys,
78
genDeploymentJson,
89
genCommands,
910
genGenesisInputFile,
1011
};
12+
function genXdposKeys() {
13+
const keys = {};
14+
console.log("genXdposKeys called");
15+
console.log(config.keys)
16+
// const num = config.keys.subnets_addr.length
17+
for (let i = 0; i < config.keys.subnets_addr.length; i++) {
18+
const key = `key${i + 1}`;
19+
const private_key = config.keys.subnets_pk[i];
20+
const address = config.keys.subnets_addr[i];
21+
keys[key] = {
22+
PrivateKey: private_key,
23+
"0x": address,
24+
short: address.replace(/^0x/i, ""),
25+
};
26+
}
27+
keys["Owner"] = {
28+
PrivateKey: config.keys.grandmaster_pk,
29+
"0x": config.keys.grandmaster_addr,
30+
short: config.keys.grandmaster_addr.replace(/^0x/i, ""),
31+
};
32+
if (Object.keys(keys).length !== config.num_subnet + 1) {
33+
// sanity check
34+
console.log("bad case, key length not equal number of subnets");
35+
console.log(Object.keys(keys).length, config.num_subnet + 1);
36+
console.log(keys);
37+
process.exit();
38+
}
39+
return keys;
40+
}
1141

1242
function genSubnetKeys() {
1343
const keys = {};

0 commit comments

Comments
 (0)