-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_poi.sh
62 lines (50 loc) · 1.92 KB
/
get_poi.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
#!/bin/sh
# Find all subgraph health:
#query {
# indexingStatuses {
# subgraph
# synced
# health
# }
#}
INDEXER_ADDRESS='change_your_indexer_address'
INDEXER_EVM_RPC_URL="change_your_eth_rpc"
SUBGRAPH_DEPLOYMENT=$1
BLOCK_NUMBER=$2
if [ -z "$INDEXER_ADDRESS" ]; then
echo 'Environment variable INDEXER_ADDRESS must be set to a valid indexer address'
exit 1
fi
if [ -z "$SUBGRAPH_DEPLOYMENT" ] || [ -z "$BLOCK_NUMBER" ]; then
echo "Usage: $0 [subgraph deployment IPFS hash] [last good block number]"
exit 1
fi
if [ "$BLOCK_NUMBER" -lt 11446768 ]; then
startBlock=11446768
echo "startBlock: $startBlock"
else
start_block='{epoches(where: {startBlock_lt: '$BLOCK_NUMBER', endBlock_gt: '$BLOCK_NUMBER'}){startBlock}}'
start_block_json="{\"query\":\"$start_block\"}"
startBlock=$(curl \
-s -L -X POST -H 'Content-Type: application/json' \
-d "$start_block_json" https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-mainnet | \
jq -r '.data.epoches[0].startBlock')
echo "query startBlock: " $startBlock
fi
BLOCK_HEX=$(echo "obase=16; $startBlock" | bc | xargs printf "0x%s\n")
BLOCK_HASH=$(curl \
-s -X POST -H 'Content-Type: application/json' \
--data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["'$BLOCK_HEX'", false],"id":1}' \
$INDEXER_EVM_RPC_URL | \
jq -r '.result.hash')
if [ -z "$BLOCK_HASH" ]; then
echo "Block $startBlock not found"
exit 2
fi
gql_query='query { proofOfIndexing(subgraph: \"'$SUBGRAPH_DEPLOYMENT'\", blockHash: \"'$BLOCK_HASH'\", blockNumber: '$startBlock', indexer: \"'$INDEXER_ADDRESS'\") }'
json="{\"query\":\"$gql_query\"}"
POI=$(curl \
-s -L -X POST -H 'Content-Type: application/json' \
-d "$json" http://127.0.0.1:8030/graphql | \
jq -r '.data.proofOfIndexing')
echo $POI