-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.rs
executable file
·114 lines (104 loc) · 3.13 KB
/
lib.rs
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
#![cfg_attr(not(feature = "std"), no_std, no_main)]
mod impls;
#[openbrush::implementation(PSP34, PSP34Mintable, PSP34Metadata, PSP34Enumerable, Ownable)]
#[openbrush::contract]
mod nft_market {
use crate::impls;
use ink::codegen::{EmitEvent, Env};
use openbrush::{
contracts::{
psp34::{extensions::metadata, PSP34Impl},
reentrancy_guard,
},
traits::Storage,
};
#[ink(storage)]
#[derive(Default, Storage)]
pub struct NftMarket {
#[storage_field]
psp34: psp34::Data,
#[storage_field]
guard: reentrancy_guard::Data,
#[storage_field]
ownable: ownable::Data,
#[storage_field]
metadata: metadata::Data,
#[storage_field]
nftdata: impls::types::NftData,
#[storage_field]
enumerable: enumerable::Data,
}
/// Event emitted when a token transfer occurs.
#[ink(event)]
pub struct Transfer {
#[ink(topic)]
from: Option<AccountId>,
#[ink(topic)]
to: Option<AccountId>,
#[ink(topic)]
id: Id,
}
/// Event emitted when a token approve occurs.
#[ink(event)]
pub struct Approval {
#[ink(topic)]
from: AccountId,
#[ink(topic)]
to: AccountId,
#[ink(topic)]
id: Option<Id>,
approved: bool,
}
// Override event emission methods
#[overrider(psp34::Internal)]
fn _emit_transfer_event(&self, from: Option<AccountId>, to: Option<AccountId>, id: Id) {
self.env().emit_event(Transfer { from, to, id });
}
#[overrider(psp34::Internal)]
fn _emit_approval_event(&self, from: AccountId, to: AccountId, id: Option<Id>, approved: bool) {
self.env().emit_event(Approval {
from,
to,
id,
approved,
});
}
impl impls::market::Internal for NftMarket {}
impl impls::market::MarketImpl for NftMarket {}
impl NftMarket {
#[ink(constructor)]
pub fn new(
name: String,
symbol: String,
base_uri: String,
max_supply: u64,
price_per_mint: Balance,
) -> Self {
let mut instance = Self::default();
let caller = instance.env().caller();
ownable::InternalImpl::_init_with_owner(&mut instance, caller);
let col_id = PSP34Impl::collection_id(&instance);
metadata::InternalImpl::_set_attribute(
&mut instance,
col_id.clone(),
String::from("name"),
name,
);
metadata::InternalImpl::_set_attribute(
&mut instance,
col_id.clone(),
String::from("symbol"),
symbol,
);
metadata::InternalImpl::_set_attribute(
&mut instance,
col_id,
String::from("baseUri"),
base_uri,
);
instance.nftdata.max_supply = max_supply;
instance.nftdata.price_per_mint = price_per_mint;
instance
}
}
}