Skip to content

Commit

Permalink
Adds new interface for extended catalog, to easily identify the new i…
Browse files Browse the repository at this point in the history
…mplementation.
  • Loading branch information
steven2308 committed Mar 1, 2024
1 parent 9b215cc commit c5bad77
Show file tree
Hide file tree
Showing 10 changed files with 539 additions and 82 deletions.
71 changes: 71 additions & 0 deletions contracts/implementations/catalog/IRMRKCatalogExtended.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.21;

import {IRMRKCatalog} from "../../RMRK/catalog/IRMRKCatalog.sol";

/**
* @title IRMRKCatalogExtended
* @author RMRK team
* @notice An extended interface for Catalog for RMRK equippable module.
*/
interface IRMRKCatalogExtended is IRMRKCatalog {
/**
* @notice From ERC7572 (Draft) Emitted when the contract-level metadata is updated
*/
event ContractURIUpdated();

/**
* @notice Emited when the type of the catalog is updated
* @param newType The new type of the catalog
*/
event TypeUpdated(string newType);

/**
* @notice Used to get all the part IDs in the catalog.
* @dev Can get at least 10k parts. Higher limits were not tested.
* @dev It may fail if there are too many parts, in that case use either `getPaginatedPartIds` or `getTotalParts` and `getPartByIndex`.
* @return partIds An array of all the part IDs in the catalog
*/
function getAllPartIds() external view returns (uint64[] memory partIds);

/**
* @notice Used to get all the part IDs in the catalog.
* @param offset The offset to start from
* @param limit The maximum number of parts to return
* @return partIds An array of all the part IDs in the catalog
*/
function getPaginatedPartIds(
uint256 offset,
uint256 limit
) external view returns (uint64[] memory partIds);

/**
* @notice Used to get the total number of parts in the catalog.
* @return totalParts The total number of parts in the catalog
*/
function getTotalParts() external view returns (uint256 totalParts);

/**
* @notice Used to get a single `Part` by the index of its `partId`.
* @param index The index of the `partId`.
* @return part The `Part` struct associated with the `partId` at the given index
*/
function getPartByIndex(
uint256 index
) external view returns (Part memory part);

/**
* @notice Used to set the metadata URI of the catalog.
* @param newContractURI The new metadata URI
* @dev emits `ContractURIUpdated` event
*/
function setMetadataURI(string memory newContractURI) external;

/**
* @notice Used to set the type of the catalog.
* @param newType The new type of the catalog
* @dev emits `TypeUpdated` event
*/
function setType(string memory newType) external;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

pragma solidity ^0.8.21;

import {OwnableLock} from "../RMRK/access/OwnableLock.sol";
import {RMRKCatalog} from "../RMRK/catalog/RMRKCatalog.sol";
import {OwnableLock} from "../../RMRK/access/OwnableLock.sol";
import {RMRKCatalog, IERC165} from "../../RMRK/catalog/RMRKCatalog.sol";
import {IRMRKCatalogExtended} from "./IRMRKCatalogExtended.sol";

/**
* @title RMRKCatalogImpl
Expand All @@ -13,18 +14,7 @@ import {RMRKCatalog} from "../RMRK/catalog/RMRKCatalog.sol";
* This default implementation includes an OwnableLock dependency, which allows the deployer to freeze the state of the
* catalog contract.
*/
contract RMRKCatalogImpl is OwnableLock, RMRKCatalog {
/**
* @notice From ERC7572 (Draft) Emitted when the contract-level metadata is updated
*/
event ContractURIUpdated();

/**
* @notice Emited when the type of the catalog is updated
* @param newType The new type of the catalog
*/
event TypeUpdated(string newType);

contract RMRKCatalogImpl is OwnableLock, RMRKCatalog, IRMRKCatalogExtended {
/**
* @notice Used to initialize the smart contract.
* @param metadataURI Base metadata URI of the contract
Expand Down Expand Up @@ -134,20 +124,14 @@ contract RMRKCatalogImpl is OwnableLock, RMRKCatalog {
}

/**
* @notice Used to get all the part IDs in the catalog.
* @dev Can get at least 10k parts. Higher limits were not tested.
* @dev It may fail if there are too many parts, in that case use either `getPaginatedPartIds` or `getTotalParts` and `getPartByIndex`.
* @return partIds An array of all the part IDs in the catalog
* @inheritdoc IRMRKCatalogExtended
*/
function getAllPartIds() public view returns (uint64[] memory partIds) {
partIds = _partIds;
}

/**
* @notice Used to get all the part IDs in the catalog.
* @param offset The offset to start from
* @param limit The maximum number of parts to return
* @return partIds An array of all the part IDs in the catalog
* @inheritdoc IRMRKCatalogExtended
*/
function getPaginatedPartIds(
uint256 offset,
Expand All @@ -165,35 +149,49 @@ contract RMRKCatalogImpl is OwnableLock, RMRKCatalog {
}

/**
* @notice Used to get the total number of parts in the catalog.
* @return totalParts The total number of parts in the catalog
* @inheritdoc IRMRKCatalogExtended
*/
function getTotalParts() public view returns (uint256 totalParts) {
totalParts = _partIds.length;
}

/**
* @notice Used to get a single `Part` by the index of its `partId`.
* @param index The index of the `partId`.
* @return part The `Part` struct associated with the `partId` at the given index
* @inheritdoc IRMRKCatalogExtended
*/
function getPartByIndex(
uint256 index
) public view returns (Part memory part) {
part = getPart(_partIds[index]);
}

/**
* @inheritdoc IRMRKCatalogExtended
*/
function setMetadataURI(
string memory newContractURI
) public virtual onlyOwnerOrContributor {
_setMetadataURI(newContractURI);
emit ContractURIUpdated();
}

/**
* @inheritdoc IRMRKCatalogExtended
*/
function setType(
string memory newType
) public virtual onlyOwnerOrContributor {
_setType(newType);
emit TypeUpdated(newType);
}

/**
* @inheritdoc IERC165
*/
function supportsInterface(
bytes4 interfaceId
) public view virtual override(RMRKCatalog, IERC165) returns (bool) {
return
interfaceId == type(IRMRKCatalogExtended).interfaceId ||
super.supportsInterface(interfaceId);
}
}
Loading

0 comments on commit c5bad77

Please sign in to comment.