-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathERC721.rb
103 lines (70 loc) · 3.09 KB
/
ERC721.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
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
pragma :rubidity, "1.0.0"
contract :ERC721, abstract: true do
event :Transfer, { from: :address, to: :address, id: :uint256 }
event :Approval, { owner: :address, spender: :address, id: :uint256 }
event :ApprovalForAll, { owner: :address, operator: :address, approved: :bool }
string :public, :name
string :public, :symbol
mapping ({ uint256: :address }), :internal, :_ownerOf
mapping ({ address: :uint256 }), :internal, :_balanceOf
mapping ({ uint256: :address }), :public, :getApproved
mapping ({ address: mapping(address: :bool) }), :public, :isApprovedForAll
constructor(name: :string, symbol: :string) {
s.name = name
s.symbol = symbol
}
function :ownerOf, { id: :uint256 }, :public, :view, :virtual, returns: :address do
owner = s._ownerOf[id]
require(owner != address(0), "ERC721: owner query for nonexistent token")
return owner
end
function :balanceOf, { owner: :address }, :public, :view, :virtual, returns: :uint256 do
require(owner != address(0), "ERC721: balance query for nonexistent owner")
return s._balanceOf[owner]
end
function :approve, { spender: :address, id: :uint256 }, :public, :virtual do
owner = s._ownerOf[id];
require(msg.sender == owner || s.isApprovedForAll[owner][msg.sender], "NOT_AUTHORIZED");
s.getApproved[id] = spender;
emit :Approval, owner: owner, spender: spender, id: id
end
function :setApprovalForAll, { operator: :address, bool: :approved }, :public, :virtual do
s.isApprovedForAll[msg.sender][operator] = approved;
emit :ApprovalForAll, owner: msg.sender, operator: operator, approved: approved
end
function :transferFrom, { from: :address, to: :address, id: :uint256 }, :public, :virtual do
require(from == s._ownerOf[id], "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
require(
msg.sender == from ||
s.getApproved[id] == msg.sender ||
isApprovedForAll[from][msg.sender],
"NOT_AUTHORIZED"
);
s._balanceOf[from] -= 1;
s._balanceOf[to] += 1;
s._ownerOf[id] = to;
s.getApproved[id] = address(0);
return nil
end
function :_exists, { id: :uint256 }, :internal, :virtual, returns: :bool do
return s._ownerOf[id] != address(0)
end
function :_mint, { to: :address, id: :uint256 }, :internal, :virtual do
require(to != address(0), "ERC721: mint to the zero address");
require(s._ownerOf[id] == address(0), "ERC721: token already minted");
s._balanceOf[to] += 1;
s._ownerOf[id] = to;
emit :Transfer, from: address(0), to: to, id: id
end
function :_burn, { id: :uint256 }, :internal, :virtual do
owner = s._ownerOf[id];
require(owner != address(0), "ERC721: burn of nonexistent token");
s._balanceOf[owner] -= 1;
s._ownerOf[id] = address(0);
s.getApproved[id] = address(0);
emit :Transfer, from: owner, to: address(0), id: id
end
function :tokenURI, { id: :uint256 }, :public, :view, :virtual, returns: :string do
end
end