Add script to create and collect gentx

This commit is contained in:
Shreerang Kale 2025-05-14 11:05:51 +05:30
parent 13c95e61c5
commit daad25a049

View File

@ -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