-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgurupasstoken.sol
101 lines (84 loc) · 3.14 KB
/
gurupasstoken.sol
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
/*
This file is part of the Guru Collective DAO.
The GuruPassToken Contract is free software: you can redistribute it and/or
modify it under the terms of the GNU lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The GuruPassToken Contract is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU lesser General Public License for more details.
You should have received a copy of the GNU lesser General Public License
along with the GuruPassToken Contract. If not, see <http://www.gnu.org/licenses/>.
@author Ilya Svirin <[email protected]>
*/
// SPDX-License-Identifier: GNU lesser General Public License
pragma solidity ^0.8.0;
import "github.com/OpenZeppelin/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol";
import "github.com/OpenZeppelin/openzeppelin-contracts/contracts/access/Ownable.sol";
contract GuruPassToken is ERC721, Ownable
{
event Deployed();
event CustomMetaSet(uint256 indexed tokenId, string meta);
event MetaLoaderChanged(address indexed addr);
uint256 public tokensCounter;
address public metaLoader;
string public base;
string public defaultMeta;
mapping (uint256 => string) customMetas;
constructor() ERC721("Guru Collective", "Guru Pass")
{
setMetaLoader(_msgSender());
setBaseURI("https://ipfs.io/ipfs/");
setDefaultMeta("bafkreibop3ww35p6d5plr7kx5rvozqxcgxbnenodkk2txiv6bstgu5nfn4");
emit Deployed();
}
function setMetaLoader(address addr) public onlyOwner
{
metaLoader = addr;
emit MetaLoaderChanged(addr);
}
function setBaseURI(string memory baseURI) public onlyOwner
{
base = baseURI;
}
function setDefaultMeta(string memory meta) public onlyOwner
{
defaultMeta = meta;
}
function setCustomMeta(uint256 tokenId, string memory meta) public
{
require(_msgSender() == owner() || _msgSender() == metaLoader, "GuruPassToken: permission denied");
customMetas[tokenId] = meta;
emit CustomMetaSet(tokenId, meta);
}
function tokenURI(uint256 tokenId) public view virtual override returns (string memory)
{
require(_exists(tokenId), "GuruPassToken: URI query for nonexistent token");
string memory meta = customMetas[tokenId];
if(bytes(meta).length == 0)
{
meta = defaultMeta;
}
return string(abi.encodePacked(base, meta));
}
function safeMint(address recepient) public onlyOwner returns(uint256)
{
return _mintSingle(recepient);
}
function safeMintMulti(address recepient, uint256 amount) public onlyOwner returns(uint256)
{
uint256 last;
for(uint256 i = 0; i < amount; i++)
{
last = _mintSingle(recepient);
}
return last;
}
function _mintSingle(address recipient) internal returns(uint256)
{
tokensCounter++;
_safeMint(recipient, tokensCounter);
return tokensCounter;
}
}