-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnsDomain.sol
60 lines (46 loc) · 1.45 KB
/
EnsDomain.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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract ETHDaddy is ERC721 {
uint256 public maxSupply;
uint256 public totalSupply;
address public owner;
struct Domain {
string name;
uint256 cost;
bool isOwned;
}
mapping(uint256 => Domain) domains;
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
constructor(string memory _name, string memory _symbol)
ERC721(_name, _symbol)
{
owner = msg.sender;
}
function list(string memory _name, uint256 _cost) public onlyOwner {
maxSupply++;
domains[maxSupply] = Domain(_name, _cost, false);
}
function mint(uint256 _id) public payable {
require(_id != 0);
require(_id <= maxSupply);
require(domains[_id].isOwned == false);
require(msg.value >= domains[_id].cost);
domains[_id].isOwned = true;
totalSupply++;
_safeMint(msg.sender, _id);
}
function getDomain(uint256 _id) public view returns (Domain memory) {
return domains[_id];
}
function getBalance() public view returns (uint256) {
return address(this).balance;
}
function withdraw( ) public onlyOwner {
(bool success, ) = owner.call{value: address(this).balance}("");
require(success);
}
}