-
Notifications
You must be signed in to change notification settings - Fork 9
/
deploy_graph.sh
executable file
·43 lines (31 loc) · 1.15 KB
/
deploy_graph.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
#!/bin/sh
# Check if all required arguments are provided
if [ $# -ne 4 ]; then
echo "Usage: $0 <subgraph-name> <rpc-url> <graph-node-url> <ipfs-url>"
exit 1
fi
SUBGRAPH_NAME=$1
RPC_URL=$2
GRAPH_NODE_URL=$3
IPFS_URL=$4
export SUBGRAPH_NAME
export RPC_URL
export GRAPH_NODE_URL
export IPFS_URL
# Query the Polygon service
response=$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' $RPC_URL)
echo "RPC Response $response"
# Parse and convert the result from hex to decimal
hex_result=$(echo $response | sed -n 's/.*"result":"0x\([^"]*\)".*/\1/p')
decimal_result=$(printf "%d" 0x$hex_result)
echo "Hex result: $hex_result"
echo "Decimal result: $decimal_result"
# Increment the block number by one
incremented_result=$((decimal_result + 1))
echo "Incremented result: $incremented_result"
export START_BLOCK=$incremented_result
echo "Substituting block number"
# Substitute environment variables in the JSON file
envsubst < $SUBGRAPH_NAME/networkConfig/localhost.json.template > $SUBGRAPH_NAME/networkConfig/localhost.json
echo "Deploying $SUBGRAPH_NAME"
cd $SUBGRAPH_NAME && yarn deploy