Skip to content

Commit

Permalink
Adding support register IP Asset with mediaURL
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster-will committed Nov 18, 2023
1 parent 2653961 commit ed9edc5
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ interface IRegistrationModule {
/// @param name_ The name of the IP asset being registered.
/// @param ipAssetType_ The numerical id of the IP asset type.
/// @param hash_ The content hash of the registered IP asset.
/// @param mediaUrl_ The media URL of the registered IP asset.
event IPAssetRegistered(
uint256 ipAssetId_,
address indexed ipOrg_,
uint256 ipOrgAssetId_,
address indexed owner_,
string name_,
uint64 indexed ipAssetType_,
bytes32 hash_
bytes32 hash_,
string mediaUrl_
);

/// @notice Emits when an IP asset is transferred to a new owner.
Expand Down
1 change: 1 addition & 0 deletions contracts/lib/IPAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ library IPAsset {
uint64 ipAssetType;
address owner;
bytes32 hash;
string mediaUrl;
}

struct CreateIpAssetParams {
Expand Down
1 change: 1 addition & 0 deletions contracts/lib/modules/Registration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ library Registration {
string name;
uint64 ipAssetType;
bytes32 hash;
string mediaUrl;
}

// TODO(leeren): Change in favor of granular function-selector based auth.
Expand Down
21 changes: 18 additions & 3 deletions contracts/modules/registration/RegistrationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ contract RegistrationModule is BaseModule, IRegistrationModule, AccessControlled
/// @notice Reverse lookup from IP Org asset to global IP asset ids.
mapping(address => mapping(uint256 => uint256)) public ipAssetId;

/// @notice IP Org asset to its tokenURI.
mapping(address => mapping(uint256 => string)) public tokenUris;

/// @notice Initializes the registration module.
constructor(
BaseModule.ModuleConstruction memory params_,
Expand Down Expand Up @@ -79,6 +82,12 @@ contract RegistrationModule is BaseModule, IRegistrationModule, AccessControlled
revert Errors.RegistrationModule_IPAssetNonExistent();
}

// If the token URI has been set to specific IP Org asset, return it.
// It overrides the base URI.
if (bytes(tokenUris[ipOrg_][ipOrgAssetId_]).length > 0) {
return tokenUris[ipOrg_][ipOrgAssetId_];
}

Registration.IPOrgConfig memory config = ipOrgConfigs[ipOrg_];
if (bytes(config.baseURI).length != 0) {
return string(abi.encodePacked(config.baseURI, Strings.toString(id)));
Expand Down Expand Up @@ -185,7 +194,7 @@ contract RegistrationModule is BaseModule, IRegistrationModule, AccessControlled
return "";
} else if (executionType == Registration.REGISTER_IP_ASSET) {
Registration.RegisterIPAssetParams memory params = abi.decode(executionData, (Registration.RegisterIPAssetParams));
(uint256 ipAssetId__, uint256 ipOrgAssetId) = _registerIPAsset(ipOrg_, params.owner, params.name, params.ipAssetType, params.hash);
(uint256 ipAssetId__, uint256 ipOrgAssetId) = _registerIPAsset(ipOrg_, params.owner, params.name, params.ipAssetType, params.hash, params.mediaUrl);
return abi.encode(ipAssetId__, ipOrgAssetId);
}
return "";
Expand All @@ -197,12 +206,14 @@ contract RegistrationModule is BaseModule, IRegistrationModule, AccessControlled
/// @param name_ A descriptive name for the IP asset being registered.
/// @param ipAssetType_ A numerical identifier for the IP asset type.
/// @param hash_ The content hash of the IP asset being registered.
/// @param mediaUrl_ The media URL of the IP asset being registered.
function _registerIPAsset(
IIPOrg ipOrg_,
address owner_,
string memory name_,
uint64 ipAssetType_,
bytes32 hash_
bytes32 hash_,
string memory mediaUrl_
) internal returns (uint256 ipAssetId_, uint256 ipOrgAssetId_) {
ipAssetId_ = IPA_REGISTRY.register(
address(ipOrg_),
Expand All @@ -215,14 +226,18 @@ contract RegistrationModule is BaseModule, IRegistrationModule, AccessControlled
ipAssetId[address(ipOrg_)][ipOrgAssetId_] = ipAssetId_;
IPOrgAsset memory ipOrgAsset = IPOrgAsset(address(ipOrg_), ipOrgAssetId_);
ipOrgAssets[ipAssetId_] = ipOrgAsset;
if (bytes(mediaUrl_).length > 0) {
tokenUris[address(ipOrg_)][ipOrgAssetId_] = mediaUrl_;
}
emit IPAssetRegistered(
ipAssetId_,
address(ipOrg_),
ipOrgAssetId_,
owner_,
name_,
ipAssetType_,
hash_
hash_,
mediaUrl_
);
}

Expand Down
42 changes: 38 additions & 4 deletions test/foundry/modules/registration/RegistrationTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ contract RegistrationModuleTest is BaseTest {
address indexed owner_,
string name_,
uint64 indexed ipAssetType_,
bytes32 hash_
bytes32 hash_,
string mediaUrl_
);

// Id of IP asset which may differ per test based on testing constraints.
Expand Down Expand Up @@ -116,13 +117,44 @@ contract RegistrationModuleTest is BaseTest {
cal,
"TestIPA",
0,
"",
""
);
_register(address(ipOrg), cal, "TestIPA", 0, "");
_register(address(ipOrg), cal, "TestIPA", 0, "", "");
assertEq(registry.ipAssetOwner(0), cal);
assertEq(ipOrg.ownerOf(0), cal);
}

/// @notice Tests IP Asset registration with media URL.
function test_RegistrationModuleIPARegistrationWithMediaUrl() public virtual {
string memory mediaUrl = "http://token.url";
vm.prank(cal);
vm.expectEmit(true, true, true, true, address(registry));
emit Registered(
0,
"TestIPA",
0,
address(ipOrg),
cal,
""
);
vm.expectEmit(true, true, true, true, address(registrationModule));
emit IPAssetRegistered(
0,
address(ipOrg),
0,
cal,
"TestIPA",
0,
"",
mediaUrl
);
_register(address(ipOrg), cal, "TestIPA", 0, "", mediaUrl);
assertEq(registry.ipAssetOwner(0), cal);
assertEq(ipOrg.ownerOf(0), cal);
assertEq(mediaUrl, registrationModule.tokenURI(address(ipOrg), 0));
}

/// @dev Helper function that performs registration.
/// @param ipOrg_ Address of the ipOrg of the IP asset.
/// @param owner_ Address of the owner of the IP asset.
Expand All @@ -134,13 +166,15 @@ contract RegistrationModuleTest is BaseTest {
address owner_,
string memory name_,
uint64 ipAssetType_,
bytes32 hash_
bytes32 hash_,
string memory mediaUrl_
) internal virtual returns (uint256, uint256) {
Registration.RegisterIPAssetParams memory params = Registration.RegisterIPAssetParams({
owner: owner_,
name: name_,
ipAssetType: ipAssetType_,
hash: hash_
hash: hash_,
mediaUrl: mediaUrl_
});
bytes[] memory hooks = new bytes[](0);
return spg.registerIPAsset(address(ipOrg), params, hooks, hooks);
Expand Down
3 changes: 2 additions & 1 deletion test/foundry/utils/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ contract BaseTest is BaseTestUtils, ProxyHelper, AccessControlHelper {
owner: ipAssetOwner,
name: "TestIPAsset",
ipAssetType: 0,
hash: ""
hash: "",
mediaUrl: ""
});
bytes[] memory hooks = new bytes[](0);
(uint256 globalId, uint256 localId) = spg.registerIPAsset(address(ipOrg), params, hooks, hooks);
Expand Down

0 comments on commit ed9edc5

Please sign in to comment.