diff --git a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage1-genesis-from-csv.sh b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage1-genesis-from-csv.sh new file mode 100755 index 0000000..3c4e6f4 --- /dev/null +++ b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage1-genesis-from-csv.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +# Exit on error +set -e +set -u + +# Check args +if [ "$#" -ne 3 ]; then + echo "Usage: $0 " + echo "Example: $0 /home/user/stage0-deployment subscribed-participants.csv 1000000 1000000000000" + exit 1 +fi +STAGE0_DEPLOYMENT_DIR="$1" +PARTICIPANT_ALLOCATION="$2" +VALIDATOR_ALLOCATION="$3" +CSV_FILE_PATH="$4" +STAGE1_GENESIS_DIR=stage1-genesis + +# Create a temporary target directory +mkdir -p $STAGE1_GENESIS_DIR + +# -------- + +# For each participant, set balance for stage1 using funding_amount value (if present) or default allocations + +stage1_allocations_file="$STAGE1_GENESIS_DIR/stage1-allocations.json" +jq -Rn --arg participant_allocation "$PARTICIPANT_ALLOCATION" --arg validator_allocation "$VALIDATOR_ALLOCATION" ' + (input | split(",")) as $header | + reduce (inputs | split(",")) as $row ( + []; + . + [{ + cosmos_address: $row[($header | index("laconic_address"))], + balance: (if $row[($header | index("funding_amount"))] != "" then $row[($header | index("funding_amount"))] else (if $row[($header | index("role"))] == "validator" then $validator_allocation else $participant_allocation end) end) + }] + ) +' < <(tail -n +2 "$CSV_FILE_PATH") > "$stage1_csv_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"