LensHub now returns IDs for profile creation, collect, mirror, comment and follow

This commit is contained in:
donosonaumczuk
2022-03-31 20:29:57 +01:00
parent 76151b3662
commit 84a8b87b7d
2 changed files with 106 additions and 50 deletions

View File

@@ -147,6 +147,7 @@ contract LensHub is ILensHub, LensNFTBase, VersionedInitializable, LensMultiStat
override
whenNotPaused
onlyWhitelistedProfileCreator
returns (uint256)
{
uint256 profileId = ++_profileCounter;
_mint(vars.to, profileId);
@@ -157,6 +158,7 @@ contract LensHub is ILensHub, LensNFTBase, VersionedInitializable, LensMultiStat
_profileById,
_followModuleWhitelisted
);
return profileId;
}
/// @inheritdoc ILensHub
@@ -338,7 +340,12 @@ contract LensHub is ILensHub, LensNFTBase, VersionedInitializable, LensMultiStat
}
/// @inheritdoc ILensHub
function post(DataTypes.PostData calldata vars) external override whenPublishingEnabled {
function post(DataTypes.PostData calldata vars)
external
override
whenPublishingEnabled
returns (uint256)
{
_validateCallerIsProfileOwnerOrDispatcher(vars.profileId);
_createPost(
vars.profileId,
@@ -348,6 +355,7 @@ contract LensHub is ILensHub, LensNFTBase, VersionedInitializable, LensMultiStat
vars.referenceModule,
vars.referenceModuleData
);
return _profileById[vars.profileId].pubCount;
}
/// @inheritdoc ILensHub
@@ -355,6 +363,7 @@ contract LensHub is ILensHub, LensNFTBase, VersionedInitializable, LensMultiStat
external
override
whenPublishingEnabled
returns (uint256)
{
address owner = ownerOf(vars.profileId);
_validateRecoveredAddress(
@@ -384,12 +393,19 @@ contract LensHub is ILensHub, LensNFTBase, VersionedInitializable, LensMultiStat
vars.referenceModule,
vars.referenceModuleData
);
return _profileById[vars.profileId].pubCount;
}
/// @inheritdoc ILensHub
function comment(DataTypes.CommentData calldata vars) external override whenPublishingEnabled {
function comment(DataTypes.CommentData calldata vars)
external
override
whenPublishingEnabled
returns (uint256)
{
_validateCallerIsProfileOwnerOrDispatcher(vars.profileId);
_createComment(vars);
return _profileById[vars.profileId].pubCount;
}
/// @inheritdoc ILensHub
@@ -397,6 +413,7 @@ contract LensHub is ILensHub, LensNFTBase, VersionedInitializable, LensMultiStat
external
override
whenPublishingEnabled
returns (uint256)
{
address owner = ownerOf(vars.profileId);
_validateRecoveredAddress(
@@ -432,10 +449,16 @@ contract LensHub is ILensHub, LensNFTBase, VersionedInitializable, LensMultiStat
vars.referenceModuleData
)
);
return _profileById[vars.profileId].pubCount;
}
/// @inheritdoc ILensHub
function mirror(DataTypes.MirrorData calldata vars) external override whenPublishingEnabled {
function mirror(DataTypes.MirrorData calldata vars)
external
override
whenPublishingEnabled
returns (uint256)
{
_validateCallerIsProfileOwnerOrDispatcher(vars.profileId);
_createMirror(
vars.profileId,
@@ -444,6 +467,7 @@ contract LensHub is ILensHub, LensNFTBase, VersionedInitializable, LensMultiStat
vars.referenceModule,
vars.referenceModuleData
);
return _profileById[vars.profileId].pubCount;
}
/// @inheritdoc ILensHub
@@ -451,6 +475,7 @@ contract LensHub is ILensHub, LensNFTBase, VersionedInitializable, LensMultiStat
external
override
whenPublishingEnabled
returns (uint256)
{
address owner = ownerOf(vars.profileId);
_validateRecoveredAddress(
@@ -478,6 +503,7 @@ contract LensHub is ILensHub, LensNFTBase, VersionedInitializable, LensMultiStat
vars.referenceModule,
vars.referenceModuleData
);
return _profileById[vars.profileId].pubCount;
}
/**
@@ -517,15 +543,17 @@ contract LensHub is ILensHub, LensNFTBase, VersionedInitializable, LensMultiStat
external
override
whenNotPaused
returns (uint256[] memory)
{
InteractionLogic.follow(
msg.sender,
profileIds,
datas,
FOLLOW_NFT_IMPL,
_profileById,
_profileIdByHandleHash
);
return
InteractionLogic.follow(
msg.sender,
profileIds,
datas,
FOLLOW_NFT_IMPL,
_profileById,
_profileIdByHandleHash
);
}
/// @inheritdoc ILensHub
@@ -533,6 +561,7 @@ contract LensHub is ILensHub, LensNFTBase, VersionedInitializable, LensMultiStat
external
override
whenNotPaused
returns (uint256[] memory)
{
bytes32[] memory dataHashes = new bytes32[](vars.datas.length);
for (uint256 i = 0; i < vars.datas.length; ++i) {
@@ -553,14 +582,15 @@ contract LensHub is ILensHub, LensNFTBase, VersionedInitializable, LensMultiStat
vars.follower,
vars.sig
);
InteractionLogic.follow(
vars.follower,
vars.profileIds,
vars.datas,
FOLLOW_NFT_IMPL,
_profileById,
_profileIdByHandleHash
);
return
InteractionLogic.follow(
vars.follower,
vars.profileIds,
vars.datas,
FOLLOW_NFT_IMPL,
_profileById,
_profileIdByHandleHash
);
}
/// @inheritdoc ILensHub
@@ -568,16 +598,17 @@ contract LensHub is ILensHub, LensNFTBase, VersionedInitializable, LensMultiStat
uint256 profileId,
uint256 pubId,
bytes calldata data
) external override whenNotPaused {
InteractionLogic.collect(
msg.sender,
profileId,
pubId,
data,
COLLECT_NFT_IMPL,
_pubByIdByProfile,
_profileById
);
) external override whenNotPaused returns (uint256) {
return
InteractionLogic.collect(
msg.sender,
profileId,
pubId,
data,
COLLECT_NFT_IMPL,
_pubByIdByProfile,
_profileById
);
}
/// @inheritdoc ILensHub
@@ -585,6 +616,7 @@ contract LensHub is ILensHub, LensNFTBase, VersionedInitializable, LensMultiStat
external
override
whenNotPaused
returns (uint256)
{
_validateRecoveredAddress(
_calculateDigest(
@@ -602,15 +634,16 @@ contract LensHub is ILensHub, LensNFTBase, VersionedInitializable, LensMultiStat
vars.collector,
vars.sig
);
InteractionLogic.collect(
vars.collector,
vars.profileId,
vars.pubId,
vars.data,
COLLECT_NFT_IMPL,
_pubByIdByProfile,
_profileById
);
return
InteractionLogic.collect(
vars.collector,
vars.profileId,
vars.pubId,
vars.data,
COLLECT_NFT_IMPL,
_pubByIdByProfile,
_profileById
);
}
/// @inheritdoc ILensHub

View File

@@ -97,7 +97,7 @@ interface ILensHub {
* followModule: The follow module to use, can be the zero address.
* followModuleData: The follow module initialization data, if any.
*/
function createProfile(DataTypes.CreateProfileData calldata vars) external;
function createProfile(DataTypes.CreateProfileData calldata vars) external returns (uint256);
/**
* @notice Sets the mapping between wallet and its main profile identity.
@@ -184,44 +184,55 @@ interface ILensHub {
* @notice Publishes a post to a given profile, must be called by the profile owner.
*
* @param vars A PostData struct containing the needed parameters.
*
* @return An integer representing the post's publication ID.
*/
function post(DataTypes.PostData calldata vars) external;
function post(DataTypes.PostData calldata vars) external returns (uint256);
/**
* @notice Publishes a post to a given profile via signature with the specified parameters.
*
* @param vars A PostWithSigData struct containing the regular parameters and an EIP712Signature struct.
*
* @return An integer representing the post's publication ID.
*/
function postWithSig(DataTypes.PostWithSigData calldata vars) external;
function postWithSig(DataTypes.PostWithSigData calldata vars) external returns (uint256);
/**
* @notice Publishes a comment to a given profile, must be called by the profile owner.
*
* @param vars A CommentData struct containing the needed parameters.
*
* @return An integer representing the comment's publication ID.
*/
function comment(DataTypes.CommentData calldata vars) external;
function comment(DataTypes.CommentData calldata vars) external returns (uint256);
/**
* @notice Publishes a comment to a given profile via signature with the specified parameters.
*
*@param vars A CommentWithSigData struct containing the regular parameters and an EIP712Signature struct.
* @param vars A CommentWithSigData struct containing the regular parameters and an EIP712Signature struct.
*
* @return An integer representing the comment's publication ID.
*/
function commentWithSig(DataTypes.CommentWithSigData calldata vars) external;
function commentWithSig(DataTypes.CommentWithSigData calldata vars) external returns (uint256);
/**
* @notice Publishes a mirror to a given profile, must be called by the profile owner.
*
* @param vars A MirrorData struct containing the necessary parameters.
*
* @return An integer representing the mirror's publication ID.
*/
function mirror(DataTypes.MirrorData calldata vars) external;
function mirror(DataTypes.MirrorData calldata vars) external returns (uint256);
/**
* @notice Publishes a mirror to a given profile via signature with the specified parameters.
*
* @param vars A MirrorWithSigData struct containing the regular parameters and an EIP712Signature struct.
*
* @return An integer representing the mirror's publication ID.
*/
function mirrorWithSig(DataTypes.MirrorWithSigData calldata vars) external;
function mirrorWithSig(DataTypes.MirrorWithSigData calldata vars) external returns (uint256);
/**
* @notice Follows the given profiles, executing each profile's follow module logic (if any) and minting followNFTs to the caller.
@@ -230,16 +241,24 @@ interface ILensHub {
*
* @param profileIds The token ID array of the profiles to follow.
* @param datas The arbitrary data array to pass to the follow module for each profile if needed.
*
* @return An array of integers representing the minted follow NFTs token IDs.
*/
function follow(uint256[] calldata profileIds, bytes[] calldata datas) external;
function follow(uint256[] calldata profileIds, bytes[] calldata datas)
external
returns (uint256[] memory);
/**
* @notice Follows a given profile via signature with the specified parameters.
*
* @param vars A FollowWithSigData struct containing the regular parameters as well as the signing follower's address
* and an EIP712Signature struct.
*
* @return An array of integers representing the minted follow NFTs token IDs.
*/
function followWithSig(DataTypes.FollowWithSigData calldata vars) external;
function followWithSig(DataTypes.FollowWithSigData calldata vars)
external
returns (uint256[] memory);
/**
* @notice Collects a given publication, executing collect module logic and minting a collectNFT to the caller.
@@ -247,20 +266,24 @@ interface ILensHub {
* @param profileId The token ID of the profile that published the publication to collect.
* @param pubId The publication to collect's publication ID.
* @param data The arbitrary data to pass to the collect module if needed.
*
* @return An integer representing the minted token ID.
*/
function collect(
uint256 profileId,
uint256 pubId,
bytes calldata data
) external;
) external returns (uint256);
/**
* @notice Collects a given publication via signature with the specified parameters.
*
* @param vars A CollectWithSigData struct containing the regular parameters as well as the collector's address and
* an EIP712Signature struct.
*
* @return An integer representing the minted token ID.
*/
function collectWithSig(DataTypes.CollectWithSigData calldata vars) external;
function collectWithSig(DataTypes.CollectWithSigData calldata vars) external returns (uint256);
/**
* @dev Helper function to emit a detailed followNFT transfer event from the hub, to be consumed by frontends to track