From aad81d4f7ba9bac2280d8e0737a25a6ee5291d75 Mon Sep 17 00:00:00 2001 From: Darshan K <35736874+darshankabariya@users.noreply.github.com> Date: Fri, 25 Jul 2025 22:15:03 +0530 Subject: [PATCH] fix: Improve setup wizard (#168) --- register_rln.sh | 31 ++++++++++++------- setup_wizard.sh | 79 +++++++++++-------------------------------------- 2 files changed, 38 insertions(+), 72 deletions(-) diff --git a/register_rln.sh b/register_rln.sh index 10312d6..449995a 100755 --- a/register_rln.sh +++ b/register_rln.sh @@ -1,6 +1,5 @@ #!/bin/sh - if test -f ./keystore/keystore.json; then echo "keystore/keystore.json already exists. Use it instead of creating a new one." echo "Exiting" @@ -27,20 +26,32 @@ if ! command -v cast >/dev/null 2>&1; then foundryup fi +# default: do mint/approve +NEED_MINTING=1 + +for arg in "$@"; do + case "$arg" in + --no-mint) NEED_MINTING=0 ;; + --mint) NEED_MINTING=1 ;; + esac +done + RLN_CONTRACT_ADDRESS=0xB9cd878C90E49F797B4431fBF4fb333108CB90e6 TOKEN_CONTRACT_ADDRESS=0x185A0015aC462a0aECb81beCc0497b649a64B9ea TTT_AMOUNT_WEI=5000000000000000000 # Mint -echo "\nMinting test token" -if ! cast send "$TOKEN_CONTRACT_ADDRESS" "mint(address,uint256)" \ - "$ETH_TESTNET_ACCOUNT" "$TTT_AMOUNT_WEI" \ - --private-key "$ETH_TESTNET_KEY" \ - --rpc-url "$RLN_RELAY_ETH_CLIENT_ADDRESS" -then - echo " Mint transaction failed." - exit 1 -fi +if [ "$NEED_MINTING" = "1" ]; then + echo "\nMinting test token" + if ! cast send "$TOKEN_CONTRACT_ADDRESS" "mint(address,uint256)" \ + "$ETH_TESTNET_ACCOUNT" "$TTT_AMOUNT_WEI" \ + --private-key "$ETH_TESTNET_KEY" \ + --rpc-url "$RLN_RELAY_ETH_CLIENT_ADDRESS" + then + echo " Mint transaction failed." + exit 1 + fi +fi # Approve echo "\nApprove to spend the test tokens" diff --git a/setup_wizard.sh b/setup_wizard.sh index 791a2ad..1c4e5b9 100755 --- a/setup_wizard.sh +++ b/setup_wizard.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash echocol() { @@ -10,35 +10,6 @@ echocol() RLN_CONTRACT_ADDRESS=0xB9cd878C90E49F797B4431fBF4fb333108CB90e6 TOKEN_CONTRACT_ADDRESS=0x185A0015aC462a0aECb81beCc0497b649a64B9ea REQUIRED_AMOUNT=5 -TTT_AMOUNT_WEI=5000000000000000000 - -mint_tokens() { - echocol "" - echocol "Minting TTT tokens ..." - cast send $TOKEN_CONTRACT_ADDRESS "mint(address,uint256)" \ - $ETH_TESTNET_ACCOUNT $TTT_AMOUNT_WEI \ - --private-key $ETH_TESTNET_KEY \ - --rpc-url $RLN_RELAY_ETH_CLIENT_ADDRESS || { - echocol "❌ Mint transaction failed." - exit 1 - } - echocol "✅ Mint complete!" - echocol "" -} - -approve_tokens() { - echocol "" - echocol "Approving RLN contract to spend your TTT tokens ..." - cast send $TOKEN_CONTRACT_ADDRESS "approve(address,uint256)" \ - $RLN_CONTRACT_ADDRESS $TTT_AMOUNT_WEI \ - --private-key $ETH_TESTNET_KEY \ - --rpc-url $RLN_RELAY_ETH_CLIENT_ADDRESS || { - echocol "❌ Approve transaction failed." - exit 1 - } - echocol "✅ Approval complete!" - echocol "" -} check_eth_balance() { # 0.01 ETH in wei @@ -75,6 +46,15 @@ if [ -f keystore/keystore.json ]; then fi fi +# Ensure Foundry (cast & foundryup) is available for token mint/approve calls +if ! command -v cast >/dev/null 2>&1; then + echocol "\n Foundry toolkit (cast) not found. Installing Foundry... \n" + curl -L https://foundry.paradigm.xyz | bash + # Make the freshly installed binaries available in the current session + export PATH="$HOME/.foundry/bin:$PATH" + foundryup +fi + if [ -z "$(which docker 2>/dev/null)" ]; then echo "Ensure that 'docker\` is installed and in \$PATH" exit 1 @@ -186,41 +166,16 @@ echocol "Your current TTT token balance is: $USER_BALANCE" echocol "Required amount: $REQUIRED_AMOUNT" echocol "" +MINT_CHOICE="y" if [ "$USER_BALANCE" -ge "$REQUIRED_AMOUNT" ]; then echocol "You already have enough TTT tokens to register." read -p "Do you want to mint more tokens? (y/N): " MINT_CHOICE - if [ "$MINT_CHOICE" = "y" ] || [ "$MINT_CHOICE" = "Y" ]; then - mint_tokens - approve_tokens - else - approve_tokens - fi +fi + +if [ "$MINT_CHOICE" = "y" ] || [ "$MINT_CHOICE" = "Y" ]; then + ./register_rln.sh --mint; else - echocol "Minting and approving required TTT tokens …" - mint_tokens - approve_tokens -fi - -SUDO="" -if ! docker info > /dev/null 2>&1; then - echocol "...." - echocol "'sudo' seems to be needed to run docker, your unix password will be asked" - SUDO="sudo" -fi - - - -echocol "" -echocol "🔐 Registering RLN membership..." -read -p "Press ENTER to continue..." foo - -if ! $SUDO ./register_rln.sh; then - echocol "" - echocol "❌ RLN registration failed. This may be due to high gas fees." - echocol "💡 Make sure you have enough Linea Sepolia ETH and try again with:" - echocol " $SUDO ./register_rln.sh" - echocol "" - exit 1 + ./register_rln.sh --no-mint; fi echocol "" @@ -229,6 +184,6 @@ echocol "" echocol "Your node is ready! enter the following command to start it:" read -p "Press ENTER to continue..." foo -echo "> $SUDO docker-compose up -d" +docker-compose up -d echocol "✅ Node started successfully!" echocol ""