From 5d8095172eb15edb1759fd1b877f18645e1f8628 Mon Sep 17 00:00:00 2001 From: donosonaumczuk Date: Tue, 15 Aug 2023 21:01:10 +0100 Subject: [PATCH] feat: Profile creation and follow module set event flow improved Co-authored-by: Victor Naumik --- contracts/libraries/ProfileLib.sol | 40 ++++++++++-------------- contracts/libraries/constants/Events.sol | 5 --- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/contracts/libraries/ProfileLib.sol b/contracts/libraries/ProfileLib.sol index 39da7a4..5b0d987 100644 --- a/contracts/libraries/ProfileLib.sol +++ b/contracts/libraries/ProfileLib.sol @@ -44,31 +44,15 @@ library ProfileLib { Types.Profile storage _profile = StorageLib.getProfile(profileId); _profile.imageURI = createProfileParams.imageURI; - bytes memory followModuleReturnData; - if (createProfileParams.followModule != address(0)) { - // Load the follow module to be used in the next assembly block. - address followModule = createProfileParams.followModule; - - StorageLib.getProfile(profileId).followModule = followModule; - - // We don't need to check for deprecated modules here because deprecated ones are no longer whitelisted. - // Initialize the follow module. - followModuleReturnData = _initFollowModule({ - profileId: profileId, - transactionExecutor: msg.sender, - followModule: createProfileParams.followModule, - followModuleInitData: createProfileParams.followModuleInitData - }); - } emit Events.ProfileCreated( profileId, msg.sender, createProfileParams.to, createProfileParams.imageURI, - createProfileParams.followModule, - followModuleReturnData, block.timestamp ); + + _setFollowModule(profileId, createProfileParams.followModule, createProfileParams.followModuleInitData); } /** @@ -94,12 +78,7 @@ library ProfileLib { address followModule, bytes calldata followModuleInitData ) external { - StorageLib.getProfile(profileId).followModule = followModule; - bytes memory followModuleReturnData; - if (followModule != address(0)) { - followModuleReturnData = _initFollowModule(profileId, msg.sender, followModule, followModuleInitData); - } - emit Events.FollowModuleSet(profileId, followModule, followModuleReturnData, block.timestamp); + _setFollowModule(profileId, followModule, followModuleInitData); } function setProfileMetadataURI(uint256 profileId, string calldata metadataURI) external { @@ -287,4 +266,17 @@ library ProfileLib { } return configSwitched; } + + function _setFollowModule( + uint256 profileId, + address followModule, + bytes calldata followModuleInitData + ) private { + StorageLib.getProfile(profileId).followModule = followModule; + bytes memory followModuleReturnData; + if (followModule != address(0)) { + followModuleReturnData = _initFollowModule(profileId, msg.sender, followModule, followModuleInitData); + } + emit Events.FollowModuleSet(profileId, followModule, followModuleReturnData, block.timestamp); + } } diff --git a/contracts/libraries/constants/Events.sol b/contracts/libraries/constants/Events.sol index f54c287..766053f 100644 --- a/contracts/libraries/constants/Events.sol +++ b/contracts/libraries/constants/Events.sol @@ -110,9 +110,6 @@ library Events { * @param creator The profile creator, who created the token with the given profile ID. * @param to The address receiving the profile with the given profile ID. * @param imageURI The image URI set for the profile. - * @param followModule The profile's newly set follow module. This CAN be the zero address. - * @param followModuleReturnData The data returned from the follow module's initialization. This is ABI-encoded - * and totally depends on the follow module chosen. * @param timestamp The current block timestamp. */ event ProfileCreated( @@ -120,8 +117,6 @@ library Events { address indexed creator, address indexed to, string imageURI, - address followModule, - bytes followModuleReturnData, uint256 timestamp );