use schemars::JsonSchema;
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{to_json_binary, Binary, CosmosMsg, StdResult, WasmMsg};
#[cw_serde]
pub struct Cw721ReceiveMsg {
pub sender: String,
pub token_id: String,
pub msg: Binary,
}
impl Cw721ReceiveMsg {
pub fn into_json_binary(self) -> StdResult<Binary> {
let msg = ReceiverExecuteMsg::ReceiveNft(self);
to_json_binary(&msg)
}
pub fn into_cosmos_msg<TAddress: Into<String>, TCustomResponseMsg>(
self,
contract_addr: TAddress,
) -> StdResult<CosmosMsg<TCustomResponseMsg>>
where
TCustomResponseMsg: Clone + std::fmt::Debug + PartialEq + JsonSchema,
{
let msg = self.into_json_binary()?;
let execute = WasmMsg::Execute {
contract_addr: contract_addr.into(),
msg,
funds: vec![],
};
Ok(execute.into())
}
}
#[cw_serde]
pub enum ReceiverExecuteMsg {
ReceiveNft(Cw721ReceiveMsg),
}