#!/bin/bash

# Exit on error
set -e
set -u

NODE_HOME="$HOME/.laconicd"
testnet2_genesis="$NODE_HOME/tmp-testnet2/genesis.json"

if [ ! -f ${testnet2_genesis} ]; then
  echo "testnet2 genesis file not found, exiting..."
  exit 1
fi

# Remove data but keep keys
laconicd cometbft unsafe-reset-all

# Use provided genesis config
cp $testnet2_genesis $NODE_HOME/config/genesis.json

# Set chain id in config
chain_id=$(jq -r '.chain_id' $testnet2_genesis)
laconicd config set client chain-id $chain_id --home $NODE_HOME

echo "Node data reset and ready for testnet2!"
