near_sdk_contract_tools/standard/nep171/
event.rs

1//! Event log metadata & associated structures.
2
3use std::borrow::Cow;
4
5use near_sdk::{
6    serde::{Deserialize, Serialize},
7    AccountIdRef,
8};
9use near_sdk_contract_tools_macros::event;
10
11/// NEP-171 standard events.
12#[event(
13    crate = "crate",
14    macros = "near_sdk_contract_tools_macros",
15    standard = "nep171",
16    version = "1.2.0"
17)]
18#[derive(Debug, Clone)]
19pub enum Nep171Event<'a> {
20    /// Emitted when a token is newly minted.
21    NftMint(Vec<NftMintLog<'a>>),
22    /// Emitted when a token is transferred between two parties.
23    NftTransfer(Vec<NftTransferLog<'a>>),
24    /// Emitted when a token is burned.
25    NftBurn(Vec<NftBurnLog<'a>>),
26    /// Emitted when the metadata associated with an NFT contract is updated.
27    NftMetadataUpdate(Vec<NftMetadataUpdateLog<'a>>),
28    /// Emitted when the metadata associated with an NFT contract is updated.
29    ContractMetadataUpdate(Vec<NftContractMetadataUpdateLog<'a>>),
30}
31
32/// Tokens minted to a single owner.
33#[derive(Serialize, Deserialize, Debug, Clone)]
34#[serde(crate = "near_sdk::serde")]
35pub struct NftMintLog<'a> {
36    /// To whom were the new tokens minted?
37    pub owner_id: Cow<'a, AccountIdRef>,
38    /// Which tokens were minted?
39    pub token_ids: Vec<Cow<'a, str>>,
40    /// Additional mint information.
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub memo: Option<Cow<'a, str>>,
43}
44
45/// Tokens are transferred from one account to another.
46#[derive(Serialize, Deserialize, Debug, Clone)]
47#[serde(crate = "near_sdk::serde")]
48pub struct NftTransferLog<'a> {
49    /// NEP-178 authorized account ID.
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub authorized_id: Option<Cow<'a, AccountIdRef>>,
52    /// Account ID of the previous owner.
53    pub old_owner_id: Cow<'a, AccountIdRef>,
54    /// Account ID of the new owner.
55    pub new_owner_id: Cow<'a, AccountIdRef>,
56    /// IDs of the transferred tokens.
57    pub token_ids: Vec<Cow<'a, str>>,
58    /// Additional transfer information.
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub memo: Option<Cow<'a, str>>,
61}
62
63/// Tokens are burned from a single holder.
64#[derive(Serialize, Deserialize, Debug, Clone)]
65#[serde(crate = "near_sdk::serde")]
66pub struct NftBurnLog<'a> {
67    /// What is the ID of the account from which the tokens were burned?
68    pub owner_id: Cow<'a, AccountIdRef>,
69    /// IDs of the burned tokens.
70    pub token_ids: Vec<Cow<'a, str>>,
71    /// NEP-178 authorized account ID.
72    #[serde(skip_serializing_if = "Option::is_none")]
73    pub authorized_id: Option<Cow<'a, AccountIdRef>>,
74    /// Additional burn information.
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub memo: Option<Cow<'a, str>>,
77}
78
79/// Token metadata update.
80#[derive(Serialize, Deserialize, Debug, Clone)]
81#[serde(crate = "near_sdk::serde")]
82pub struct NftMetadataUpdateLog<'a> {
83    /// IDs of the updated tokens.
84    pub token_ids: Vec<Cow<'a, str>>,
85    /// Additional update information.
86    #[serde(skip_serializing_if = "Option::is_none")]
87    pub memo: Option<Cow<'a, str>>,
88}
89
90/// Contract metadata update.
91#[derive(Serialize, Deserialize, Debug, Clone)]
92#[serde(crate = "near_sdk::serde")]
93pub struct NftContractMetadataUpdateLog<'a> {
94    /// Additional update information.
95    #[serde(skip_serializing_if = "Option::is_none")]
96    pub memo: Option<Cow<'a, str>>,
97}