-
Notifications
You must be signed in to change notification settings - Fork 179
/
Copy pathreceiver.rs
44 lines (39 loc) · 1.29 KB
/
receiver.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use schemars::JsonSchema;
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{to_json_binary, Binary, CosmosMsg, StdResult, WasmMsg};
/// Cw721ReceiveMsg should be de/serialized under `Receive()` variant in a ExecuteMsg
#[cw_serde]
pub struct Cw721ReceiveMsg {
pub sender: String,
pub token_id: String,
pub msg: Binary,
}
impl Cw721ReceiveMsg {
/// serializes the message
pub fn into_json_binary(self) -> StdResult<Binary> {
let msg = ReceiverExecuteMsg::ReceiveNft(self);
to_json_binary(&msg)
}
/// creates a cosmos_msg sending this struct to the named contract
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())
}
}
/// This is just a helper to properly serialize the above message.
/// The actual receiver should include this variant in the larger ExecuteMsg enum
#[cw_serde]
pub enum ReceiverExecuteMsg {
ReceiveNft(Cw721ReceiveMsg),
}