From b1bf65fb2afc68f977803260e264220af1b8c99b Mon Sep 17 00:00:00 2001 From: Tim Pechersky Date: Thu, 10 Feb 2022 05:07:07 +0000 Subject: [PATCH] return array with all pool ids that controller owns --- contracts/terminus/TerminusFacet.sol | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/contracts/terminus/TerminusFacet.sol b/contracts/terminus/TerminusFacet.sol index dd1a864..fb8ade1 100644 --- a/contracts/terminus/TerminusFacet.sol +++ b/contracts/terminus/TerminusFacet.sol @@ -265,16 +265,23 @@ contract TerminusFacet is ERC1155WithTerminusStorage { { LibTerminus.TerminusStorage storage ts = LibTerminus.terminusStorage(); + uint256 index = 0; + uint256[] memory poolIDs = new uint256[](ts.currentPoolID); + uint256 numControlledPools = 0; for (uint256 i = 0; i < ts.currentPoolID; i++) { - uint256 index = 0; - uint256[] memory poolIDs = new uint256[](ts.currentPoolID); address poolController = ts.poolController[i]; if (poolController == controler) { - poolIDs[index] = i; + numControlledPools++; + } + } + uint256[] memory controlledPools = new uint256[](numControlledPools); + for (uint256 i = 0; i < ts.currentPoolID; i++) { + address poolController = ts.poolController[i]; + if (poolController == controler) { + controlledPools[index] = i; index++; } - index++; - return poolIDs[:index]; } + return controlledPools; } }