foundry container now does work of extracting private keys

This commit is contained in:
stubbsta 2024-05-24 09:41:03 +02:00
parent 894f73462d
commit da0cbd0da4
No known key found for this signature in database
4 changed files with 23 additions and 33 deletions

View File

@ -16,8 +16,6 @@ services:
com.centurylinklabs.watchtower.enable: '${WATCHTOWER_ENABLED:-false}'
ports:
- 0.0.0.0:8545:8545
environment:
- ANVIL_ACC=${ACCOUNTS}
command:
- anvil
--port=8545
@ -28,8 +26,10 @@ services:
--block-time=12
--silent
--config-out=/shared/anvil-config.txt
- /getPrivateKeys.sh
volumes:
- accounts-volume:/shared
- ./getPrivateKeys.sh:/getPrivateKeys.sh
networks:
- simulation
@ -85,7 +85,6 @@ services:
- '/opt/run_nwaku.sh'
volumes:
- ./run_nwaku.sh:/opt/run_nwaku.sh:Z
- ./parseAccountsDetails.sh:/opt/parseAccountsDetails.sh:Z
- accounts-volume:/shared
depends_on:
contract-repo-deployer:

15
getPrivateKeys.sh Normal file
View File

@ -0,0 +1,15 @@
#!/bin/sh
# Install json parser
apk update
apk add jq
# Read the JSON file
json_content=$(cat /shared/anvil-config.txt)
# Extract private_keys array values using jq
private_keys=$(echo "$json_content" | jq -r '.private_keys[]')
# Write private keys to a new file for easier access
echo "Writing private keys to file"
echo "$private_keys" > /shared/private-keys.txt

View File

@ -1,23 +0,0 @@
#!/bin/bash
# Read the JSON file
json_content=$(cat /shared/anvil-config.txt)
# Extract available_accounts and private_keys arrays using jq
available_accounts=$(echo "$json_content" | jq -r '.available_accounts[]')
private_keys=$(echo "$json_content" | jq -r '.private_keys[]')
# Convert the extracted strings to Bash arrays
available_accounts_array=()
while IFS= read -r account; do
available_accounts_array+=("$account")
done <<< "$available_accounts"
private_keys_array=()
while IFS= read -r key; do
private_keys_array+=("$key")
done <<< "$private_keys"
# echo "ACCOUNT: ${available_accounts_array[$1-1]}"
# echo "PRIVATE KEY: ${private_keys_array[$1-1]}"
echo ${private_keys_array[$1-1]}

View File

@ -2,8 +2,8 @@
# Install bind-tools package used for domainname resolution
apk add bind-tools
apk add jq
apk add bash
# apk add jq
# apk add bash
if test -f .env; then
echo "Using .env file"
@ -21,6 +21,7 @@ get_ip_address_and_replace() {
# 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"
@ -52,18 +53,16 @@ INDEX=`dig -x $IP +short | sed 's/.*_\([0-9]*\)\..*/\1/'`
# Hello
echo "Hello I'm container $INDEX of $COUNT"
###########################################################################
if test -f .$RLN_CREDENTIAL_PATH; then
echo "$RLN_CREDENTIAL_PATH already exists. Use it instead of creating a new one."
else
val=$(/bin/bash ./opt/parseAccountsDetails.sh $INDEX)
echo $val
PRIVATE_KEY=$(sed -n "${INDEX}p" /shared/private-keys.txt)
echo $PRIVATE_KEY
echo "Generating RLN keystore"
/usr/bin/wakunode generateRlnKeystore \
--rln-relay-eth-client-address="$RPC_URL" \
--rln-relay-eth-private-key=$val \
--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 \