-
-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathnf-token-metadata-base-uri-mock.sol
More file actions
110 lines (102 loc) · 2.19 KB
/
nf-token-metadata-base-uri-mock.sol
File metadata and controls
110 lines (102 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../tokens/nf-token-metadata.sol";
import "../ownership/ownable.sol";
/**
* @dev This is an example contract implementation of NFToken with metadata extension.
*/
contract NFTokenMetadataBaseUriMock is
NFTokenMetadata,
Ownable
{
/**
* @dev URI base for tokenURI function. Token URI is constructed as baseURI + tokenId.
*/
string public baseURI;
/**
* @dev Contract constructor.
* @param _name A descriptive name for a collection of NFTs.
* @param _symbol An abbreviated name for NFTokens.
* @param _baseURI String representing base RFC 3986 URI.
*/
constructor(
string memory _name,
string memory _symbol,
string memory _baseURI
)
{
nftName = _name;
nftSymbol = _symbol;
baseURI = _baseURI;
}
/**
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function mint(
address _to,
uint256 _tokenId
)
external
onlyOwner
{
super._mint(_to, _tokenId);
}
/**
* @dev Removes a NFT from owner.
* @param _tokenId Which NFT we want to remove.
*/
function burn(
uint256 _tokenId
)
external
onlyOwner
{
super._burn(_tokenId);
}
/**
* @dev A distinct URI (RFC 3986) for a given NFT.
* @param _tokenId Id for which we want uri.
* @return URI of _tokenId.
*/
function _tokenURI(
uint256 _tokenId
)
internal
override
view
returns (string memory)
{
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, _uint2str(_tokenId))) : "";
}
/**
* @dev Helper function that changes uint to string representation.
* @return str String representation.
*/
function _uint2str(
uint256 _i
)
internal
pure
returns (string memory str)
{
if (_i == 0) {
return "0";
}
uint256 j = _i;
uint256 length;
while (j != 0) {
length++;
j /= 10;
}
bytes memory bstr = new bytes(length);
uint256 k = length;
j = _i;
while (j != 0) {
bstr[--k] = bytes1(uint8(48 + j % 10));
j /= 10;
}
str = string(bstr);
}
}