bs721/
receiver.rs

1use schemars::JsonSchema;
2
3use cosmwasm_schema::cw_serde;
4use cosmwasm_std::{to_binary, Binary, CosmosMsg, StdResult, WasmMsg};
5
6/// Bs721ReceiveMsg should be de/serialized under `Receive()` variant in a ExecuteMsg
7#[cw_serde]
8pub struct Bs721ReceiveMsg {
9    pub sender: String,
10    pub token_id: String,
11    pub msg: Binary,
12}
13
14impl Bs721ReceiveMsg {
15    /// serializes the message
16    pub fn into_binary(self) -> StdResult<Binary> {
17        let msg = ReceiverExecuteMsg::ReceiveNft(self);
18        to_binary(&msg)
19    }
20
21    /// creates a cosmos_msg sending this struct to the named contract
22    pub fn into_cosmos_msg<T: Into<String>, C>(self, contract_addr: T) -> StdResult<CosmosMsg<C>>
23    where
24        C: Clone + std::fmt::Debug + PartialEq + JsonSchema,
25    {
26        let msg = self.into_binary()?;
27        let execute = WasmMsg::Execute {
28            contract_addr: contract_addr.into(),
29            msg,
30            funds: vec![],
31        };
32        Ok(execute.into())
33    }
34}
35
36/// This is just a helper to properly serialize the above message.
37/// The actual receiver should include this variant in the larger ExecuteMsg enum
38#[cw_serde]
39enum ReceiverExecuteMsg {
40    ReceiveNft(Bs721ReceiveMsg),
41}