Commit b7d93556 authored by Adrian Sutton's avatar Adrian Sutton

op-challenger: Add script to list all games.

parent 4861e897
...@@ -111,6 +111,17 @@ If the game is resolved successfully, the result is printed. ...@@ -111,6 +111,17 @@ If the game is resolved successfully, the result is printed.
These arguments must specify a way for `cast` to sign the transactions. These arguments must specify a way for `cast` to sign the transactions.
See `cast send --help` for supported options. See `cast send --help` for supported options.
### [list_games.sh](scripts/list_games.sh)
```shell
./scripts/list_games.sh <RPC> <GAME_FACTORY_ADDRESS>
```
Prints the games created by the game factory along with their current status.
* `RPC_URL` - the RPC endpoint of the L1 endpoint to use (e.g. `http://localhost:8545`).
* `GAME_FACTORY_ADDRESS` - the address of the dispute game factory contract on L1.
### [list_claims.sh](scripts/list_claims.sh) ### [list_claims.sh](scripts/list_claims.sh)
```shell ```shell
......
#!/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]}"
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]} Status: ${STATUS}"
done
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment