Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.

Commit 4fcc28a

Browse files
committed
Move market logging
1 parent a7973f1 commit 4fcc28a

File tree

8 files changed

+101
-181
lines changed

8 files changed

+101
-181
lines changed

mintbase-deps/src/logging.rs

Lines changed: 89 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ use near_events::{
22
near_event_data,
33
near_event_data_log,
44
};
5-
use near_sdk::json_types::U64;
5+
use near_sdk::json_types::{
6+
U128,
7+
U64,
8+
};
69
#[cfg(feature = "de")]
710
use near_sdk::serde::Deserialize;
811
#[cfg(feature = "ser")]
912
use near_sdk::serde::Serialize;
1013
use near_sdk::AccountId;
1114

12-
// TODO: events defined here, logging functions into market/store
13-
mod market;
14-
pub use market::*;
15-
1615
// ----------------------------- Core (NEP171) ------------------------------ //
1716
#[cfg_attr(feature = "all", derive(Clone, Debug))]
1817
#[near_event_data_log(standard = "nep171", version = "1.0.0", event = "nft_mint")]
@@ -138,3 +137,88 @@ impl MbStoreChangeSettingData {
138137
}
139138
}
140139
}
140+
141+
// --------------------------------- Market --------------------------------- //
142+
#[cfg_attr(feature = "ser", derive(Serialize))]
143+
#[cfg_attr(feature = "de", derive(Deserialize))]
144+
#[cfg_attr(any(feature = "ser", feature = "de"), serde(crate = "near_sdk::serde"))]
145+
pub struct NftListLog {
146+
pub list_id: String,
147+
pub price: String,
148+
pub token_key: String,
149+
pub owner_id: String,
150+
pub autotransfer: bool,
151+
pub approval_id: String,
152+
pub token_id: String,
153+
pub store_id: String,
154+
}
155+
156+
#[near_event_data(standard = "mb_market", version = "0.1.0", event = "nft_list")]
157+
pub struct NftListData(pub Vec<NftListLog>);
158+
159+
#[cfg_attr(feature = "all", derive(Clone, Debug))]
160+
#[near_event_data(standard = "mb_market", version = "0.1.0", event = "nft_update_list")]
161+
pub struct NftUpdateListData {
162+
pub list_id: String,
163+
pub auto_transfer: Option<bool>,
164+
pub price: Option<String>,
165+
}
166+
167+
#[cfg_attr(feature = "all", derive(Clone, Debug))]
168+
#[near_event_data_log(standard = "mb_market", version = "0.1.0", event = "nft_unlist")]
169+
pub struct NftUnlistLog {
170+
pub list_id: String,
171+
}
172+
173+
#[cfg_attr(feature = "all", derive(Clone, Debug))]
174+
#[near_event_data(standard = "mb_market", version = "0.1.0", event = "nft_sold")]
175+
pub struct NftSaleData {
176+
pub list_id: String,
177+
pub offer_num: u64,
178+
pub token_key: String,
179+
pub payout: HashMap<AccountId, U128>,
180+
// Not originally in 0.1.0, but option makes it backwards compatible with
181+
// serde_json
182+
pub mintbase_amount: Option<U128>,
183+
}
184+
185+
#[cfg_attr(feature = "all", derive(Clone, Debug))]
186+
#[cfg_attr(feature = "ser", derive(Serialize))]
187+
#[cfg_attr(feature = "de", derive(Deserialize))]
188+
#[cfg_attr(any(feature = "ser", feature = "de"), serde(crate = "near_sdk::serde"))]
189+
pub struct NftMakeOfferLog {
190+
pub offer: crate::common::TokenOffer, // TODO: TokenOfferJson to stringify u128?
191+
pub list_id: String,
192+
pub token_key: String,
193+
pub offer_num: u64,
194+
}
195+
196+
// FIXME: u128 is not supported -_____-
197+
#[cfg_attr(feature = "all", derive(Clone, Debug))]
198+
#[near_event_data(standard = "mb_market", version = "0.1.0", event = "nft_make_offer")]
199+
pub struct NftMakeOfferData(pub Vec<NftMakeOfferLog>);
200+
201+
#[cfg_attr(feature = "all", derive(Clone, Debug))]
202+
#[near_event_data(
203+
standard = "mb_market",
204+
version = "0.1.0",
205+
event = "nft_withdraw_offer"
206+
)]
207+
pub struct NftWithdrawOfferData {
208+
pub list_id: String,
209+
pub offer_num: u64,
210+
}
211+
212+
#[cfg_attr(feature = "all", derive(Clone, Debug))]
213+
#[near_event_data(standard = "mb_market", version = "0.1.0", event = "update_banlist")]
214+
pub struct UpdateBanlistData {
215+
pub account_id: String,
216+
pub state: bool,
217+
}
218+
219+
#[cfg_attr(feature = "all", derive(Clone, Debug))]
220+
#[near_event_data(standard = "mb_market", version = "0.1.0", event = "update_allowlist")]
221+
pub struct UpdateAllowlistData {
222+
pub account_id: String,
223+
pub state: bool,
224+
}

