From daad25a0491cb70e714fdb2442e18cc36da58749 Mon Sep 17 00:00:00 2001 From: Shreerang Kale Date: Wed, 14 May 2025 11:05:51 +0530 Subject: [PATCH] Add script to create and collect gentx --- .../create-and-collect-gentx.sh | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 stack-orchestrator/config/mainnet-laconicd/create-and-collect-gentx.sh diff --git a/stack-orchestrator/config/mainnet-laconicd/create-and-collect-gentx.sh b/stack-orchestrator/config/mainnet-laconicd/create-and-collect-gentx.sh new file mode 100755 index 0000000..f6fb9bd --- /dev/null +++ b/stack-orchestrator/config/mainnet-laconicd/create-and-collect-gentx.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +set -e + +NODE_HOME=/root/.laconicd +genesis_file_path=$NODE_HOME/config/genesis.json + +if [ -f "$genesis_file_path" ]; then + echo "Genesis file already created, exiting..." + exit 0 +fi + +if [ -z "$PVT_KEY" ]; then + echo "PVT_KEY environment variable not set, exiting..." + exit 1 +fi + +if [ -z "$KEY_NAME" ]; then + echo "KEY_NAME environment variable not set, exiting..." + exit 1 +fi + +if [ -z "$DENOM" ]; then + echo "DENOM environment variable not set, exiting..." + exit 1 +fi + +input_genesis_file=$NODE_HOME/tmp/genesis.json +if [ ! -f ${input_genesis_file} ]; then + echo "Genesis file not provided, exiting..." + exit 1 +fi + +# Strip leading and trailing quotes ("") if they exist +export MONIKER=$(echo "$MONIKER" | sed -e 's/^["'\'']//g' -e 's/["'\'']$//g') +export CHAIN_ID=$(echo "$CHAIN_ID" | sed -e 's/^["'\'']//g' -e 's/["'\'']$//g') +export DENOM=$(echo "$DENOM" | sed -e 's/^["'\'']//g' -e 's/["'\'']$//g') + +# Init +laconicd config set client chain-id $CHAIN_ID --home $NODE_HOME +laconicd init $MONIKER --chain-id=$CHAIN_ID --home $NODE_HOME + +# Copy over provided genesis config +cp $input_genesis_file $genesis_file_path + +# Import private key passed via PVT_KEY +laconicd keys import-hex "$KEY_NAME" "$PVT_KEY" + +account_address=$(laconicd keys list | awk -v key_name="$KEY_NAME" ' + $1 == "name:" && $2 == key_name {found=1} + found && $1 == "- address:" {print $3; exit} +') + +stake_amount=$(jq -r --arg address "$account_address" --arg denom "$DENOM" '.app_state.bank.balances[] | select(.address == $address) | .coins[] | select(.denom == $denom) | .amount' $genesis_file_path) + +# Create gentx with staked amount equal to allocated balance +laconicd genesis gentx $KEY_NAME $stake_amount$DENOM --chain-id $CHAIN_ID + +# Collect the gentx and validate +laconicd genesis collect-gentxs +laconicd genesis validate + +# Update the input genesis file +cp $genesis_file_path $input_genesis_file