-
Notifications
You must be signed in to change notification settings - Fork 0
/
validators.template
54 lines (48 loc) · 1.4 KB
/
validators.template
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
const web3 = require("web3")
const RLP = require('rlp');
// Configure
const validators = [
{% for v in validators %}
{
"consensusAddr": "{{ v.consensusAddr }}",
"feeAddr": "{{ v.feeAddr }}",
"bscFeeAddr": "{{ v.bscFeeAddr }}",
"votingPower": {{ v.votingPower }},
},{% endfor %}
];
// =============== Do not edit below ====
function generateExtradata(validators) {
let extraVanity =Buffer.alloc(32);
let validatorsBytes = extraDataSerialize(validators);
let extraSeal =Buffer.alloc(65);
return Buffer.concat([extraVanity,validatorsBytes,extraSeal]);
}
function extraDataSerialize(validators) {
let n = validators.length;
let arr = [];
for (let i = 0;i<n;i++) {
let validator = validators[i];
arr.push(Buffer.from(web3.utils.hexToBytes(validator.consensusAddr)));
}
return Buffer.concat(arr);
}
function validatorUpdateRlpEncode(validators) {
let n = validators.length;
let vals = [];
for (let i = 0;i<n;i++) {
vals.push([
validators[i].consensusAddr,
validators[i].bscFeeAddr,
validators[i].feeAddr,
validators[i].votingPower,
]);
}
let pkg = [0x00, vals];
return web3.utils.bytesToHex(RLP.encode(pkg));
}
extraValidatorBytes = generateExtradata(validators);
validatorSetBytes = validatorUpdateRlpEncode(validators);
exports = module.exports = {
extraValidatorBytes: extraValidatorBytes,
validatorSetBytes: validatorSetBytes,
}