-
Notifications
You must be signed in to change notification settings - Fork 1
/
list_games.sh
executable file
·38 lines (33 loc) · 1.17 KB
/
list_games.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
#!/usr/bin/env bash
set -euo pipefail
RPC=${1:?Must specify RPC address}
FACTORY_ADDR=${2:?Must specify dispute game factory address}
COUNT=$(cast call --rpc-url "${RPC}" "${FACTORY_ADDR}" 'gameCount() returns(uint256)')
echo "Game count: ${COUNT}"
if [[ "${COUNT}" == "0" ]]
then
exit
fi
((COUNT=COUNT-1))
for i in $(seq 0 "${COUNT}")
do
GAME=$(cast call --rpc-url "${RPC}" "${FACTORY_ADDR}" 'gameAtIndex(uint256) returns(uint8, uint64, address)' "${i}")
SAVEIFS=$IFS # Save current IFS (Internal Field Separator)
IFS=$'\n' # Change IFS to newline char
GAME=($GAME) # split the string into an array by the same name
IFS=$SAVEIFS # Restore original IFS
GAME_ADDR="${GAME[2]}"
CLAIMS=$(cast call --rpc-url "${RPC}" "${GAME_ADDR}" "claimDataLen() returns(uint256)")
STATUS=$(cast call --rpc-url "${RPC}" "${GAME_ADDR}" "status() return(uint8)" | cast to-dec)
if [[ "${STATUS}" == "0" ]]
then
STATUS="In Progress"
elif [[ "${STATUS}" == "1" ]]
then
STATUS="Challenger Wins"
elif [[ "${STATUS}" == "2" ]]
then
STATUS="Defender Wins"
fi
echo "${i} Game: ${GAME_ADDR} Type: ${GAME[0]} Created: ${GAME[1]} Claims: ${CLAIMS} Status: ${STATUS}"
done