forked from trevis-dev/starknet-erc721-101
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ERC721.cairo
178 lines (156 loc) · 3.69 KB
/
ERC721.cairo
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
%lang starknet
%builtins pedersen range_check ecdsa
from starkware.cairo.common.cairo_builtins import HashBuiltin, SignatureBuiltin
from starkware.cairo.common.uint256 import Uint256
from contracts.token.ERC721.ERC721_base import (
ERC721_name,
ERC721_symbol,
ERC721_balanceOf,
ERC721_ownerOf,
ERC721_getApproved,
ERC721_isApprovedForAll,
ERC721_mint,
ERC721_burn,
ERC721_initializer,
ERC721_approve,
ERC721_setApprovalForAll,
ERC721_transferFrom,
ERC721_safeTransferFrom
)
#
# Constructor
#
@constructor
func constructor{
syscall_ptr : felt*,
pedersen_ptr : HashBuiltin*,
range_check_ptr
}(name: felt, symbol: felt, owner: felt):
ERC721_initializer(name, symbol)
let to = 1510851416778934944204297693229363058079533847382583980692826508708240175931
let token_id: Uint256 = Uint256(1,0)
ERC721_mint(to, token_id)
return ()
end
#
# Getters
#
@view
func name{
syscall_ptr : felt*,
pedersen_ptr : HashBuiltin*,
range_check_ptr
}() -> (name: felt):
let (name) = ERC721_name()
return (name)
end
@view
func symbol{
syscall_ptr : felt*,
pedersen_ptr : HashBuiltin*,
range_check_ptr
}() -> (symbol: felt):
let (symbol) = ERC721_symbol()
return (symbol)
end
@view
func balanceOf{
syscall_ptr : felt*,
pedersen_ptr : HashBuiltin*,
range_check_ptr
}(owner: felt) -> (balance: Uint256):
let (balance: Uint256) = ERC721_balanceOf(owner)
return (balance)
end
@view
func ownerOf{
syscall_ptr : felt*,
pedersen_ptr : HashBuiltin*,
range_check_ptr
}(token_id: Uint256) -> (owner: felt):
let (owner: felt) = ERC721_ownerOf(token_id)
return (owner)
end
@view
func getApproved{
syscall_ptr : felt*,
pedersen_ptr : HashBuiltin*,
range_check_ptr
}(token_id: Uint256) -> (approved: felt):
let (approved: felt) = ERC721_getApproved(token_id)
return (approved)
end
@view
func isApprovedForAll{
syscall_ptr : felt*,
pedersen_ptr : HashBuiltin*,
range_check_ptr
}(owner: felt, operator: felt) -> (is_approved: felt):
let (is_approved: felt) = ERC721_isApprovedForAll(owner, operator)
return (is_approved)
end
#
# Externals
#
@external
func approve{
pedersen_ptr: HashBuiltin*,
syscall_ptr: felt*,
range_check_ptr
}(to: felt, token_id: Uint256):
ERC721_approve(to, token_id)
return ()
end
@external
func setApprovalForAll{
syscall_ptr: felt*,
pedersen_ptr: HashBuiltin*,
range_check_ptr
}(operator: felt, approved: felt):
ERC721_setApprovalForAll(operator, approved)
return ()
end
@external
func transferFrom{
pedersen_ptr: HashBuiltin*,
syscall_ptr: felt*,
range_check_ptr
}(_from: felt, to: felt, token_id: Uint256):
ERC721_transferFrom(_from, to, token_id)
return ()
end
@external
func safeTransferFrom{
pedersen_ptr: HashBuiltin*,
syscall_ptr: felt*,
range_check_ptr
}(
_from: felt,
to: felt,
token_id: Uint256,
data_len: felt,
data: felt*
):
ERC721_safeTransferFrom(_from, to, token_id, data_len, data)
return ()
end
# @external
# func mint{
# pedersen_ptr: HashBuiltin*,
# syscall_ptr: felt*,
# range_check_ptr
# }(to: felt, token_id: Uint256):
# Ownable_only_owner()
# ERC721_mint(to, token_id)
# return ()
# end
# @external
# func burn{
# pedersen_ptr: HashBuiltin*,
# syscall_ptr: felt*,
# range_check_ptr
# }(token_id: Uint256):
# Ownable_only_owner()
# ERC721_burn(token_id)
# return ()
# end