simple_nft/
msg.rs

1//! Defines *InstantiateMsg*, *ExecuteMsg* and *QueryMsg*.
2
3use cosmwasm_std::{Addr, Binary, Coin};
4use cw721::Expiration;
5use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, JsonSchema)]
9#[serde(rename_all = "snake_case")]
10pub struct InstantiateMsg {
11    /// Name of the NFT
12    pub name: String,
13    /// Symbol of the NFT
14    pub symbol: String,
15    // /// Minter has the permission to mint new tokens
16    // pub minter: String,
17}
18
19#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
20#[serde(rename_all = "snake_case")]
21pub enum ExecuteMsg {
22    /// Transfer is a base message to move a token to another account without triggering actions
23    TransferNft { recipient: String, token_id: u64 },
24    /// Send is a base message to transfer a token to a contract and trigger an action
25    /// on the receiving contract.
26    SendNft {
27        contract: String,
28        token_id: u64,
29        msg: Binary,
30    },
31    /// Allows operator to transfer / send the token from the owner's account.
32    /// If expiration is set, then this allowance has a time/height limit
33    Approve {
34        operator: String,
35        token_id: u64,
36        expires: Option<Expiration>,
37    },
38    /// Remove previously granted Approval
39    Revoke { operator: String, token_id: u64 },
40    /// Allows operator to transfer / send any token from the owner's account.
41    /// If expiration is set, then this allowance has a time/height limit
42    ApproveAll {
43        operator: String,
44        expires: Option<Expiration>,
45    },
46    /// Remove previously granted ApproveAll permission
47    RevokeAll { operator: String },
48    /// Mint a new token with the details as in MintMsg.
49    Mint(MintMsg),
50}
51
52#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
53pub struct Approval {
54    /// Account that can transfer/send the token
55    pub operator: Addr,
56    /// When the Approval expires (maybe Expiration::never)
57    pub expires: Expiration,
58}
59
60#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
61pub struct MintMsg {
62    // /// Unique ID of the NFT
63    // pub token_id: u64,
64    /// The owner of the newly minter NFT
65    pub owner: String,
66    /// Universal resource identifier for this NFT
67    /// Should point to a JSON file that conforms to the ERC721
68    /// Metadata JSON Schema
69    pub token_uri: Option<String>,
70    /// Price of the token
71    pub price: Vec<Coin>,
72}
73
74#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
75#[serde(rename_all = "snake_case")]
76pub enum QueryMsg {
77    // The price of the token
78    AskingPrice {
79        token_id: u64,
80    },
81    // Owner of the token
82    OwnerOf {
83        token_id: u64,
84        include_expired: Option<bool>,
85    },
86    // Return the operator, who has approval for given token
87    Approval {
88        token_id: u64,
89        operator: String,
90        include_expired: Option<bool>,
91    },
92
93    // All approvals for the given token
94    Approvals {
95        token_id: u64,
96        include_expired: Option<bool>,
97    },
98    // Return all operators with access to all of the given owner's tokens
99    AllOperators {
100        owner: String,
101        include_expired: Option<bool>,
102        start_after: Option<String>,
103        limit: Option<u32>,
104    },
105    // Number of tokens issued thus far
106    NumTokens {},
107    // Return the contract info.
108    // Part of Metadata Extension
109    ContractInfo {},
110    // Return NFT info.
111    // Part of Metadata Extension
112    NftInfo {
113        token_id: u64,
114    },
115    // Return NFT info and OwnerOf response.
116    // Part of Metadata Extension
117    AllNftInfo {
118        token_id: u64,
119        include_expired: Option<bool>,
120    },
121}
122
123#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
124pub struct AskingPriceResponse {
125    pub price: Vec<Coin>,
126}
127
128#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
129pub struct OwnerOfResponse {
130    pub owner: String,
131    pub approvals: Vec<Approval>,
132}
133
134#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
135pub struct ApprovalResponse {
136    pub approval: Approval,
137}
138
139#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
140pub struct ApprovalsResponse {
141    pub approvals: Vec<Approval>,
142}
143
144#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
145pub struct NumTokensResponse {
146    pub tokens: u64,
147}
148
149#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
150pub struct ContractInfoResponse {
151    pub name: String,
152    pub symbol: String,
153}
154
155#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
156pub struct NftInfoResponse {
157    pub token_uri: String,
158}
159
160#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
161pub struct AllNftInfoResponse {
162    pub owner: OwnerOfResponse,
163    pub info: NftInfoResponse,
164}