-
Notifications
You must be signed in to change notification settings - Fork 0
/
validators.js
53 lines (47 loc) · 1.41 KB
/
validators.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
const web3 = require("web3")
const RLP = require('rlp');
// Configure
const validators = [
{
consensusAddr: "0x9fB29AAc15b9A4B7F17c3385939b007540f4d791",
feeAddr: "0x9fB29AAc15b9A4B7F17c3385939b007540f4d791",
bscFeeAddr: "0x9fB29AAc15b9A4B7F17c3385939b007540f4d791",
votingPower: 0x0000000000000064
}
];
// =============== 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,
}