1use super::TokenId;
2use derive_more::derive::From;
3use near_sdk::{AccountIdRef, json_types::U128, near, serde::Deserialize};
4use std::borrow::Cow;
5
6#[must_use = "make sure to `.emit()` this event"]
7#[near(event_json(standard = "nep245"))]
8#[derive(Debug, Clone, Deserialize, From)]
9pub enum MtEvent<'a> {
10 #[event_version("1.0.0")]
11 MtMint(Cow<'a, [MtMintEvent<'a>]>),
12 #[event_version("1.0.0")]
13 MtBurn(Cow<'a, [MtBurnEvent<'a>]>),
14 #[event_version("1.0.0")]
15 MtTransfer(Cow<'a, [MtTransferEvent<'a>]>),
16}
17
18#[must_use = "make sure to `.emit()` this event"]
19#[near(serializers = [json])]
20#[derive(Debug, Clone)]
21pub struct MtMintEvent<'a> {
22 pub owner_id: Cow<'a, AccountIdRef>,
23 pub token_ids: Cow<'a, [TokenId]>,
24 pub amounts: Cow<'a, [U128]>,
25 #[serde(default, skip_serializing_if = "Option::is_none")]
26 pub memo: Option<Cow<'a, str>>,
27}
28
29#[must_use = "make sure to `.emit()` this event"]
30#[near(serializers = [json])]
31#[derive(Debug, Clone)]
32pub struct MtBurnEvent<'a> {
33 pub owner_id: Cow<'a, AccountIdRef>,
34 #[serde(default, skip_serializing_if = "Option::is_none")]
35 pub authorized_id: Option<Cow<'a, AccountIdRef>>,
36 pub token_ids: Cow<'a, [TokenId]>,
37 pub amounts: Cow<'a, [U128]>,
38 #[serde(default, skip_serializing_if = "Option::is_none")]
39 pub memo: Option<Cow<'a, str>>,
40}
41
42#[must_use = "make sure to `.emit()` this event"]
43#[near(serializers = [json])]
44#[derive(Debug, Clone)]
45pub struct MtTransferEvent<'a> {
46 #[serde(default, skip_serializing_if = "Option::is_none")]
47 pub authorized_id: Option<Cow<'a, AccountIdRef>>,
48 pub old_owner_id: Cow<'a, AccountIdRef>,
49 pub new_owner_id: Cow<'a, AccountIdRef>,
50 pub token_ids: Cow<'a, [TokenId]>,
51 pub amounts: Cow<'a, [U128]>,
52 #[serde(default, skip_serializing_if = "Option::is_none")]
53 pub memo: Option<Cow<'a, str>>,
54}
55
56pub trait MtEventEmit<'a>: Into<MtEvent<'a>> {
59 #[inline]
60 fn emit(self) {
61 MtEvent::emit(&self.into());
62 }
63}
64impl<'a, T> MtEventEmit<'a> for T where T: Into<MtEvent<'a>> {}