forked from starknet-edu/starknet-erc721
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ERC721_metadata.cairo
174 lines (150 loc) · 4.62 KB
/
ERC721_metadata.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
%lang starknet
from starkware.cairo.common.cairo_builtins import HashBuiltin, SignatureBuiltin
from starkware.cairo.common.uint256 import Uint256
from openzeppelin.token.erc721.library import ERC721
from openzeppelin.introspection.erc165.library import ERC165
from openzeppelin.access.ownable.library import Ownable
from contracts.token.ERC721.ERC721_Metadata_base import (
ERC721_Metadata_initializer,
ERC721_Metadata_tokenURI,
ERC721_Metadata_setBaseTokenURI,
)
//
// Constructor
//
@constructor
func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
name: felt,
symbol: felt,
owner: felt,
base_token_uri_len: felt,
base_token_uri: felt*,
token_uri_suffix: felt,
) {
ERC721.initializer(name, symbol);
ERC721_Metadata_initializer();
Ownable.initializer(owner);
ERC721_Metadata_setBaseTokenURI(base_token_uri_len, base_token_uri, token_uri_suffix);
return ();
}
//
// Getters
//
@view
func getOwner{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (owner: felt) {
let (owner) = Ownable.owner();
return (owner=owner);
}
@view
func supportsInterface{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
interface_id: felt
) -> (success: felt) {
let (success) = ERC165.supports_interface(interface_id);
return (success,);
}
@view
func name{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (name: felt) {
let (name) = ERC721.name();
return (name,);
}
@view
func symbol{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (symbol: felt) {
let (symbol) = ERC721.symbol();
return (symbol,);
}
@view
func balanceOf{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(owner: felt) -> (
balance: Uint256
) {
let (balance: Uint256) = ERC721.balance_of(owner);
return (balance,);
}
@view
func ownerOf{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
token_id: Uint256
) -> (owner: felt) {
let (owner: felt) = ERC721.owner_of(token_id);
return (owner,);
}
@view
func getApproved{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
token_id: Uint256
) -> (approved: felt) {
let (approved: felt) = ERC721.get_approved(token_id);
return (approved,);
}
@view
func isApprovedForAll{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
owner: felt, operator: felt
) -> (is_approved: felt) {
let (is_approved: felt) = ERC721.is_approved_for_all(owner, operator);
return (is_approved,);
}
@view
func tokenURI{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
token_id: Uint256
) -> (token_uri_len: felt, token_uri: felt*) {
let (token_uri_len, token_uri) = ERC721_Metadata_tokenURI(token_id);
return (token_uri_len=token_uri_len, token_uri=token_uri);
}
//
// Externals
//
@external
func approve{pedersen_ptr: HashBuiltin*, syscall_ptr: felt*, range_check_ptr}(
to: felt, token_id: Uint256
) {
ERC721.approve(to, token_id);
return ();
}
@external
func setApprovalForAll{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
operator: felt, approved: felt
) {
ERC721.set_approval_for_all(operator, approved);
return ();
}
@external
func transferFrom{pedersen_ptr: HashBuiltin*, syscall_ptr: felt*, range_check_ptr}(
_from: felt, to: felt, token_id: Uint256
) {
ERC721.transfer_from(_from, to, token_id);
return ();
}
@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.safe_transfer_from(_from, to, token_id, data_len, data);
return ();
}
@external
func setTokenURI{pedersen_ptr: HashBuiltin*, syscall_ptr: felt*, range_check_ptr}(
base_token_uri_len: felt, base_token_uri: felt*, token_uri_suffix: felt
) {
Ownable.assert_only_owner();
ERC721_Metadata_setBaseTokenURI(base_token_uri_len, base_token_uri, token_uri_suffix);
return ();
}
@external
func mint{pedersen_ptr: HashBuiltin*, syscall_ptr: felt*, range_check_ptr}(
to: felt, token_id: Uint256
) {
Ownable.assert_only_owner();
ERC721._mint(to, token_id);
return ();
}
@external
func burn{pedersen_ptr: HashBuiltin*, syscall_ptr: felt*, range_check_ptr}(token_id: Uint256) {
Ownable.assert_only_owner();
ERC721._burn(token_id);
return ();
}
@external
func transferOwnership{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
new_owner: felt
) -> (new_owner: felt) {
// Ownership check is handled by this function
Ownable.transfer_ownership(new_owner);
return (new_owner=new_owner);
}