forked from seeyijie/Memediction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-local.sh
executable file
·58 lines (49 loc) · 1.43 KB
/
setup-local.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
check_anvil_running() {
if lsof -i:8545 >/dev/null; then
return 0 # Anvil is already running
else
return 1 # Anvil is not running
fi
}
kill_anvil() {
echo "Stopping existing Anvil..."
lsof -ti:8545 | xargs kill
}
RESTART_ANVIL=0
while [[ "$1" != "" ]]; do
case $1 in
--restart ) RESTART_ANVIL=1
;;
esac
shift
done
if check_anvil_running; then
if [[ $RESTART_ANVIL -eq 1 ]]; then
kill_anvil
echo "Restarting Anvil..."
anvil > /dev/null & # redirect stdout to /dev/null
ANVIL_PID=$!
sleep 3
else
echo "Anvil is already running. Skipping Anvil startup..."
fi
else
echo "Starting Anvil..."
anvil &
ANVIL_PID=$!
sleep 3
fi
RPC_URL="http://127.0.0.1:8545"
BLOCK_CHECK=$(cast block --rpc-url $RPC_URL)
if [[ $BLOCK_CHECK == *"error"* ]]; then
echo "Failed to connect to Anvil. Exiting..."
if [[ -n "$ANVIL_PID" ]]; then
kill $ANVIL_PID
fi
exit 1
else
echo "Anvil is running. Proceeding with the script..."
fi
# Deploy the contracts, setup the hooks and start initializing
forge compile && forge script script/V4Deployer.s.sol:V4Deployer --rpc-url http://127.0.0.1:8545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --broadcast && forge script script/HookMiningSample.s.sol:HookMiningSample --rpc-url http://127.0.0.1:8545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --broadcast