Skip to content

Commit

Permalink
add hooksRegistry function to modules
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster-will committed Nov 16, 2023
1 parent 58db156 commit 661b76c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
22 changes: 21 additions & 1 deletion contracts/modules/registration/RegistrationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ contract RegistrationModule is BaseModule, IRegistrationModule, AccessControlled
address accessControl_
) BaseModule(params_) AccessControlled(accessControl_) {}


/// @notice Registers hooks for a specific type and IP Org.
/// @dev This function can only be called by the IP Org owner.
/// @param hType_ The type of the hooks to register.
/// @param ipOrg_ The IP Org for which the hooks are being registered.
/// @param hooks_ The addresses of the hooks to register.
/// @param hooksConfig_ The configurations for the hooks.
function registerHooks(
HookType hType_,
IIPOrg ipOrg_,
address[] calldata hooks_,
bytes[] calldata hooksConfig_
) external onlyIpOrgOwner(ipOrg_) {
bytes32 registryKey = _generateRegistryKey(ipOrg_);
registerHooks(hType_, ipOrg_, registryKey, hooks_, hooksConfig_);
}

/// @notice Gets the contract URI for an IP Org.
/// @param ipOrg_ The address of the IP Org.
function contractURI(address ipOrg_) public view returns (string memory) {
Expand Down Expand Up @@ -283,7 +300,10 @@ contract RegistrationModule is BaseModule, IRegistrationModule, AccessControlled
address,
bytes calldata
) internal view virtual override returns(bytes32) {
return keccak256(abi.encode(address(ipOrg_), "REGISTRATION"));
return _generateRegistryKey(ipOrg_);
}

function _generateRegistryKey(IIPOrg ipOrg_) private pure returns(bytes32) {
return keccak256(abi.encode(address(ipOrg_), "REGISTRATION"));
}
}
26 changes: 24 additions & 2 deletions contracts/modules/relationships/RelationshipModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,25 @@ contract RelationshipModule is BaseModule, IRelationshipModule, AccessControlled
address accessControl_
) BaseModule(params_) AccessControlled(accessControl_) {}



/// @notice Registers hooks for a specific hook type, based on IP Org and relationship type.
/// @dev This function can only be called by the IP Org owner.
/// @param hType_ The type of the hooks to register.
/// @param ipOrg_ The IP Org for which the hooks are being registered.
/// @param relType_ The relationship type for which the hooks are being registered.
/// @param hooks_ The addresses of the hooks to register.
/// @param hooksConfig_ The configurations for the hooks.
function registerHooks(
HookType hType_,
IIPOrg ipOrg_,
string calldata relType_,
address[] calldata hooks_,
bytes[] calldata hooksConfig_
) external onlyIpOrgOwner(ipOrg_) {
bytes32 registryKey = _generateRegistryKey(ipOrg_, relType_);
registerHooks(hType_, ipOrg_, registryKey, hooks_, hooksConfig_);
}

/// Gets relationship type definition for a given relationship type name
/// Will revert if no relationship type is found
/// @param ipOrg_ IP Org address or zero address for protocol level relationships
Expand Down Expand Up @@ -242,6 +260,10 @@ contract RelationshipModule is BaseModule, IRelationshipModule, AccessControlled
bytes calldata params_
) internal view virtual override returns(bytes32) {
LibRelationship.CreateRelationshipParams memory createParams = abi.decode(params_, (LibRelationship.CreateRelationshipParams));
return keccak256(abi.encode(address(ipOrg_), createParams.relType));
return _generateRegistryKey(ipOrg_, createParams.relType);
}

function _generateRegistryKey(IIPOrg ipOrg_, string memory relType_) private pure returns(bytes32) {
return keccak256(abi.encode(address(ipOrg_), relType_));
}
}

0 comments on commit 661b76c

Please sign in to comment.