From c323cc4d980527844f9ff35964cdb96cf64b1cb2 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 19 Aug 2024 09:47:03 +0530 Subject: [PATCH] Add a script to generate stage1 genesis file from a JSON file --- .../generate-stage1-genesis-from-json.sh | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage1-genesis-from-json.sh diff --git a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage1-genesis-from-json.sh b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage1-genesis-from-json.sh new file mode 100755 index 0000000..af888ee --- /dev/null +++ b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage1-genesis-from-json.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +# Exit on error +set -e +set -u + +# Check args +if [ "$#" -ne 3 ]; then + echo "Usage: $0 " + 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"