diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..5045b4a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "submodules/waku-rln-contract"] + path = submodules/waku-rln-contract + url = https://github.com/waku-org/waku-rln-contract.git diff --git a/run_nwaku.sh b/run_nwaku.sh index aac8eac..3543e36 100755 --- a/run_nwaku.sh +++ b/run_nwaku.sh @@ -1,5 +1,50 @@ #!/bin/sh +# Install bind-tools package used for domainname resolution +apk add bind-tools + +if test -f .env; then + echo "Using .env file" + . $(pwd)/.env +fi + +# Function to extract IP address from URL, resolve the IP and replace it in the original URL +get_ip_address_and_replace() { + local url=$1 + local domain_name=$(echo $RPC_URL | awk -F[/:] '{print $4}') + local ip_address=$(dig +short $domain_name) + valid_rpc_url="${url/$domain_name/$ip_address}" + echo $valid_rpc_url +} + +# the format of the RPC URL is checked in the generateRlnKeystore command and hostnames are not valid +pattern="^(https?):\/\/((localhost)|([\w_-]+(?:(?:\.[\w_-]+)+)))(:[0-9]{1,5})?([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])*" +# Perform regex matching +if [[ $RPC_URL =~ $pattern ]]; then + echo "RPC URL is valid" +else + echo "RPC URL is invalid: $RPC_URL. Attempting to resolve hostname." + resolved_rpc_url="$(get_ip_address_and_replace $RPC_URL)" + if [ -z "$resolved_rpc_url" ]; then + echo -e "Failed to retrieve IP address for $RPC_URL\n" + else + echo -e "Resolved RPC URL for $RPC_URL: $resolved_rpc_url" + RPC_URL="$resolved_rpc_url" + fi +fi + +if test -f ./$RLN_CREDENTIAL_PATH; then + echo "$RLN_CREDENTIAL_PATH already exists. Use it instead of creating a new one." +else + /usr/bin/wakunode generateRlnKeystore \ + --rln-relay-eth-client-address="$RPC_URL" \ + --rln-relay-eth-private-key=$PRIVATE_KEY \ + --rln-relay-eth-contract-address=$RLN_CONTRACT_ADDRESS \ + --rln-relay-cred-path=$RLN_CREDENTIAL_PATH \ + --rln-relay-cred-password=$RLN_CREDENTIAL_PASSWORD \ + --execute +fi + IP=$(ip a | grep "inet " | grep -Fv 127.0.0.1 | sed 's/.*inet \([^/]*\).*/\1/') echo "I am a nwaku node" @@ -37,8 +82,8 @@ exec /usr/bin/wakunode\ --rest-address=0.0.0.0\ --rln-relay=true\ --rln-relay-dynamic=true\ - --rln-relay-eth-client-address=http://10.1.0.4:8545\ - --rln-relay-eth-contract-address=0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0\ + --rln-relay-eth-client-address="$RPC_URL"\ + --rln-relay-eth-contract-address=$RLN_CONTRACT_ADDRESS\ --dns-discovery=true\ --discv5-discovery=true\ --discv5-enr-auto-update=True\ @@ -47,4 +92,4 @@ exec /usr/bin/wakunode\ --metrics-server=True\ --metrics-server-address=0.0.0.0\ --discv5-bootstrap-node=${BOOTSTRAP_ENR}\ - --nat=extip:${IP} + --nat=extip:${IP} \ No newline at end of file diff --git a/run_register_rln.sh b/run_register_rln.sh deleted file mode 100644 index a8ea0d3..0000000 --- a/run_register_rln.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/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" - exit 1 -fi - - -if test -f .env; then - echo "Using .env file" - . $(pwd)/.env -fi - -# TODO: Set nwaku release when ready instead of quay - - -exec /usr/bin/wakunode generateRlnKeystore \ ---rln-relay-eth-client-address=http://10.1.0.5:8545 \ ---rln-relay-eth-private-key=0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6 \ ---rln-relay-eth-contract-address=0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 \ ---rln-relay-cred-path=/keystore/keystore.json \ ---rln-relay-cred-password="my_secure_keystore_password" \ ---execute \ No newline at end of file diff --git a/submodules/waku-rln-contract b/submodules/waku-rln-contract new file mode 160000 index 0000000..a01daa8 --- /dev/null +++ b/submodules/waku-rln-contract @@ -0,0 +1 @@ +Subproject commit a01daa8b9475a5dd23db47625e86f585963dd473