Skip to main content

lotus_tokenfactory/
set_before_send_hook.rs

1use crate::common::{create_msg, MsgTypes};
2use anybuf::{Anybuf, Bufany};
3use cosmwasm_schema::cw_serde;
4use cosmwasm_std::StdResult;
5
6use cosmwasm_std::{Addr, CosmosMsg};
7
8use crate::common::EncodeMessage;
9
10/// Returns the MsgSetBeforeSendHook Stargate message
11pub fn set_before_send_hook(sender: Addr, denom: String, contract_addr: String) -> CosmosMsg {
12    let message_data = MsgSetBeforeSendHook {
13        sender: sender.to_string(),
14        denom,
15        contract_addr,
16    };
17    create_msg(message_data, MsgTypes::SetBeforeSendHook.as_str())
18}
19
20#[cw_serde]
21pub struct MsgSetBeforeSendHook {
22    pub sender: String,
23    pub denom: String,
24    pub contract_addr: String,
25}
26
27impl EncodeMessage for MsgSetBeforeSendHook {
28    fn encode(data: Self) -> Vec<u8> {
29        Anybuf::new()
30            .append_string(1, data.sender)
31            .append_string(2, data.denom)
32            .append_string(3, data.contract_addr)
33            .into_vec()
34    }
35
36    fn decode(data: Vec<u8>) -> StdResult<Self>
37    where
38        Self: Sized,
39    {
40        let deserialized = Bufany::deserialize(&data).unwrap();
41        Ok(Self {
42            sender: deserialized.string(1).unwrap(),
43            denom: deserialized.string(2).unwrap(),
44            contract_addr: deserialized.string(3).unwrap(),
45        })
46    }
47}
48
49/// MsgSetBeforeSendHookResponse defines the response structure for an executed
50/// MsgSetBeforeSendHook message.
51#[cw_serde]
52pub struct MsgSetBeforeSendHookResponse {
53    pub new_token_denom: String,
54}