forked from bnb-chain/bsc-genesis-contract
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidators.js
57 lines (51 loc) · 1.59 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
54
55
56
57
const web3 = require("web3")
const RLP = require('rlp');
// Configure
const validators = [
{
consensusAddr: "0x9fB29AAc15b9A4B7F17c3385939b007540f4d791",
feeAddr: "0x9fB29AAc15b9A4B7F17c3385939b007540f4d791",
bscFeeAddr: "0x9fB29AAc15b9A4B7F17c3385939b007540f4d791",
votingPower: 0x0000000000000064
}
];
const bLSPublicKeys = [
"0x85e6972fc98cd3c81d64d40e325acfed44365b97a7567a27939c14dbc7512ddcf54cb1284eb637cfa308ae4e00cb5588",
];
// =============== 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, bLSPublicKeys) {
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,
bLSPublicKeys[i]
]);
}
let pkg = [0x00, vals];
return web3.utils.bytesToHex(RLP.encode(pkg));
}
extraValidatorBytes = generateExtradata(validators);
validatorSetBytes = validatorUpdateRlpEncode(validators, bLSPublicKeys);
exports = module.exports = {
extraValidatorBytes: extraValidatorBytes,
validatorSetBytes: validatorSetBytes,
}