#!/bin/bash # Exit on error set -e set -u # Check args if [ "$#" -ne 2 ]; then echo "Usage: $0 " exit 1 fi TESTNET_STATE_FILE="$1" LPS_DISTRIBUTION_FILE="$2" MAINNET_GENESIS_DIR=mainnet-genesis OUTPUT_DIR=output if ! jq empty $LPS_DISTRIBUTION_FILE >/dev/null 2>&1; then echo "$LPS_DISTRIBUTION_FILE is not a valid JSON" exit 1 fi # Create a required target directories mkdir -p $MAINNET_GENESIS_DIR mkdir -p $OUTPUT_DIR # -------- # Copy testnet state file and distribution to required dir cp $TESTNET_STATE_FILE $MAINNET_GENESIS_DIR/testnet-state.json cp $LPS_DISTRIBUTION_FILE $MAINNET_GENESIS_DIR/distribution.json # -------- script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" echo "Initializing a new empty chain with chain-id $CHAIN_ID..." docker run \ -v ./$MAINNET_GENESIS_DIR:/root/.laconicd \ -v $script_dir:/scripts \ -e "CHAIN_ID=$CHAIN_ID" \ cerc/laconicd:local bash -c "/scripts/init-mainnet.sh" # -------- # Install required bech32 dependency # Define and create venv if not exists venv_dir="$PWD/venv" if [ ! -d "$venv_dir" ]; then python3 -m venv "$venv_dir" "$venv_dir/bin/pip" install bech32 fi echo "Carrying over state from testnet state to mainnet genesis..." "$venv_dir/bin/python" "$script_dir/transfer-state.py" # Clean up venv rm -rf "$venv_dir" # -------- # Run a script with cerc/laconicd:local to generate the genesis file # with onboarding module state and given allocations echo "Performing alps allocations..." docker run \ -v ./$MAINNET_GENESIS_DIR:/root/.laconicd \ -v $script_dir:/scripts \ -e "CHAIN_ID=$CHAIN_ID" \ -e "EARLY_SUPPORTS_ACC_ADDRESS=$EARLY_SUPPORTS_ACC_ADDRESS" \ cerc/laconicd:local bash -c "/scripts/genesis.sh" # Copy over the genesis file to output folder cp ./$MAINNET_GENESIS_DIR/config/genesis.json $OUTPUT_DIR/genesis.json echo "Genesis file for mainnet written to $OUTPUT_DIR/genesis.json" # -------- # Clean up rm -rf $MAINNET_GENESIS_DIR