Skip to content

Instantly share code, notes, and snippets.

@andreivladbrg
Created September 6, 2023 12:22
Show Gist options
  • Save andreivladbrg/59c27efa49662460e2463fa500be64e8 to your computer and use it in GitHub Desktop.
Save andreivladbrg/59c27efa49662460e2463fa500be64e8 to your computer and use it in GitHub Desktop.
    function _removeStreamIdFromRecipient(address recipient, uint256 streamId) internal {
        uint256 lastStreamId = _repicientStreamIds[repicient].length - 1;
        uint256 streamIdIndex = _findStreamIdIndex(repicient, streamId);

        // Move the last stream id to the slot of the stream id to delete
        _repicientStreamIds[repicient][streamIdIndex] = _repicientStreamIds[repicient][lastStreamId];
        // Remove the last id
        _repicientStreamIds[repicient].pop();
    }

    function _findStreamIdIndex(address recipient, uint256 streamId) internal view returns (uint256) {
        for (uint256 i = 0; i < _repicientStreamIds[recipient].length; i++) {
            if (_repicientStreamIds[recipient][i] == streamId) {
                return i;
            }
        }
    }

    function _addStreamIdToRecipient(address recipient, uint256 streamId) internal {
        _repicientStreamIds[recipient].push(streamId);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment