Skip to main content

ics721_types/
types.rs

1use cosmwasm_schema::{cw_serde, schemars::JsonSchema};
2use cosmwasm_std::{Binary, IbcPacket};
3use serde::{Deserialize, Serialize};
4
5use crate::ibc_types::NonFungibleTokenPacketData;
6
7#[derive(Serialize, Deserialize, JsonSchema, Clone, Debug, PartialEq)]
8#[allow(clippy::derive_partial_eq_without_eq)]
9#[schemars(crate = "cosmwasm_schema::schemars")]
10#[serde(crate = "cosmwasm_schema::serde")]
11pub struct Ics721Memo {
12    pub callbacks: Option<Ics721Callbacks>,
13}
14
15/// The format we expect for the memo field on a send
16#[cw_serde]
17pub struct Ics721Callbacks {
18    /// Data to pass with a callback on source side (status update)
19    /// Note - If this field is empty, no callback will be sent
20    pub ack_callback_data: Option<Binary>,
21    /// The address that will receive the callback message
22    /// Defaults to the sender address
23    pub ack_callback_addr: Option<String>,
24    /// Data to pass with a callback on the destination side (ReceiveNftIcs721)
25    /// Note - If this field is empty, no callback will be sent
26    pub receive_callback_data: Option<Binary>,
27    /// The address that will receive the callback message
28    /// Defaults to the receiver address
29    pub receive_callback_addr: Option<String>,
30}
31
32/// A message is that is being called on receiving the NFT after transfer was completed.
33/// Receiving this message means that the NFT was successfully transferred.
34/// You must verify this message was called by an approved ICS721 contract, either by code_id or address.
35#[cw_serde]
36pub struct Ics721ReceiveCallbackMsg {
37    pub nft_contract: String,
38    pub original_packet: NonFungibleTokenPacketData,
39    pub msg: Binary,
40}
41
42/// A message to update your contract of the status of a transfer
43/// status = Ics721Status::Success - the transfer was successful and NFT is on the other chain
44/// status = Ics721Status::Failed - Transfer failed and contract still owns the NFT
45#[cw_serde]
46pub struct Ics721AckCallbackMsg {
47    pub status: Ics721Status,
48    pub nft_contract: String,
49    pub original_packet: NonFungibleTokenPacketData,
50    pub msg: Binary,
51}
52
53/// The status of a transfer on callback
54#[cw_serde]
55pub enum Ics721Status {
56    Success,
57    Failed(String),
58}
59
60/// This is a wrapper for ics721 callbacks
61/// so contracts will be able to recieve both status update and on receive hook.
62#[cw_serde]
63pub enum ReceiverExecuteMsg {
64    /// Being called on receiving the NFT after transfer was completed. (destination side)
65    /// `on_recieve` hook
66    /// Note - Failing this message will fail the transfer.
67    Ics721ReceiveCallback(Ics721ReceiveCallbackMsg),
68    /// Being called as a status update of the transfer. (source side)
69    /// Note - Failing this message will NOT fail the transfer, its just a status update.
70    Ics721AckCallback(Ics721AckCallbackMsg),
71
72    /// Being called on receiving the NFT before transfer is completed. (destination side)
73    /// `on_recieve` hook
74    /// Note - Failing this message will fail the transfer.
75    Ics721ReceivePacketMsg {
76        packet: IbcPacket,
77        data: NonFungibleTokenPacketData,
78    },
79}