-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun-dev-node.sh
executable file
·98 lines (80 loc) · 3.33 KB
/
run-dev-node.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
NITRO_NODE_VERSION="v3.2.1-d81324d" # <-- only update this when you need a new version
TARGET_IMAGE="offchainlabs/nitro-node:${NITRO_NODE_VERSION}"
# By default, use nitro docker image. If "--stylus" is passed, build the image with stylus dev dependencies
STYLUS_MODE="false"
# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--stylus)
STYLUS_MODE="true"
shift
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
if [[ "$STYLUS_MODE" == "true" ]]; then
echo "Building Nitro node with Stylus dev dependencies..."
# Build using the specific version
docker build . --target nitro-node-stylus-dev \
--tag nitro-node-stylus-dev -f stylus-dev/Dockerfile \
--build-arg NITRO_NODE_VERSION="${NITRO_NODE_VERSION}"
TARGET_IMAGE="nitro-node-stylus-dev"
fi
# Start Nitro dev node in the background
echo "Starting Nitro dev node..."
docker run --rm --name nitro-dev -p 8547:8547 "${TARGET_IMAGE}" --dev --http.addr 0.0.0.0 --http.api=net,web3,eth,debug &
# Wait for the node to initialize
echo "Waiting for the Nitro node to initialize..."
until [[ "$(curl -s -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"net_version","params":[],"id":1}' \
http://127.0.0.1:8547)" == *"result"* ]]; do
sleep 0.1
done
# Check if node is running
curl_output=$(curl -s -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"net_version","params":[],"id":1}' \
http://127.0.0.1:8547)
if [[ "$curl_output" == *"result"* ]]; then
echo "Nitro node is running!"
else
echo "Failed to start Nitro node."
exit 1
fi
# Make the caller a chain owner
echo "Setting chain owner to pre-funded dev account..."
cast send 0x00000000000000000000000000000000000000FF "becomeChainOwner()" \
--private-key 0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659 \
--rpc-url http://127.0.0.1:8547
# Deploy Cache Manager Contract
echo "Deploying Cache Manager contract..."
deploy_output=$(cast send --private-key 0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659 \
--rpc-url http://127.0.0.1:8547 \
--create 0x60a06040523060805234801561001457600080fd5b50608051611d1c61003060003960006105260152611d1c6000f3fe)
# Extract contract address using awk from plain text output
contract_address=$(echo "$deploy_output" | awk '/contractAddress/ {print $2}')
# Check if contract deployment was successful
if [[ -z "$contract_address" ]]; then
echo "Error: Failed to extract contract address. Full output:"
echo "$deploy_output"
exit 1
fi
echo "Cache Manager contract deployed at address: $contract_address"
# Register the deployed Cache Manager contract
echo "Registering Cache Manager contract as a WASM cache manager..."
registration_output=$(cast send --private-key 0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659 \
--rpc-url http://127.0.0.1:8547 \
0x0000000000000000000000000000000000000070 \
"addWasmCacheManager(address)" "$contract_address")
# Check if registration was successful
if [[ "$registration_output" == *"error"* ]]; then
echo "Failed to register Cache Manager contract. Registration output:"
echo "$registration_output"
exit 1
fi
# If no errors, print success message
echo "Cache Manager deployed and registered successfully. Nitro node is running..."
wait # Keep the script alive and the node running