-
Notifications
You must be signed in to change notification settings - Fork 0
/
convertConfig.js
128 lines (108 loc) · 2.69 KB
/
convertConfig.js
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
const fs = require('fs');
var config = JSON.parse(fs.readFileSync('networkNodesInfo.json', 'utf8'));
var nettingConfig = [];
var truffleNetworks = {
"development": {
"nodeId": 0,
"host": "localhost",
"port": 8545,
"network_id": "*"
}
};
var stashNames = {
"01": "MASREGULATOR",
"02": "MASGSGSG",
"03": "BOFASG2X",
"04": "CHASSGSG",
"05": "CITISGSG",
"06": "CSFBSGSX",
"07": "DBSSSGSG",
"08": "HSBCSGSG",
"09": "MTBCSGSG",
"10": "OCBCSGSG",
"12": "SCBLSGSG",
"14": "UOBVSGSG",
"15": "XSIMSGSG"
};
var truffleNames = {
"01": "mas",
"02": "cb",
"03": "a",
"04": "b",
"05": "c",
"06": "d",
"07": "e",
"08": "f",
"09": "g",
"10": "h",
"12": "i",
"14": "j",
"15": "k"
};
var counter = 0;
Object.keys(config).forEach(enode => {
let nodeId = config[enode].nodeName.slice(2, 4);
let centralBank = false;
let regulator = false;
let stashName = stashNames[nodeId];
if (stashName === "MASGSGSG") centralBank = true;
if (stashName === "MASREGULATOR") regulator = true;
let nodeConfig = {
"nodeId": parseInt(nodeId),
"host": config[enode].ipAddress,
"port": "20010",
"accountNumber": 0,
"ethKey": config[enode].address,
"constKey": config[enode].constellationPublicKey,
"stashName": stashName,
"enode": enode,
"centralBank": centralBank,
"regulator": regulator,
"localport": 3000
};
nettingConfig.push(nodeConfig);
if (typeof stashName != 'undefined') {
let truffleName = truffleNames[nodeId];
let truffleNode = {
"nodeId": nodeConfig.nodeId,
"host": nodeConfig.host,
"port": parseInt(nodeConfig.port),
"network_id": "*"
};
if (regulator) {
truffleNode["gas"] = 200000000;
}
truffleNetworks[truffleName] = truffleNode;
}
counter++;
});
nettingConfig.sort((a, b) => {
return a.nodeId - b.nodeId;
});
function sortTruffle(o) {
return Object.keys(o).sort((a, b) => {
return o[a].nodeId - o[b].nodeId;
}).reduce((r, k) => (r[k] = o[k], r), {});
}
truffleNetworks = sortTruffle(truffleNetworks)
fs.writeFile('test-scripts/config/config.json', JSON.stringify(nettingConfig, null, " "),
err => {
if (err) console.log(err);
});
var testnet = {
"nodes": nettingConfig.map(i => i.constKey)
};
fs.writeFile('testnet.json', JSON.stringify(testnet, null, " "),
err => {
if (err) console.log(err);
});
fs.writeFile('server/config/network.json', JSON.stringify(nettingConfig, null, " "),
err => {
if (err) console.log(err);
});
fs.writeFile('truffle.js', 'module.exports = ' + JSON.stringify({
"networks": truffleNetworks
}, null, " ").replace(/\"([^"]+)\":/g, "$1:") + ';',
err => {
if (err) console.log(err);
});