Add a script to generate stage1 genesis file from a JSON file
This commit is contained in:
parent
f27ff06e63
commit
c323cc4d98
@ -0,0 +1,64 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Exit on error
|
||||||
|
set -e
|
||||||
|
set -u
|
||||||
|
|
||||||
|
# Check args
|
||||||
|
if [ "$#" -ne 3 ]; then
|
||||||
|
echo "Usage: $0 <stage1-participants-json> <participant-allocation> <validator-allocation>"
|
||||||
|
echo "Example: $0 ./stage-participants.json 1000000 1000000000000"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
STAGE1_PARTICIPANTS_FILE="$1"
|
||||||
|
PARTICIPANT_ALLOCATION="$2"
|
||||||
|
VALIDATOR_ALLOCATION="$3"
|
||||||
|
STAGE1_GENESIS_DIR=stage1-genesis
|
||||||
|
|
||||||
|
# Create a temporary target directory
|
||||||
|
mkdir -p $STAGE1_GENESIS_DIR
|
||||||
|
|
||||||
|
# --------
|
||||||
|
|
||||||
|
# Copy over the stage1-participants json file for genesis.sh to use
|
||||||
|
cp $STAGE1_PARTICIPANTS_FILE "$STAGE1_GENESIS_DIR/stage1-participants.json"
|
||||||
|
|
||||||
|
echo "Copied over stage1 participants json file to mount dir"
|
||||||
|
|
||||||
|
# --------
|
||||||
|
|
||||||
|
# For each participant, allocate balance on stage1 according to role
|
||||||
|
stage1_participants=$(cat "$STAGE1_PARTICIPANTS_FILE")
|
||||||
|
stage1_allocations_file="$STAGE1_GENESIS_DIR/stage1-allocations.json"
|
||||||
|
jq -n --argjson participants "$stage1_participants" --arg participant_allocation "$PARTICIPANT_ALLOCATION" --arg validator_allocation "$VALIDATOR_ALLOCATION" '
|
||||||
|
[
|
||||||
|
$participants[] |
|
||||||
|
{
|
||||||
|
cosmos_address: .cosmos_address,
|
||||||
|
balance: (if .role == "validator" then $validator_allocation else $participant_allocation end)
|
||||||
|
}
|
||||||
|
]' > $stage1_allocations_file
|
||||||
|
|
||||||
|
echo "Calculated allocations for stage 1 chain"
|
||||||
|
|
||||||
|
# --------
|
||||||
|
|
||||||
|
# Run a script with cerc/laconicd:local to generate the genesis file
|
||||||
|
# with onboarding module state and given allocations
|
||||||
|
docker run -it \
|
||||||
|
-v ./$STAGE1_GENESIS_DIR:/root/.laconicd \
|
||||||
|
-v ./scripts:/scripts \
|
||||||
|
cerc/laconicd:local bash -c "/scripts/genesis.sh"
|
||||||
|
|
||||||
|
# Copy over the genesis file to output folder
|
||||||
|
OUTPUT_DIR=output
|
||||||
|
mkdir -p $OUTPUT_DIR
|
||||||
|
cp ./$STAGE1_GENESIS_DIR/config/genesis.json $OUTPUT_DIR/genesis.json
|
||||||
|
|
||||||
|
echo "Genesis file for stage1 written to $OUTPUT_DIR/genesis.json"
|
||||||
|
|
||||||
|
# --------
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
echo "Please remove the temporary data directory: sudo rm -rf $STAGE1_GENESIS_DIR"
|
Loading…
Reference in New Issue
Block a user