-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnwithErc721.sol
87 lines (69 loc) · 2.92 KB
/
EnwithErc721.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract EnwithErc721 is ERC721, ERC721Burnable, Ownable {
mapping(address => string) public addresses;
mapping(string => address) public names;
mapping(string => address) public creators;
mapping(address => bool) public nameCreationStatus;
mapping(uint256 => string) public IdToName;
mapping(string => uint256) public NameToId;
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
constructor() ERC721("MyToken", "MTK") {}
function createName(string memory name) public {
require(names[name] == address(0), "Name already exists");
require(!nameCreationStatus[msg.sender], "You have already created a name");
creators[name] = msg.sender;
names[name] = msg.sender;
addresses[msg.sender] = name;
nameCreationStatus[msg.sender] = true;
uint256 tokenId = _tokenIdCounter.current() + 1;
_tokenIdCounter.increment();
_safeMint(msg.sender, tokenId);
IdToName[tokenId] = name;
NameToId[name] = tokenId;
}
function transferName(string memory name, address newOwner) public {
require(names[name] == msg.sender, "You don't own this name");
//Requirement to check if the receiver already has
require(!nameCreationStatus[newOwner], "New Owner Already has a name");
names[name] = newOwner;
addresses[newOwner] = name;
addresses[msg.sender] = "";
nameCreationStatus[msg.sender] = false;
safeTransferFrom(msg.sender, newOwner, NameToId[name]);
nameCreationStatus[newOwner] = true;
}
function ChangeName(string memory NewName, string memory name) public
{
require(names[name] == msg.sender, "You don't own this name");
NameToId[NewName] = NameToId[name];
IdToName[NameToId[name]] = NewName;
creators[NewName] = msg.sender;
names[NewName] = msg.sender;
addresses[msg.sender] = NewName;
creators[name] = address(0);
names[name] = address(0);
NameToId[name] = 0;
}
function deleteName(string memory name) public {
require(names[name] == msg.sender, "You don't own this name");
addresses[msg.sender] = "";
delete names[name];
delete creators[name];
nameCreationStatus[msg.sender] = false;
//Make Sure you set name to id to be zero also
IdToName[NameToId[name]] = "";
NameToId[name] = 0;
}
function getCreator(string memory name) public view returns (address) {
return creators[name];
}
function getOwner(string memory name) public view returns (address) {
return names[name];
}
}