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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#![allow(clippy::field_reassign_with_default)] use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use cosmwasm_std::{to_binary, Binary, CosmosMsg, Addr, StdResult, Uint128, WasmMsg};
use crate::{state::RESPONSE_BLOCK_SIZE, msg::space_pad};
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub struct Snip1155ReceiveMsg {
pub sender: Addr,
pub token_id: String,
pub from: Addr,
pub amount: Uint128,
#[serde(skip_serializing_if = "Option::is_none")]
pub memo: Option<String>,
pub msg: Option<Binary>,
}
impl Snip1155ReceiveMsg {
pub fn new(
sender: Addr,
token_id: String,
from: Addr,
amount: Uint128,
memo: Option<String>,
msg: Option<Binary>,
) -> Self {
Self {
sender,
token_id,
from,
amount,
memo,
msg,
}
}
pub fn into_binary(self) -> StdResult<Binary> {
let msg = ReceiverHandleMsg::Snip1155Receive(self);
let mut data = to_binary(&msg)?;
space_pad(RESPONSE_BLOCK_SIZE, &mut data.0);
Ok(data)
}
pub fn into_cosmos_msg(
self,
code_hash: String,
contract_addr: Addr,
) -> StdResult<CosmosMsg> {
let msg = self.into_binary()?;
let execute = WasmMsg::Execute {
msg,
code_hash,
contract_addr: contract_addr.to_string(),
funds: vec![],
};
Ok(execute.into())
}
}
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum ReceiverHandleMsg {
Snip1155Receive(Snip1155ReceiveMsg),
}