mintbase-deps/src/logging/market.rs

Lines changed: 0 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,6 @@ use near_sdk::{
2020
use crate::common::TokenOffer;
2121

2222
// ----------------------------- create listing ----------------------------- //
23-
#[cfg_attr(feature = "ser", derive(Serialize))]
24-
#[cfg_attr(feature = "de", derive(Deserialize))]
25-
#[cfg_attr(any(feature = "ser", feature = "de"), serde(crate = "near_sdk::serde"))]
26-
pub struct NftListLog {
27-
pub list_id: String,
28-
pub price: String,
29-
pub token_key: String,
30-
pub owner_id: String,
31-
pub autotransfer: bool,
32-
pub approval_id: String,
33-
pub token_id: String,
34-
pub store_id: String,
35-
}
36-
37-
#[near_event_data(standard = "mb_market", version = "0.1.0", event = "nft_list")]
38-
pub struct NftListData(Vec<NftListLog>);
3923

4024
#[cfg(feature = "ser")]
4125
pub fn log_listing_created(
@@ -98,13 +82,6 @@ pub fn log_batch_listing_created(
9882

9983
// ---------------------------- update listings ----------------------------- //
10084
// TODO: test!
101-
#[cfg_attr(feature = "all", derive(Clone, Debug))]
102-
#[near_event_data(standard = "mb_market", version = "0.1.0", event = "nft_update_list")]
103-
pub struct NftUpdateListData {
104-
pub list_id: String,
105-
pub auto_transfer: Option<bool>,
106-
pub price: Option<String>,
107-
}
10885

10986
#[cfg(feature = "ser")]
11087
pub fn log_set_token_autotransfer(
@@ -132,151 +109,10 @@ pub fn log_set_token_asking_price(
132109
env::log_str(&data.serialize_event());
133110
}
134111

135-
// ------------------------------- unlisting -------------------------------- //
136-
#[cfg_attr(feature = "all", derive(Clone, Debug))]
137-
#[near_event_data_log(standard = "mb_market", version = "0.1.0", event = "nft_unlist")]
138-
pub struct NftUnlistLog {
139-
pub list_id: String,
140-
}
141-
142112
#[cfg(feature = "ser")]
143113
pub fn log_token_removed(list_id: &str) {
144114
let log = NftUnlistLog {
145115
list_id: list_id.to_string(),
146116
};
147117
env::log_str(&log.serialize_event());
148118
}
149-
150-
// ------------------------------ sell listing ------------------------------ //
151-
#[cfg_attr(feature = "all", derive(Clone, Debug))]
152-
#[near_event_data(standard = "mb_market", version = "0.1.0", event = "nft_sold")]
153-
pub struct NftSaleData {
154-
pub list_id: String,
155-
pub offer_num: u64,
156-
pub token_key: String,
157-
pub payout: HashMap<AccountId, U128>,
158-
// Not originally in 0.1.0, but option makes it backwards compatible with
159-
// serde_json
160-
pub mintbase_amount: Option<U128>,
161-
}
162-
163-
#[cfg(feature = "ser")]
164-
pub fn log_sale(
165-
list_id: &str,
166-
offer_num: u64,
167-
token_key: &str,
168-
payout: &HashMap<AccountId, U128>,
169-
mintbase_amount: U128,
170-
) {
171-
let data = NftSaleData {
172-
list_id: list_id.to_string(),
173-
offer_num,
174-
token_key: token_key.to_string(),
175-
payout: payout.clone(),
176-
mintbase_amount: Some(mintbase_amount),
177-
};
178-
env::log_str(&data.serialize_event());
179-
}
180-
181-
// ----------------------------- creating offer ----------------------------- //
182-
#[cfg_attr(feature = "all", derive(Clone, Debug))]
183-
#[cfg_attr(feature = "ser", derive(Serialize))]
184-
#[cfg_attr(feature = "de", derive(Deserialize))]
185-
#[cfg_attr(any(feature = "ser", feature = "de"), serde(crate = "near_sdk::serde"))]
186-
pub struct NftMakeOfferLog {
187-
pub offer: TokenOffer, // TODO: TokenOfferJson to stringify u128?
188-
pub list_id: String,
189-
pub token_key: String,
190-
pub offer_num: u64,
191-
}
192-
193-
// FIXME: u128 is not supported -_____-
194-
#[cfg_attr(feature = "all", derive(Clone, Debug))]
195-
#[near_event_data(standard = "mb_market", version = "0.1.0", event = "nft_make_offer")]
196-
pub struct NftMakeOfferData(Vec<NftMakeOfferLog>);
197-
198-
#[cfg(feature = "ser")]
199-
pub fn log_make_offer(
200-
offer: Vec<&TokenOffer>,
201-
token_key: Vec<&String>,
202-
list_id: Vec<String>,
203-
offer_num: Vec<u64>,
204-
) {
205-
let data = NftMakeOfferData(
206-
offer
207-
.iter()
208-
.enumerate()
209-
.map(|(u, &x)| NftMakeOfferLog {
210-
offer: x.clone(),
211-
list_id: list_id[u].clone(),
212-
token_key: token_key[u].clone(),
213-
offer_num: offer_num[u],
214-
})
215-
.collect::<Vec<_>>(),
216-
);
217-
env::log_str(&data.serialize_event());
218-
}
219-
220-
// --------------------------- withdrawing offer ---------------------------- //
221-
// TODO: testing!
222-
#[cfg_attr(feature = "all", derive(Clone, Debug))]
223-
#[near_event_data(
224-
standard = "mb_market",
225-
version = "0.1.0",
226-
event = "nft_withdraw_offer"
227-
)]
228-
pub struct NftWithdrawOfferData {
229-
pub list_id: String,
230-
pub offer_num: u64,
231-
}
232-
233-
#[cfg(feature = "ser")]
234-
pub fn log_withdraw_token_offer(
235-
list_id: &str,
236-
offer_num: u64,
237-
) {
238-
let data = NftWithdrawOfferData {
239-
offer_num,
240-
list_id: list_id.to_string(),
241-
};
242-
env::log_str(&data.serialize_event());
243-
}
244-
245-
// ----------------------- updating banlist/allowlist ----------------------- //
246-
#[cfg_attr(feature = "all", derive(Clone, Debug))]
247-
#[near_event_data(standard = "mb_market", version = "0.1.0", event = "update_banlist")]
248-
pub struct UpdateBanlistData {
249-
pub account_id: String,
250-
pub state: bool,
251-
}
252-
253-
#[cfg(feature = "ser")]
254-
pub fn log_banlist_update(
255-
account_id: &AccountId,
256-
state: bool,
257-
) {
258-
let data = UpdateBanlistData {
259-
account_id: account_id.to_string(),
260-
state,
261-
};
262-
env::log_str(&data.serialize_event());
263-
}
264-
265-
#[cfg_attr(feature = "all", derive(Clone, Debug))]
266-
#[near_event_data(standard = "mb_market", version = "0.1.0", event = "update_allowlist")]
267-
pub struct UpdateAllowlistData {
268-
pub account_id: String,
269-
pub state: bool,
270-
}
271-
272-
#[cfg(feature = "ser")]
273-
pub fn log_allowlist_update(
274-
account_id: &AccountId,
275-
state: bool,
276-
) {
277-
let data = UpdateAllowlistData {
278-
account_id: account_id.to_string(),
279-
state,
280-
};
281-
env::log_str(&data.serialize_event());
282-
}

store/src/approvals.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl MintbaseStore {
210210
}
211211
}
212212

213-
pub fn log_approve(
213+
fn log_approve(
214214
token_id: u64,
215215
approval_id: u64,
216216
account_id: &AccountId,
@@ -223,7 +223,7 @@ pub fn log_approve(
223223
env::log_str(&data.serialize_event());
224224
}
225225

226-
pub fn log_batch_approve(
226+
fn log_batch_approve(
227227
tokens: &[U64],
228228
approvals: &[U64],
229229
account_id: &AccountId,
@@ -242,7 +242,7 @@ pub fn log_batch_approve(
242242
env::log_str(&data.serialize_event());
243243
}
244244

245-
pub fn log_revoke(
245+
fn log_revoke(
246246
token_id: u64,
247247
account_id: &AccountId,
248248
) {
@@ -255,7 +255,7 @@ pub fn log_revoke(
255255
);
256256
}
257257

258-
pub fn log_revoke_all(token_id: u64) {
258+
fn log_revoke_all(token_id: u64) {
259259
env::log_str(
260260
&NftRevokeAllData {
261261
token_id: token_id.into(),

store/src/burning.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl MintbaseStore {
7575
// -------------------------- internal methods -------------------------
7676
}
7777

78-
pub fn log_nft_batch_burn(
78+
fn log_nft_batch_burn(
7979
token_ids: &[U64],
8080
owner_id: String,
8181
) {

store/src/core.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl MintbaseStore {
296296
}
297297
}
298298

299-
pub fn log_nft_transfer(
299+
fn log_nft_transfer(
300300
to: &AccountId,
301301
token_id: u64,
302302
memo: &Option<String>,
@@ -313,7 +313,7 @@ pub fn log_nft_transfer(
313313
env::log_str(data.serialize_event().as_str());
314314
}
315315

316-
pub fn log_nft_batch_transfer(
316+
fn log_nft_batch_transfer(
317317
tokens: &[U64],
318318
accounts: &[AccountId],
319319
old_owners: Vec<String>,

store/src/minting.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ fn option_string_is_u64(opt_s: &Option<String>) -> bool {
350350
}
351351

352352
#[allow(clippy::too_many_arguments)]
353-
pub fn log_nft_batch_mint(
353+
fn log_nft_batch_mint(
354354
first_token_id: u64,
355355
last_token_id: u64,
356356
minter: &str,
@@ -380,7 +380,7 @@ pub fn log_nft_batch_mint(
380380
env::log_str(log.serialize_event().as_str());
381381
}
382382

383-
pub fn log_grant_minter(account_id: &AccountId) {
383+
pub(crate) fn log_grant_minter(account_id: &AccountId) {
384384
env::log_str(
385385
&MbStoreChangeSettingData {
386386
granted_minter: Some(account_id.to_string()),
@@ -390,7 +390,7 @@ pub fn log_grant_minter(account_id: &AccountId) {
390390
);
391391
}
392392

393-
pub fn log_revoke_minter(account_id: &AccountId) {
393+
pub(crate) fn log_revoke_minter(account_id: &AccountId) {
394394
env::log_str(
395395
&MbStoreChangeSettingData {
396396
revoked_minter: Some(account_id.to_string()),

store/src/ownership.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl MintbaseStore {
111111
}
112112
}
113113

114-
pub fn log_transfer_store(account_id: &AccountId) {
114+
fn log_transfer_store(account_id: &AccountId) {
115115
env::log_str(
116116
&MbStoreChangeSettingData {
117117
new_owner: Some(account_id.to_string()),

0 commit comments

Comments
 (0)