github.com/haliliceylan/bsc@v1.1.10-0.20220501224556-eb78d644ebcb/tests/truffle/scripts/bootstrap.sh (about) 1 #!/usr/bin/env bash 2 3 workspace=$(cd `dirname $0`; pwd)/.. 4 5 function prepare() { 6 if ! [[ -f /usr/local/bin/geth ]];then 7 echo "geth do not exist!" 8 exit 1 9 fi 10 rm -rf ${workspace}/storage/* 11 cd ${workspace}/genesis 12 rm -rf validators.conf 13 } 14 15 function init_validator() { 16 node_id=$1 17 mkdir -p ${workspace}/storage/${node_id} 18 geth --datadir ${workspace}/storage/${node_id} account new --password /dev/null > ${workspace}/storage/${node_id}Info 19 validatorAddr=`cat ${workspace}/storage/${node_id}Info|grep 'Public address of the key'|awk '{print $6}'` 20 echo "${validatorAddr},${validatorAddr},${validatorAddr},0x0000000010000000" >> ${workspace}/genesis/validators.conf 21 echo ${validatorAddr} > ${workspace}/storage/${node_id}/address 22 } 23 24 function generate_genesis() { 25 INIT_HOLDER_ADDRESSES=$(ls ${workspace}/init-holders | tr '\n' ',') 26 INIT_HOLDER_ADDRESSES=${INIT_HOLDER_ADDRESSES/%,/} 27 sed "s/{{INIT_HOLDER_ADDRESSES}}/${INIT_HOLDER_ADDRESSES}/g" ${workspace}/genesis/init_holders.template | sed "s/{{INIT_HOLDER_BALANCE}}/${INIT_HOLDER_BALANCE}/g" > ${workspace}/genesis/init_holders.js 28 node generate-validator.js 29 chainIDHex=$(printf '%04x\n' ${BSC_CHAIN_ID}) 30 node generate-genesis.js --chainid ${BSC_CHAIN_ID} --bscChainId ${chainIDHex} 31 } 32 33 function init_genesis_data() { 34 node_type=$1 35 node_id=$2 36 geth --datadir ${workspace}/storage/${node_id} init ${workspace}/genesis/genesis.json 37 cp ${workspace}/config/config-${node_type}.toml ${workspace}/storage/${node_id}/config.toml 38 sed -i -e "s/{{NetworkId}}/${BSC_CHAIN_ID}/g" ${workspace}/storage/${node_id}/config.toml 39 if [ "${node_id}" == "bsc-rpc" ]; then 40 cp ${workspace}/init-holders/* ${workspace}/storage/${node_id}/keystore 41 cp ${workspace}/genesis/genesis.json ${workspace}/storage/${node_id} 42 fi 43 } 44 45 prepare 46 47 # First, generate config for each validator 48 for((i=1;i<=${NUMS_OF_VALIDATOR};i++)); do 49 init_validator "bsc-validator${i}" 50 done 51 52 # Then, use validator configs to generate genesis file 53 generate_genesis 54 55 # Finally, use genesis file to init cluster data 56 init_genesis_data bsc-rpc bsc-rpc 57 58 for((i=1;i<=${NUMS_OF_VALIDATOR};i++)); do 59 init_genesis_data validator "bsc-validator${i}" 60 done