use cosmwasm_schema::cw_serde;
use cosmwasm_std::{to_binary, Binary, CosmosMsg, StdResult, Uint128, WasmMsg};
use crate::msg::TokenId;
#[cw_serde]
pub struct Cw1155ReceiveMsg {
pub operator: String,
pub from: Option<String>,
pub token_id: TokenId,
pub amount: Uint128,
pub msg: Binary,
}
impl Cw1155ReceiveMsg {
pub fn into_binary(self) -> StdResult<Binary> {
let msg = ReceiverExecuteMsg::Receive(self);
to_binary(&msg)
}
pub fn into_cosmos_msg<T: Into<String>>(self, contract_addr: T) -> StdResult<CosmosMsg> {
let msg = self.into_binary()?;
let execute = WasmMsg::Execute {
contract_addr: contract_addr.into(),
msg,
funds: vec![],
};
Ok(execute.into())
}
}
#[cw_serde]
pub struct Cw1155BatchReceiveMsg {
pub operator: String,
pub from: Option<String>,
pub batch: Vec<(TokenId, Uint128)>,
pub msg: Binary,
}
impl Cw1155BatchReceiveMsg {
pub fn into_binary(self) -> StdResult<Binary> {
let msg = ReceiverExecuteMsg::BatchReceive(self);
to_binary(&msg)
}
pub fn into_cosmos_msg<T: Into<String>>(self, contract_addr: T) -> StdResult<CosmosMsg> {
let msg = self.into_binary()?;
let execute = WasmMsg::Execute {
contract_addr: contract_addr.into(),
msg,
funds: vec![],
};
Ok(execute.into())
}
}
#[cw_serde]
enum ReceiverExecuteMsg {
Receive(Cw1155ReceiveMsg),
BatchReceive(Cw1155BatchReceiveMsg),
}