Skip to main content

lotus_tokenfactory/
common.rs

1use cosmwasm_schema::cw_serde;
2use cosmwasm_std::{AnyMsg, CosmosMsg, StdResult};
3
4#[cw_serde]
5enum Protocol {
6    Osmosis,
7}
8
9impl Protocol {
10    #![allow(dead_code)]
11    fn from_features() -> Self {
12        Self::Osmosis
13    }
14    #[allow(unused_assignments)]
15    fn as_str(&self) -> &'static str {
16        match self {
17            Self::Osmosis => "osmosis",
18        }
19    }
20}
21
22#[allow(dead_code)]
23pub(crate) enum MsgTypes {
24    SetBeforeSendHook,
25    CreateDenom,
26    Mint,
27    Burn,
28}
29
30impl MsgTypes {
31    #[allow(dead_code)]
32    pub fn as_str(&self) -> &'static str {
33        match self {
34            Self::CreateDenom => "MsgCreateDenom",
35            Self::Mint => "MsgMint",
36            Self::Burn => "MsgBurn",
37            Self::SetBeforeSendHook => "MsgSetBeforeSendHook",
38        }
39    }
40}
41
42pub trait EncodeMessage {
43    /// Encodes the data as a proto doc
44    fn encode(data: Self) -> Vec<u8>;
45
46    /// Decodes the data from a proto doc. Only used for tests.
47    fn decode(data: Vec<u8>) -> StdResult<Self>
48    where
49        Self: Sized;
50}
51
52#[allow(dead_code)]
53pub(crate) fn create_msg<M: EncodeMessage>(message_data: M, msg_type: &str) -> CosmosMsg {
54    CosmosMsg::Any(AnyMsg {
55        type_url: format!(
56            "/{}.tokenfactory.v1beta1.{}",
57            Protocol::from_features().as_str(),
58            msg_type
59        ),
60        value: M::encode(message_data).into(),
61    })
62}