/// @title ERC-7432 非同质化代币角色
/// @dev See https://eips.ethereum.org/EIPS/eip-7432
/// Note: the ERC-165 identifier for this interface is 0xd00ca5cf.
interfaceIERC7432/* is ERC165 */{structRole{bytes32roleId;addresstokenAddress;uint256tokenId;addressrecipient;uint64expirationDate;boolrevocable;bytesdata;}/** Events **//// @notice Emitted when an NFT is locked (deposited or frozen).
/// @notice 当 NFT 被锁定(存入或冻结)时发出。
/// @param _owner The owner of the NFT.
/// @param _tokenAddress The token address.
/// @param _tokenId The token identifier.
eventTokenLocked(addressindexed_owner,addressindexed_tokenAddress,uint256_tokenId);/// @notice Emitted when a role is granted.
/// @notice 当角色被授予时发出。
/// @param _tokenAddress The token address.
/// @param _tokenId The token identifier.
/// @param _roleId The role identifier.
/// @param _owner The user assigning the role.
/// @param _recipient The user receiving the role.
/// @param _expirationDate The expiration date of the role.
/// @param _revocable Whether the role is revocable or not.
/// @param _data Any additional data about the role.
eventRoleGranted(addressindexed_tokenAddress,uint256indexed_tokenId,bytes32indexed_roleId,address_owner,address_recipient,uint64_expirationDate,bool_revocable,bytes_data);/// @notice Emitted when a role is revoked.
/// @notice 当角色被撤销时发出。
/// @param _tokenAddress The token address.
/// @param _tokenId The token identifier.
/// @param _roleId The role identifier.
eventRoleRevoked(addressindexed_tokenAddress,uint256indexed_tokenId,bytes32indexed_roleId);/// @notice Emitted when an NFT is unlocked (withdrawn or unfrozen).
/// @notice 当 NFT 被解锁(撤回或解冻)时发出。
/// @param _owner The original owner of the NFT.
/// @param _tokenAddress The token address.
/// @param _tokenId The token identifier.
eventTokenUnlocked(addressindexed_owner,addressindexed_tokenAddress,uint256indexed_tokenId);/// @notice Emitted when a user is approved to manage roles on behalf of another user.
/// @notice 当用户被批准代表另一个用户管理角色时发出。
/// @param _tokenAddress The token address.
/// @param _operator The user approved to grant and revoke roles.
/// @param _isApproved The approval status.
eventRoleApprovalForAll(addressindexed_tokenAddress,addressindexed_operator,boolindexed_isApproved);/** External Functions **//// @notice Grants a role to a user.
/// @notice 授予用户角色。
/// @dev Reverts if sender is not approved or the NFT owner.
/// @dev 如果发送者未被批准或不是 NFT 所有者,则还原。
/// @param _role The role attributes.
functiongrantRole(Rolecalldata_role)external;/// @notice Revokes a role from a user.
/// @notice 撤销用户的角色。
/// @dev Reverts if sender is not approved or the original owner.
/// @dev 如果发送者未被批准或不是原始所有者,则还原。
/// @param _tokenAddress The token address.
/// @param _tokenId The token identifier.
/// @param _roleId The role identifier.
functionrevokeRole(address_tokenAddress,uint256_tokenId,bytes32_roleId)external;/// @notice Unlocks NFT (transfer back to original owner or unfreeze it).
/// @notice 解锁 NFT(转移回原始所有者或解冻它)。
/// @dev Reverts if sender is not approved or the original owner.
/// @dev 如果发送者未被批准或不是原始所有者,则还原。
/// @param _tokenAddress The token address.
/// @param _tokenId The token identifier.
functionunlockToken(address_tokenAddress,uint256_tokenId)external;/// @notice Approves operator to grant and revoke roles on behalf of another user.
/// @notice 批准操作员代表另一个用户授予和撤销角色。
/// @param _tokenAddress The token address.
/// @param _operator The user approved to grant and revoke roles.
/// @param _approved The approval status.
functionsetRoleApprovalForAll(address_tokenAddress,address_operator,bool_approved)external;/** View Functions **//// @notice Retrieves the original owner of the NFT.
/// @notice 检索 NFT 的原始所有者。
/// @param _tokenAddress The token address.
/// @param _tokenId The token identifier.
/// @return owner_ The owner of the token.
functionownerOf(address_tokenAddress,uint256_tokenId)externalviewreturns(addressowner_);/// @notice Retrieves the recipient of an NFT role.
/// @notice 检索 NFT 角色的接收者。
/// @param _tokenAddress The token address.
/// @param _tokenId The token identifier.
/// @param _roleId The role identifier.
/// @return recipient_ The user that received the role.
functionrecipientOf(address_tokenAddress,uint256_tokenId,bytes32_roleId)externalviewreturns(addressrecipient_);/// @notice Retrieves the custom data of a role assignment.
/// @notice 检索角色分配的自定义数据。
/// @param _tokenAddress The token address.
/// @param _tokenId The token identifier.
/// @param _roleId The role identifier.
/// @return data_ The custom data of the role.
functionroleData(address_tokenAddress,uint256_tokenId,bytes32_roleId)externalviewreturns(bytesmemorydata_);/// @notice Retrieves the expiration date of a role assignment.
/// @notice 检索角色分配的到期日期。
/// @param _tokenAddress The token address.
/// @param _tokenId The token identifier.
/// @param _roleId The role identifier.
/// @return expirationDate_ The expiration date of the role.
functionroleExpirationDate(address_tokenAddress,uint256_tokenId,bytes32_roleId)externalviewreturns(uint64expirationDate_);/// @notice Verifies whether the role is revocable.
/// @notice 验证角色是否可撤销。
/// @param _tokenAddress The token address.
/// @param _tokenId The token identifier.
/// @param _roleId The role identifier.
/// @return revocable_ Whether the role is revocable.
functionisRoleRevocable(address_tokenAddress,uint256_tokenId,bytes32_roleId)externalviewreturns(boolrevocable_);/// @notice Verifies if the owner approved the operator.
/// @notice 验证所有者是否批准了操作员。
/// @param _tokenAddress The token address.
/// @param _owner The user that approved the operator.
/// @param _operator The user that can grant and revoke roles.
/// @return Whether the operator is approved.
functionisRoleApprovedForAll(address_tokenAddress,address_owner,address_operator)externalviewreturns(bool);}
{/** Existing NFT Metadata **//** 现有的 NFT 元数据 **/"title":"Asset Metadata","type":"object","properties":{"name":{"type":"string","description":"Identifies the asset to which this NFT represents"// "description": "标识此 NFT 代表的资产"},"description":{"type":"string","description":"Describes the asset to which this NFT represents"// "description": "描述此 NFT 代表的资产"},"image":{"type":"string","description":"A URI pointing to a resource with mime type image/* representing the asset to which this NFT represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive"// "description": "指向具有 mime 类型 image/* 的资源的 URI,表示此 NFT 代表的资产。考虑制作宽度在 320 到 1080 像素之间,宽高比在 1.91:1 到 4:5 之间的任何图像"}},/** Additional fields for Roles **//** 角色的附加字段 **/"roles":[{"id":{"type":"bytes32","description":"Identifies the role"// "description": "标识角色"},"name":{"type":"string","description":"Human-readable name of the role"// "description": "角色的可读名称"},"description":{"type":"string","description":"Describes the role"// "description": "描述角色"},"inputs":[{"name":{"type":"string","description":"Human-readable name of the argument"// "description": "参数的可读名称"},"type":{"type":"string","description":"Solidity type, e.g., uint256 or address"// "description": "Solidity 类型,例如,uint256 或 address"}}]}]}
{// ... Existing NFT Metadata// ... 现有的 NFT 元数据"roles":[{// keccak256("PropertyManager()")"id":"0x76be0ffb73d8cd9e8fa76c28632ebbc3865a8ec7a0b6acab6ac589a1c88dd301","name":"Property Manager","description":"The manager of the property is responsible for furnishing it and ensuring its good condition.",// "description": "房产经理负责提供家具并确保其良好状况。""inputs":[]},{// keccak256("PropertyTenant(uint256)")"id":"0x17dfc8ea82661b71bd62ce0bd9db3858dd8f3e8ab9799d6ab468ec64f1be21a5","name":"Property Tenant","description":"The tenant of the property is responsible for paying the rent and keeping the property in good condition.",// "description": "房产租户负责支付租金并保持房产的良好状况。""inputs":[{"name":"rent","type":"uint256"}]}]}
建议使用 roles 数组属性,开发人员应根据需要添加任何其他相关信息(例如,角色的图像)。 同样重要的是要强调 inputs 属性的重要性。 此字段描述了应编码并传递给 grantRole 函数的参数。 建议使用在 Solidity ABI Specification 上定义的属性 type 和 components,其中 type 是参数的规范类型,components 用于复杂的元组类型。
Ernani São Thiago (@ernanirst), Daniel Lima (@karacurt), "ERC-7432: 非同质化代币角色," Ethereum Improvement Proposals, no. 7432, July 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7432.