Add ability to run mobymask-v2 stack with external optimism endpoint (#279)

* Set optimism geth endpoint from env file

* Set L1 account private keys from env

* Only deploy contract and generate invite in mobymask container

* Add readme for running mobymask v2 stack independently

* Modify mobymask container to stop running server and update readmes

* Check deployer account balance before deploying contract

* Fix for checking account balance before deploying

* Update readme description

* Update MobyMask repo tag in readme

Former-commit-id: 94e38ceabaa89a3ec54e25f4a03cf253d5fae5f9
This commit is contained in:
2023-04-05 17:26:38 +05:30
committed by GitHub
parent 464ef89a01
commit 63fbaa7ae3
16 changed files with 194 additions and 81 deletions
@@ -1,8 +1,13 @@
# Change if pointing to an external L1 endpoint
L1_RPC="http://fixturenet-eth-geth-1:8545"
# L1 endpoint
L1_CHAIN_ID=1212
L1_RPC="http://fixturenet-eth-geth-1:8545"
L1_HOST="fixturenet-eth-geth-1"
L1_PORT=8545
# Credentials for accounts on L1 to send balance to Optimism Proxy contract from
# (enables them to do transactions on L2)
L1_ADDRESS=
L1_PRIV_KEY=
L1_ADDRESS_2=
+33 -5
View File
@@ -1,11 +1,39 @@
#!/bin/sh
set -e
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
# Read the private key of L1 account to deploy contract
# TODO: Take from env if /geth-accounts volume doesn't exist to allow using separately running L1
L1_PRIV_KEY=$(head -n 1 /geth-accounts/accounts.csv | cut -d ',' -f 3)
if [ -f /geth-accounts/accounts.csv ]; then
echo "Using L1 private key from the mounted volume"
# Read the private key of L1 account to deploy contract
PRIVATE_KEY_DEPLOYER=$(head -n 1 /geth-accounts/accounts.csv | cut -d ',' -f 3)
else
echo "Using PRIVATE_KEY_DEPLOYER from env"
fi
# Set the private key
jq --arg privateKey "$L1_PRIV_KEY" '.privateKey = ($privateKey)' secrets-template.json > secrets.json
jq --arg privateKey "$PRIVATE_KEY_DEPLOYER" '.privateKey = $privateKey' secrets-template.json > secrets.json
npm start
export L2_GETH_URL="http://${L2_GETH_HOST}:${L2_GETH_PORT}"
jq --arg rpcUrl "$L2_GETH_URL" '.rpcUrl = $rpcUrl' secrets.json > secrets_updated.json && mv secrets_updated.json secrets.json
cd ../hardhat
export RPC_URL="${L2_GETH_URL}"
while true; do
ACCOUNT_BALANCE=$(yarn hardhat --network optimism balance $PRIVATE_KEY_DEPLOYER | grep ETH)
if [ "$ACCOUNT_BALANCE" != "0.0 ETH" ]; then
echo "Account balance updated: $ACCOUNT_BALANCE"
break # exit the loop
fi
echo "Account balance not updated: $ACCOUNT_BALANCE"
echo "Checking after 2 seconds"
sleep 2
done
cd ../server
npm run deployAndGenerateInvite
@@ -1,5 +1,8 @@
#!/bin/sh
set -e
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
# Merging config files to get deployed contract address
jq -s '.[0] * .[1]' /app/src/mobymask-app-config.json /server/config.json > /app/src/config.json
@@ -0,0 +1,12 @@
# Change if pointing to an external optimism geth endpoint
# L2 endpoints
# TODO: Add another env for complete URL to handle https
L2_GETH_HOST="op-geth"
L2_GETH_PORT=8545
L2_NODE_HOST="op-node"
L2_NODE_PORT=8547
# Credentials for accounts to perform txs on L2
PRIVATE_KEY_DEPLOYER=
PRIVATE_KEY_PEER=
@@ -1,5 +1,5 @@
{
"rpcUrl": "http://op-geth:8545",
"rpcUrl": "",
"privateKey": "",
"baseURI": "http://127.0.0.1:3002/#"
}
@@ -1,11 +1,25 @@
#!/bin/sh
set -e
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
# Assign deployed contract address from server config
CONTRACT_ADDRESS=$(jq -r '.address' /server/config.json | tr -d '"')
L1_PRIV_KEY_2=$(awk -F, 'NR==2{print $NF}' /geth-accounts/accounts.csv)
sed "s/REPLACE_WITH_PRIVATE_KEY/${L1_PRIV_KEY_2}/" environments/watcher-config-template.toml > environments/local.toml
if [ -f /geth-accounts/accounts.csv ]; then
echo "Using L1 private key from the mounted volume"
# Read the private key of L1 account for sending txs from peer
PRIVATE_KEY_PEER=$(awk -F, 'NR==2{print $NF}' /geth-accounts/accounts.csv)
else
echo "Using PRIVATE_KEY_PEER from env"
fi
sed "s/REPLACE_WITH_PRIVATE_KEY/${PRIVATE_KEY_PEER}/" environments/watcher-config-template.toml > environments/local.toml
sed -i "s/REPLACE_WITH_CONTRACT_ADDRESS/${CONTRACT_ADDRESS}/" environments/local.toml
export L2_GETH_URL="http://${L2_GETH_HOST}:${L2_GETH_PORT}"
sed -i 's|REPLACE_WITH_L2_GETH_URL|'"${L2_GETH_URL}"'|' environments/local.toml
echo 'yarn server'
yarn server
@@ -59,7 +59,7 @@
[upstream]
[upstream.ethServer]
gqlApiEndpoint = "http://ipld-eth-server:8083/graphql"
rpcProviderEndpoint = "http://op-geth:8545"
rpcProviderEndpoint = "REPLACE_WITH_L2_GETH_URL"
blockDelayInMilliSecs = 60000
[upstream.cache]