Commit ede728c0 authored by Andreas Bigger's avatar Andreas Bigger

Append only array of games

parent 2959bbb2
......@@ -32,6 +32,13 @@ contract DisputeGameFactory is Ownable, IDisputeGameFactory {
*/
mapping(Hash => IDisputeGame) internal disputeGames;
/**
* @notice An append-only array of disputeGames that have been created.
* @dev This accessor is used by offchain game solvers to efficiently
* track dispute games
*/
IDisputeGame[] public disputeGameList;
/**
* @notice Constructs a new DisputeGameFactory contract.
* @param _owner The owner of the contract.
......@@ -40,6 +47,13 @@ contract DisputeGameFactory is Ownable, IDisputeGameFactory {
transferOwnership(_owner);
}
/**
* @inheritdoc IDisputeGameFactory
*/
function allGames() external view returns (IDisputeGame[] memory _disputeGameList) {
_disputeGameList = disputeGameList;
}
/**
* @inheritdoc IDisputeGameFactory
*/
......@@ -81,6 +95,7 @@ contract DisputeGameFactory is Ownable, IDisputeGameFactory {
// Store the dispute game in the mapping & emit the `DisputeGameCreated` event.
disputeGames[uuid] = proxy;
disputeGameList.push(proxy);
emit DisputeGameCreated(address(proxy), gameType, rootClaim);
}
......
......@@ -29,6 +29,12 @@ interface IDisputeGameFactory {
*/
event ImplementationSet(address indexed impl, GameType indexed gameType);
/**
* @notice retrieves a list of all dispute games created by this factory.
* @return _disputeGameList The list of all dispute games created by this factory.
*/
function allGames() external view returns (IDisputeGame[] memory _disputeGameList);
/**
* @notice `games` queries an internal a mapping that maps the hash of
* `gameType ++ rootClaim ++ extraData` to the deployed `DisputeGame` clone.
......
......@@ -48,6 +48,9 @@ contract DisputeGameFactory_Test is Test {
// Ensure that the dispute game was assigned to the `disputeGames` mapping.
assertEq(address(factory.games(gt, rootClaim, extraData)), address(proxy));
IDisputeGame[] memory disputeGameList = factory.allGames();
assertEq(disputeGameList.length, 1);
assertEq(address(disputeGameList[0]), address(proxy));
}
/**
......
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