Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/Payments.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ contract Payments is Initializable, UUPSUpgradeable, OwnableUpgradeable, Reentra
uint256[] storage allRailIds = isPayer ? payerRails[token][addr] : payeeRails[token][addr];
uint256 railsLength = allRailIds.length;

RailInfo[] memory tempResults = new RailInfo[](railsLength);
RailInfo[] memory results = new RailInfo[](railsLength);
uint256 resultCount = 0;

for (uint256 i = 0; i < railsLength; i++) {
Expand All @@ -1581,23 +1581,17 @@ contract Payments is Initializable, UUPSUpgradeable, OwnableUpgradeable, Reentra
// Skip non-existent rails
if (rail.from == address(0)) continue;

// Add rail to our temporary array
tempResults[resultCount] =
RailInfo({railId: railId, isTerminated: rail.endEpoch > 0, endEpoch: rail.endEpoch});
// Add rail info to results
results[resultCount] = RailInfo({railId: railId, isTerminated: rail.endEpoch > 0, endEpoch: rail.endEpoch});
resultCount++;
}

// Create correctly sized final result array
RailInfo[] memory result = new RailInfo[](resultCount);

// Only copy if we have results (avoid unnecessary operations)
if (resultCount > 0) {
for (uint256 i = 0; i < resultCount; i++) {
result[i] = tempResults[i];
}
// Truncate
assembly ("memory-safe") {
mstore(results, resultCount)
}

return result;
return results;
}

/// @notice Number of pending rate-change entries for a rail
Expand Down