-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_genesis.sh
58 lines (48 loc) · 2.04 KB
/
generate_genesis.sh
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
#!/usr/bin/env bash
basedir=$(cd `dirname $0`; pwd)
workspace=${basedir}
source ${workspace}/.env
keys_dir_name="keys"
authorities=("alice" "bob" "charlie" "dave" "eve") # predefined authorities
# Get the number of validators to create from command line argument, default to number of authorities
num_validators=${1:-${#authorities[@]}}
function get_init_holders() {
local result="${INIT_HOLDER}"
# concatenate consensus addresses
for ((i=0;i<${num_validators};i++));do
cd ${workspace}/${keys_dir_name}/${authorities[i]}
cons_addr="0x$(cat consensus/keystore/* | jq -r .address)"
# If result already has data, append a comma before adding more
if [[ -n $result ]]; then
result+=","
fi
result+="$cons_addr"
(( i++ ))
done
echo "$result"
}
# Check if the number of validators is greater than the number of authorities
if (( num_validators > ${#authorities[@]} )); then
echo "Error: The number of validators requested (${num_validators}) is greater than the number of authorities available (${#authorities[@]})."
exit 1
fi
rm -f ${workspace}/bsc-genesis-contract/validators.conf
for ((i=0;i<num_validators;i++));do
cd ${workspace}/${keys_dir_name}/${authorities[i]}
cons_addr="0x$(cat consensus/keystore/* | jq -r .address)"
fee_addr="0x$(cat fee/keystore/* | jq -r .address)"
vote_addr=0x$(cat bls/keystore/*json| jq .pubkey | sed 's/"//g')
cd ${workspace}
bbcfee_addrs=${fee_addr}
powers="0x000001d1a94a2000"
echo "${cons_addr},${bbcfee_addrs},${fee_addr},${powers},${vote_addr}" >> ${workspace}/bsc-genesis-contract/validators.conf
echo "validator" ${i} ":" ${cons_addr}
echo "validatorFee" ${i} ":" ${fee_addr}
echo "validatorVote" ${i} ":" ${vote_addr}
done
cd ${workspace}/bsc-genesis-contract/
node generate-validator.js
init_holders=$(get_init_holders)
echo "${init_holders}"
node generate-initHolders.js --initHolders ${init_holders}
node generate-genesis.js --chainid ${BSC_CHAIN_ID} --network 'local' --whitelist1Address ${INIT_HOLDER}