Skip to content

Commit

Permalink
yan
Browse files Browse the repository at this point in the history
  • Loading branch information
yanning committed Jul 27, 2022
1 parent 7999d11 commit 8c5e27a
Showing 1 changed file with 4 additions and 88 deletions.
92 changes: 4 additions & 88 deletions EIPS/eip-5334.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
eip: 5334
title: 721 User And Expires And Level Extension
description: Add a time-limited role with restricted permissions to [EIP-721] tokens.
title: [`ERC-721`] User And Expires And Level Extension
description: Add a time-limited role with restricted permissions to [`ERC-721`] tokens.
author: Yan (@yan253319066)
discussions-to: https://ethereum-magicians.org/t/erc-721-user-and-expires-and-level-extension/10097
status: Draft
Expand Down Expand Up @@ -101,92 +101,8 @@ As mentioned in the specifications section, this standard can be fully EIP-721 c
In addition, new functions introduced in this standard have many similarities with the existing functions in EIP-721. This allows developers to easily adopt the standard quickly.

## Reference Implementation
[`ERC5334`] Implementation: [`ERC5334.sol`](../assets/eip-5334/ERC5334.sol)
```solidity
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "./IERC5334.sol";
contract ERC5334 is ERC721, IERC5334 {
struct UserInfo
{
address user; // address of user role
uint64 expires; // unix timestamp, user expires
uint8 level; // user level
}
mapping (uint256 => UserInfo) internal _users;
constructor(string memory name_, string memory symbol_)
ERC721(name_,symbol_)
{
}
/// @notice set the user and expires and level of a NFT
/// @dev The zero address indicates there is no user
/// Throws if `tokenId` is not valid NFT
/// @param user The new user of the NFT
/// @param expires UNIX timestamp, The new user could use the NFT before expires
/// @param level user level
function setUser(uint256 tokenId, address user, uint64 expires, uint8 level) public virtual{
require(_isApprovedOrOwner(msg.sender, tokenId),"ERC721: transfer caller is not owner nor approved");
UserInfo storage info = _users[tokenId];
info.user = user;
info.expires = expires;
info.level = level
emit UpdateUser(tokenId,user,expires,level);
}
/// @notice Get the user address of an NFT
/// @dev The zero address indicates that there is no user or the user is expired
/// @param tokenId The NFT to get the user address for
/// @return The user address for this NFT
function userOf(uint256 tokenId)public view virtual returns(address){
if( uint256(_users[tokenId].expires) >= block.timestamp){
return _users[tokenId].user;
}
else{
return address(0);
}
}
/// @notice Get the user expires of an NFT
/// @dev The zero value indicates that there is no user
/// @param tokenId The NFT to get the user expires for
/// @return The user expires for this NFT
function userExpires(uint256 tokenId) public view virtual returns(uint256){
return _users[tokenId].expires;
}
/// @notice Get the user level of an NFT
/// @dev The zero value indicates that there is no user
/// @param tokenId The NFT to get the user level for
/// @return The user level for this NFT
function userLevel(uint256 tokenId) public view virtual returns(uint256){
return _users[tokenId].level;
}
/// @dev See {IERC165-supportsInterface}.
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC5334).interfaceId || super.supportsInterface(interfaceId);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override{
super._beforeTokenTransfer(from, to, tokenId);
if (from != to && _users[tokenId].user != address(0)) {
delete _users[tokenId];
emit UpdateUser(tokenId, address(0), 0, 0);
}
}
}
```
A reference implementation of this standard can be found in the assets folder.
<!-- [../assets/EIP-5334/ERC5334.sol](../assets/EIP-5334/ERC5334.sol). -->

## Security Considerations

Expand Down

0 comments on commit 8c5e27a

Please sign in to comment.