-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenEditionERC721.rb
56 lines (45 loc) · 1.49 KB
/
OpenEditionERC721.rb
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
pragma :rubidity, "1.0.0"
import 'ERC721'
contract :OpenEditionERC721, is: :ERC721 do
string :public, :contentURI
uint256 :public, :maxPerAddress
uint256 :public, :totalSupply
string :public, :description
datetime :public, :mintStart
datetime :public, :mintEnd
constructor(
name: :string,
symbol: :string,
contentURI: :string,
maxPerAddress: :uint256,
description: :string,
mintStart: :datetime,
mintEnd: :datetime
) {
ERC721.constructor(name: name, symbol: symbol)
s.maxPerAddress = maxPerAddress
s.description = description
s.contentURI = contentURI
s.mintStart = mintStart
s.mintEnd = mintEnd
}
function :mint, { amount: :uint256 }, :public, returns: :uint256 do
require(amount > 0, 'Amount must be positive')
require(amount + s._balanceOf[msg.sender] <= s.maxPerAddress, 'Exceeded mint limit')
require(block.timestamp >= s.mintStart, 'Minting has not started')
require(block.timestamp < s.mintEnd, 'Minting has ended')
amount.times do |id|
_mint(to: msg.sender, id: s.totalSupply + id)
end
s.totalSupply += amount
end
function :tokenURI, { id: :uint256 }, :public, :view, :override, returns: :string do
require(_exists(id: id), 'ERC721Metadata: URI query for nonexistent token')
json_data = {
name: "#{s.name} ##{string(id)}",
description: s.description,
image: s.contentURI,
}.to_json
return "data:application/json,#{json_data}"
end
end