1#![allow(clippy::field_reassign_with_default)] use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6use cosmwasm_std::{to_binary, Binary, CosmosMsg, HumanAddr, StdResult, Uint128, WasmMsg};
7
8use crate::{contract::RESPONSE_BLOCK_SIZE, msg::space_pad};
9
10#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
12#[serde(rename_all = "snake_case")]
13pub struct Hmip20ReceiveMsg {
14 pub sender: HumanAddr,
15 pub from: HumanAddr,
16 pub amount: Uint128,
17 #[serde(skip_serializing_if = "Option::is_none")]
18 pub memo: Option<String>,
19 pub msg: Option<Binary>,
20}
21
22impl Hmip20ReceiveMsg {
23 pub fn new(
24 sender: HumanAddr,
25 from: HumanAddr,
26 amount: Uint128,
27 memo: Option<String>,
28 msg: Option<Binary>,
29 ) -> Self {
30 Self {
31 sender,
32 from,
33 amount,
34 memo,
35 msg,
36 }
37 }
38
39 pub fn into_binary(self) -> StdResult<Binary> {
41 let msg = ReceiverHandleMsg::Receive(self);
42 let mut data = to_binary(&msg)?;
43 space_pad(RESPONSE_BLOCK_SIZE, &mut data.0);
44 Ok(data)
45 }
46
47 pub fn into_cosmos_msg(
49 self,
50 callback_code_hash: String,
51 contract_addr: HumanAddr,
52 ) -> StdResult<CosmosMsg> {
53 let msg = self.into_binary()?;
54 let execute = WasmMsg::Execute {
55 msg,
56 callback_code_hash,
57 contract_addr,
58 send: vec![],
59 };
60 Ok(execute.into())
61 }
62}
63
64#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
66#[serde(rename_all = "snake_case")]
67enum ReceiverHandleMsg {
68 Receive(Hmip20ReceiveMsg),
69}