-
Notifications
You must be signed in to change notification settings - Fork 316
/
erc721.cairo
71 lines (63 loc) · 2.03 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
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts for Cairo v0.11.0 (presets/erc721.cairo)
/// # ERC721 Preset
///
/// The ERC721 contract offers a batch-mint mechanism that
/// can only be executed once upon contract construction.
#[starknet::contract]
mod ERC721 {
use openzeppelin::introspection::src5::SRC5Component;
use openzeppelin::token::erc721::ERC721Component;
use starknet::ContractAddress;
component!(path: ERC721Component, storage: erc721, event: ERC721Event);
component!(path: SRC5Component, storage: src5, event: SRC5Event);
// ERC721Mixin
#[abi(embed_v0)]
impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl<ContractState>;
impl ERC721InternalImpl = ERC721Component::InternalImpl<ContractState>;
#[storage]
struct Storage {
#[substorage(v0)]
erc721: ERC721Component::Storage,
#[substorage(v0)]
src5: SRC5Component::Storage
}
#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
ERC721Event: ERC721Component::Event,
#[flat]
SRC5Event: SRC5Component::Event
}
/// Sets the token `name` and `symbol`.
/// Mints the `token_ids` tokens to `recipient` and sets
/// the base URI.
#[constructor]
fn constructor(
ref self: ContractState,
name: ByteArray,
symbol: ByteArray,
base_uri: ByteArray,
recipient: ContractAddress,
token_ids: Span<u256>,
) {
self.erc721.initializer(name, symbol, base_uri);
self._mint_assets(recipient, token_ids);
}
#[generate_trait]
impl InternalImpl of InternalTrait {
/// Mints `token_ids` to `recipient`.
fn _mint_assets(
ref self: ContractState, recipient: ContractAddress, mut token_ids: Span<u256>
) {
loop {
if token_ids.len() == 0 {
break;
}
let id = *token_ids.pop_front().unwrap();
self.erc721._mint(recipient, id);
}
}
}
}