Skip to content

Commit

Permalink
feat(ethexe): Add script to boot local ethereum node (#4106)
Browse files Browse the repository at this point in the history
  • Loading branch information
ark0f authored Aug 17, 2024
1 parent 84d4148 commit ab080d4
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ resolver = "2"

default-members = ["node/cli"]

exclude = ["ethexe/contracts", "ethexe/docker"]
exclude = ["ethexe/contracts", "ethexe/docker", "ethexe/scripts"]

members = [
"common",
Expand Down
4 changes: 4 additions & 0 deletions ethexe/contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ docs/

# Remappings
remappings.txt

# npm
package-lock.json
package.json
64 changes: 64 additions & 0 deletions ethexe/scripts/local-ethereum-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash

#
# This file is part of Gear.
#
# Copyright (C) 2024 Gear Technologies Inc.
# SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

set -eu

# never used
export ETHERSCAN_API_KEY=""
# anvil account (0) with balance
export PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
# not yet used
export ROUTER_VALIDATORS_LIST=""

ANVIL_LOG_FILE="/tmp/ethexe-anvil.log"
nohup anvil --block-time 2 > $ANVIL_LOG_FILE 2>&1 &
ANVIL_PID=$!

(cd ethexe/contracts && forge clean && forge script script/Router.s.sol:RouterScript --rpc-url "ws://localhost:8545" --broadcast)

BROADCAST_PATH="ethexe/contracts/broadcast/Router.s.sol/31337/run-latest.json"
ROUTER_ADDRESS=`cat $BROADCAST_PATH | jq '.transactions[] | select(.contractName == "Router") | .contractAddress' | tr -d '"'`
PROXY_ADDRESS=`cat $BROADCAST_PATH |
jq ".transactions[] | \
select(.contractName == \"TransparentUpgradeableProxy\") | \
select(.transactionType == \"CREATE\") | \
select(.arguments[] | ascii_downcase | contains(\"${ROUTER_ADDRESS}\")) | \
.contractAddress" |
tr -d '"'`

if [[ -e .ethexe.toml ]]; then
SED_FROM="ethereum_router_address = \"[a-zA-Z0-9]*\""
SED_TO="ethereum_router_address = \"${PROXY_ADDRESS}\""
sed -i.bak "s/$SED_FROM/$SED_TO/g" .ethexe.toml
rm .ethexe.toml.bak

echo "Router address has been updated in .ethexe.toml"
fi

echo "Router address: ${ROUTER_ADDRESS}"
echo "Proxy address: ${PROXY_ADDRESS}"
echo
echo "Anvil is running via nohup. PID: ${ANVIL_PID}. Logs at $ANVIL_LOG_FILE"
echo
read -p "Press enter to see node logs in real time"

tail -f $ANVIL_LOG_FILE

0 comments on commit ab080d4

Please sign in to comment.