Skip to main content

lotus_tokenfactory/
create_denom.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 MsgCreateDenom Stargate message
11pub fn create_denom(sender: Addr, subdenom: String) -> CosmosMsg {
12    let message_data = MsgCreateDenom {
13        sender: sender.to_string(),
14        subdenom,
15    };
16    create_msg(message_data, MsgTypes::CreateDenom.as_str())
17}
18
19#[cw_serde]
20pub struct MsgCreateDenom {
21    pub sender: String,
22    pub subdenom: String,
23}
24
25impl EncodeMessage for MsgCreateDenom {
26    fn encode(data: Self) -> Vec<u8> {
27        Anybuf::new()
28            .append_string(1, data.sender)
29            .append_string(2, data.subdenom)
30            .into_vec()
31    }
32
33    fn decode(data: Vec<u8>) -> StdResult<Self>
34    where
35        Self: Sized,
36    {
37        let deserialized = Bufany::deserialize(&data).unwrap();
38        Ok(Self {
39            sender: deserialized.string(1).unwrap(),
40            subdenom: deserialized.string(2).unwrap(),
41        })
42    }
43}
44
45/// MsgCreateDenomResponse is the return value of MsgCreateDenom It returns the full string of the newly created denom
46#[cw_serde]
47pub struct MsgCreateDenomResponse {
48    pub new_token_denom: String,
49}