diff --git a/contrib/scripts/localnet.sh b/contrib/scripts/localnet.sh index df2c86e4f..fbcb0c8a5 100755 --- a/contrib/scripts/localnet.sh +++ b/contrib/scripts/localnet.sh @@ -54,9 +54,9 @@ echo_success() { echo_info "Parsing flags for the script..." -# $FLAG_NO_BUILD: toggles whether to build from source. The default -# behavior of the script is to run make install if the flag --no-build is not present. -FLAG_NO_BUILD=false +# $FLAG_SKIP_BUILD: toggles whether to build from source. The default +# behavior of the script is to run make install if the flag --no-build is omitted. +FLAG_SKIP_BUILD=false build_from_source() { @@ -81,7 +81,7 @@ enable_feature_flag() { while [[ $# -gt 0 ]]; do case $1 in --no-build) - FLAG_NO_BUILD=true + FLAG_SKIP_BUILD=true shift ;; --features) @@ -96,13 +96,13 @@ while [[ $# -gt 0 ]]; do done -# Check if FLAG_NO_BUILD was set to true -if ! $FLAG_NO_BUILD; then +# Check if FLAG_SKIP_BUILD was set to true +if ! $FLAG_SKIP_BUILD; then build_from_source fi echo_info "Features flags:" -echo "FLAG_NO_BUILD: $FLAG_NO_BUILD" +echo "FLAG_SKIP_BUILD: $FLAG_SKIP_BUILD" SEDOPTION="" if [[ "$OSTYPE" == "darwin"* ]]; then @@ -119,9 +119,11 @@ if pgrep -x "$BINARY" >/dev/null; then killall nibid fi -# Remove previous data +# Remove previous data, preserving keyring and config files echo_info "Removing previous chain data from $CHAIN_DIR..." -rm -rf "$CHAIN_DIR" +$BINARY tendermint unsafe-reset-all +rm -f "$CHAIN_DIR/config/genesis.json" +rm -rf "$CHAIN_DIR/config/gentx/" # Add directory for chain, exit if error if ! mkdir -p "$CHAIN_DIR" 2>/dev/null; then @@ -135,6 +137,7 @@ if $BINARY init $CHAIN_ID --chain-id $CHAIN_ID --overwrite; then echo_success "Successfully initialized $CHAIN_ID" else echo_error "Failed to initialize $CHAIN_ID" + exit 1 fi # nibid config @@ -143,6 +146,7 @@ $BINARY config keyring-backend test $BINARY config chain-id $CHAIN_ID $BINARY config broadcast-mode sync $BINARY config output json +$BINARY config node "http://localhost:26657" $BINARY config # Prints config. # Enable API Server @@ -165,15 +169,19 @@ echo_info "Adding genesis accounts..." val_key_name="validator" -echo "$MNEMONIC" | $BINARY keys add $val_key_name --recover -$BINARY add-genesis-account $($BINARY keys show $val_key_name -a) $GENESIS_COINS -# EVM encrypted nibi address for the same account -$BINARY add-genesis-account nibi1cr6tg4cjvux00pj6zjqkh6d0jzg7mksaywxyl3 $GENESIS_COINS -echo_success "Successfully added genesis account: $val_key_name" +if ! $BINARY keys show $val_key_name; then + echo "$MNEMONIC" | $BINARY keys add $val_key_name --recover + echo_success "Successfully added key: $val_key_name" +fi -val_address=$($BINARY keys list | jq -r '.[] | select(.name == "validator") | .address') +val_address=$($BINARY keys show $val_key_name -a) val_address=${val_address:-"nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl"} +$BINARY add-genesis-account $val_address $GENESIS_COINS +# EVM encoded nibi address for the same account +$BINARY add-genesis-account nibi1cr6tg4cjvux00pj6zjqkh6d0jzg7mksaywxyl3 $GENESIS_COINS +echo_success "Successfully added genesis account: $val_key_name" + # ------------------------------------------------------------------------ # Configure genesis params # ------------------------------------------------------------------------