mirror of
https://github.com/lens-protocol/core.git
synced 2026-01-09 22:28:04 -05:00
58 lines
2.1 KiB
Solidity
58 lines
2.1 KiB
Solidity
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
pragma solidity 0.8.10;
|
|
|
|
import {DataTypes} from './DataTypes.sol';
|
|
import {Errors} from './Errors.sol';
|
|
|
|
/**
|
|
* @title Helpers
|
|
* @author Lens
|
|
*
|
|
* @notice This is a library that only contains a single function that is used in the hub contract as well as in
|
|
* both the publishing logic and interaction logic libraries.
|
|
*/
|
|
library Helpers {
|
|
/**
|
|
* @notice This helper function just returns the pointed publication if the passed publication is a mirror,
|
|
* otherwise it returns the passed publication.
|
|
*
|
|
* @param profileId The token ID of the profile that published the given publication.
|
|
* @param pubId The publication ID of the given publication.
|
|
* @param _pubByIdByProfile A pointer to the storage mapping of publications by pubId by profile ID.
|
|
*
|
|
* @return The pointed publication identifier if the the given publication is a mirror, otherwise, the given publication.
|
|
* This is a tuple of (profileId, pubId, collectModule)
|
|
*/
|
|
function getPointedIfMirror(
|
|
uint256 profileId,
|
|
uint256 pubId,
|
|
mapping(uint256 => mapping(uint256 => DataTypes.PublicationStruct))
|
|
storage _pubByIdByProfile
|
|
)
|
|
internal
|
|
view
|
|
returns (
|
|
uint256,
|
|
uint256,
|
|
address
|
|
)
|
|
{
|
|
address collectModule = _pubByIdByProfile[profileId][pubId].collectModule;
|
|
if (collectModule != address(0)) {
|
|
return (profileId, pubId, collectModule);
|
|
} else {
|
|
uint256 pointedTokenId = _pubByIdByProfile[profileId][pubId].profileIdPointed;
|
|
// We validate existence here as an optimization, so validating in calling contracts is unnecessary
|
|
if (pointedTokenId == 0) revert Errors.PublicationDoesNotExist();
|
|
|
|
uint256 pointedPubId = _pubByIdByProfile[profileId][pubId].pubIdPointed;
|
|
|
|
address pointedCollectModule = _pubByIdByProfile[pointedTokenId][pointedPubId]
|
|
.collectModule;
|
|
|
|
return (pointedTokenId, pointedPubId, pointedCollectModule);
|
|
}
|
|
}
|
|
}
|