Skip to content

Commit

Permalink
feat: typed nft base
Browse files Browse the repository at this point in the history
  • Loading branch information
seinmyung25 committed Jan 4, 2024
1 parent a6f7e43 commit 7e5474d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
5 changes: 4 additions & 1 deletion contracts/token/ERC721/ERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ERC721IdenticalResourceUpgradeable } from "./ERC721IdenticalResourceUpg
import { ERC721PausableUpgradeable } from "./ERC721PausableUpgradeable.sol";
import { IERC721Queryable, ERC721QueryableUpgradeable } from "./ERC721QueryableUpgradeable.sol";
import { IERC721SequencialMintUpbradeable, ERC721SequencialMintUpbradeable } from "./ERC721SequencialMintUpbradeable.sol";
import { ERC721TypedUpgradeable } from "./ERC721TypedUpgradeable.sol";
import { IERC721TypedResource, ERC721TypedUpgradeable } from "./ERC721TypedUpgradeable.sol";

interface INFT_Mintable is IERC721SequencialMintUpbradeable, IERC721Queryable {

Expand Down Expand Up @@ -94,7 +94,10 @@ contract NFT_Identical is
}
}

interface INFT_Typed is INFT_Mintable, IERC721TypedResource {}

contract NFT_Typed is
INFT_Typed,
NFT_Mintable,
ERC721TypedUpgradeable
{
Expand Down
18 changes: 9 additions & 9 deletions contracts/token/ERC721/ERC721TypedUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface IERC721TypedResource is IERC721SequencialMintUpbradeable {
event TokenType(uint256 indexed tokenId, uint256 indexed _tokenType);

function tokenType(uint256 tokenId) external view returns (uint256);
function setTokenType(uint256 tokenId, uint256 _tokenType) external;

function setTypeURI(uint256 _tokenType, string memory typedURI) external;
function typedMint(address to, uint256 _tokenType) external returns (uint256 tokenId);
Expand Down Expand Up @@ -43,23 +44,19 @@ abstract contract ERC721TypedUpgradeable is
return _getERC721TypedUpgradeable().tokenTypes[tokenId];
}

function tokenURI(uint256 tokenId) public view virtual override(IERC721Metadata, ERC721Upgradeable) returns (string memory typedURI) {
function tokenURI(uint256 tokenId) public view virtual override(IERC721Metadata, ERC721Upgradeable) returns (string memory uri) {
_requireOwned(tokenId);
ERC721TypedUpgradeableStorage storage $ = _getERC721TypedUpgradeable();

uint256 _tokenType = $.tokenTypes[tokenId];
if(_tokenType == 0) return super.tokenURI(tokenId);

typedURI = $.typeURIs[_tokenType];
require(bytes(typedURI).length != 0, "None URI");
uri = $.typeURIs[ $.tokenTypes[tokenId] ];
require(bytes(uri).length != 0, "None URI");
}

function _setTokenType(uint256 tokenId, uint256 _tokenType) internal virtual {
ERC721TypedUpgradeableStorage storage $ = _getERC721TypedUpgradeable();

require(_tokenType != 0, "default type");
require(bytes($.typeURIs[_tokenType]).length != 0, "None URI");
require($.tokenTypes[tokenId] == 0, "type immutable");
require($.tokenTypes[tokenId] != _tokenType, "token type");
$.tokenTypes[tokenId] = _tokenType;

emit TokenType(tokenId, _tokenType);
Expand All @@ -76,12 +73,15 @@ abstract contract ERC721TypedUpgradeable is
}

function setTypeURI(uint256 _tokenType, string memory typedURI) public override onlyAdmin {
require(_tokenType != 0, "default type");
require(bytes(typedURI).length != 0, "URI length");
_getERC721TypedUpgradeable().typeURIs[_tokenType] = typedURI;
}

function typedMint(address to, uint256 _tokenType) public override onlyAdmin returns (uint256 tokenId) {
tokenId = _typedMint(to, _tokenType);
}

function setTokenType(uint256 tokenId, uint256 _tokenType) public override onlyAdmin {
return _setTokenType(tokenId, _tokenType);
}
}

0 comments on commit 7e5474d

Please sign in to comment.