sg721_name/
msg.rs

1use cosmwasm_schema::{cw_serde, QueryResponses};
2use cosmwasm_std::{Addr, Binary, Timestamp};
3use cw721::{
4    AllNftInfoResponse, ApprovalResponse, ApprovalsResponse, ContractInfoResponse, Expiration,
5    NftInfoResponse, NumTokensResponse, OperatorsResponse, OwnerOfResponse, TokensResponse,
6};
7use cw721_base::{MintMsg, MinterResponse};
8use sg721::{
9    ExecuteMsg as Sg721ExecuteMsg, InstantiateMsg as Sg721InstantiateMsg, RoyaltyInfoResponse,
10    UpdateCollectionInfoMsg,
11};
12use sg721_base::msg::{CollectionInfoResponse, QueryMsg as Sg721QueryMsg};
13use sg_name::{Metadata, TextRecord, NFT};
14
15use crate::state::SudoParams;
16
17#[cw_serde]
18pub struct InstantiateMsg {
19    pub verifier: Option<String>,
20    pub base_init_msg: Sg721InstantiateMsg,
21}
22
23// Add execute msgs related to metadata, image, text records
24// The rest are inherited from sg721 and impl to properly convert the msgs.
25#[cw_serde]
26pub enum ExecuteMsg<T> {
27    /// Set name marketplace contract address
28    SetNameMarketplace { address: String },
29    /// Set an address for name reverse lookup and updates token_uri
30    /// Can be an EOA or a contract address.
31    AssociateAddress {
32        name: String,
33        address: Option<String>,
34    },
35    /// Update image NFT
36    UpdateImageNft { name: String, nft: Option<NFT> },
37    /// Add text record ex: twitter handle, discord name, etc
38    AddTextRecord { name: String, record: TextRecord },
39    /// Remove text record ex: twitter handle, discord name, etc
40    RemoveTextRecord { name: String, record_name: String },
41    /// Update text record ex: twitter handle, discord name, etc
42    UpdateTextRecord { name: String, record: TextRecord },
43    /// Verify a text record as true or false (via oracle)
44    VerifyTextRecord {
45        name: String,
46        record_name: String,
47        result: bool,
48    },
49    /// Update the reset the verification oracle
50    UpdateVerifier { verifier: Option<String> },
51    /// Transfer is a base message to move a token to another account without triggering actions
52    TransferNft { recipient: String, token_id: String },
53    /// Send is a base message to transfer a token to a contract and trigger an action
54    /// on the receiving contract.
55    SendNft {
56        contract: String,
57        token_id: String,
58        msg: Binary,
59    },
60    /// Allows operator to transfer / send the token from the owner's account.
61    /// If expiration is set, then this allowance has a time/height limit
62    Approve {
63        spender: String,
64        token_id: String,
65        expires: Option<Expiration>,
66    },
67    /// Remove previously granted Approval
68    Revoke { spender: String, token_id: String },
69    /// Allows operator to transfer / send any token from the owner's account.
70    /// If expiration is set, then this allowance has a time/height limit
71    ApproveAll {
72        operator: String,
73        expires: Option<Expiration>,
74    },
75    /// Remove previously granted ApproveAll permission
76    RevokeAll { operator: String },
77    /// Mint a new NFT, can only be called by the contract minter
78    Mint(MintMsg<T>),
79    /// Burn an NFT the sender has access to
80    Burn { token_id: String },
81    /// Update specific collection info fields
82    UpdateCollectionInfo {
83        collection_info: UpdateCollectionInfoMsg<RoyaltyInfoResponse>,
84    },
85    /// Called by the minter to update trading start time
86    UpdateStartTradingTime(Option<Timestamp>),
87    /// Freeze collection info from further updates
88    FreezeCollectionInfo {},
89}
90
91impl<T, E> From<ExecuteMsg<T>> for Sg721ExecuteMsg<T, E> {
92    fn from(msg: ExecuteMsg<T>) -> Sg721ExecuteMsg<T, E> {
93        match msg {
94            ExecuteMsg::TransferNft {
95                recipient,
96                token_id,
97            } => Sg721ExecuteMsg::TransferNft {
98                recipient,
99                token_id,
100            },
101            ExecuteMsg::SendNft {
102                contract,
103                token_id,
104                msg,
105            } => Sg721ExecuteMsg::SendNft {
106                contract,
107                token_id,
108                msg,
109            },
110            ExecuteMsg::Approve {
111                spender,
112                token_id,
113                expires,
114            } => Sg721ExecuteMsg::Approve {
115                spender,
116                token_id,
117                expires,
118            },
119            ExecuteMsg::ApproveAll { operator, expires } => {
120                Sg721ExecuteMsg::ApproveAll { operator, expires }
121            }
122            ExecuteMsg::Revoke { spender, token_id } => {
123                Sg721ExecuteMsg::Revoke { spender, token_id }
124            }
125            ExecuteMsg::RevokeAll { operator } => Sg721ExecuteMsg::RevokeAll { operator },
126            ExecuteMsg::Burn { token_id } => Sg721ExecuteMsg::Burn { token_id },
127            ExecuteMsg::UpdateCollectionInfo { collection_info } => {
128                Sg721ExecuteMsg::UpdateCollectionInfo { collection_info }
129            }
130            ExecuteMsg::UpdateStartTradingTime(start_time) => {
131                Sg721ExecuteMsg::UpdateStartTradingTime(start_time)
132            }
133            ExecuteMsg::FreezeCollectionInfo {} => Sg721ExecuteMsg::FreezeCollectionInfo {},
134            ExecuteMsg::Mint(MintMsg {
135                token_id,
136                owner,
137                token_uri,
138                extension,
139            }) => Sg721ExecuteMsg::Mint(MintMsg {
140                token_id,
141                owner,
142                token_uri,
143                extension,
144            }),
145            _ => unreachable!("Invalid ExecuteMsg"),
146        }
147    }
148}
149
150#[cw_serde]
151pub enum SudoMsg {
152    UpdateParams { max_record_count: u32 },
153}
154
155#[cw_serde]
156#[derive(QueryResponses)]
157pub enum QueryMsg {
158    /// Returns sudo params
159    #[returns(SudoParams)]
160    Params {},
161    /// Reverse lookup of name for address
162    #[returns(String)]
163    Name { address: String },
164    /// Returns the marketplace contract address
165    #[returns(Addr)]
166    NameMarketplace {},
167    /// Returns the associated address for a name
168    #[returns(Addr)]
169    AssociatedAddress { name: String },
170    /// Returns the image NFT for a name
171    #[returns(Option<NFT>)]
172    ImageNFT { name: String },
173    /// Returns the text records for a name
174    #[returns(Vec<TextRecord>)]
175    TextRecords { name: String },
176    /// Returns if Twitter is verified for a name
177    #[returns(bool)]
178    IsTwitterVerified { name: String },
179    /// Returns the verification oracle address
180    #[returns(Option<String>)]
181    Verifier {},
182    /// Everything below is inherited from sg721
183    #[returns(OwnerOfResponse)]
184    OwnerOf {
185        token_id: String,
186        include_expired: Option<bool>,
187    },
188    #[returns(ApprovalResponse)]
189    Approval {
190        token_id: String,
191        spender: String,
192        include_expired: Option<bool>,
193    },
194    #[returns(ApprovalsResponse)]
195    Approvals {
196        token_id: String,
197        include_expired: Option<bool>,
198    },
199    #[returns(OperatorsResponse)]
200    AllOperators {
201        owner: String,
202        include_expired: Option<bool>,
203        start_after: Option<String>,
204        limit: Option<u32>,
205    },
206    #[returns(NumTokensResponse)]
207    NumTokens {},
208    #[returns(ContractInfoResponse)]
209    ContractInfo {},
210    #[returns(NftInfoResponse<Metadata>)]
211    NftInfo { token_id: String },
212    #[returns(AllNftInfoResponse<Metadata>)]
213    AllNftInfo {
214        token_id: String,
215        include_expired: Option<bool>,
216    },
217    #[returns(TokensResponse)]
218    Tokens {
219        owner: String,
220        start_after: Option<String>,
221        limit: Option<u32>,
222    },
223    #[returns(TokensResponse)]
224    AllTokens {
225        start_after: Option<String>,
226        limit: Option<u32>,
227    },
228    #[returns(MinterResponse)]
229    Minter {},
230    #[returns(CollectionInfoResponse)]
231    CollectionInfo {},
232}
233
234impl From<QueryMsg> for Sg721QueryMsg {
235    fn from(msg: QueryMsg) -> Sg721QueryMsg {
236        match msg {
237            QueryMsg::OwnerOf {
238                token_id,
239                include_expired,
240            } => Sg721QueryMsg::OwnerOf {
241                token_id,
242                include_expired,
243            },
244            QueryMsg::Approval {
245                token_id,
246                spender,
247                include_expired,
248            } => Sg721QueryMsg::Approval {
249                token_id,
250                spender,
251                include_expired,
252            },
253            QueryMsg::Approvals {
254                token_id,
255                include_expired,
256            } => Sg721QueryMsg::Approvals {
257                token_id,
258                include_expired,
259            },
260            QueryMsg::AllOperators {
261                owner,
262                include_expired,
263                start_after,
264                limit,
265            } => Sg721QueryMsg::AllOperators {
266                owner,
267                include_expired,
268                start_after,
269                limit,
270            },
271            QueryMsg::NumTokens {} => Sg721QueryMsg::NumTokens {},
272            QueryMsg::ContractInfo {} => Sg721QueryMsg::ContractInfo {},
273            QueryMsg::NftInfo { token_id } => Sg721QueryMsg::NftInfo { token_id },
274            QueryMsg::AllNftInfo {
275                token_id,
276                include_expired,
277            } => Sg721QueryMsg::AllNftInfo {
278                token_id,
279                include_expired,
280            },
281            QueryMsg::Tokens {
282                owner,
283                start_after,
284                limit,
285            } => Sg721QueryMsg::Tokens {
286                owner,
287                start_after,
288                limit,
289            },
290            QueryMsg::AllTokens { start_after, limit } => {
291                Sg721QueryMsg::AllTokens { start_after, limit }
292            }
293            QueryMsg::Minter {} => Sg721QueryMsg::Minter {},
294            QueryMsg::CollectionInfo {} => Sg721QueryMsg::CollectionInfo {},
295            _ => unreachable!("cannot convert {:?} to Cw721QueryMsg", msg),
296        }
297    }
298}