something_for_tests/
msg.rs1use cosmwasm_std::{Binary, StdError, StdResult, Uint128};
2use cw20::{Cw20Coin, Expiration, MinterResponse};
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6#[derive(Serialize, Deserialize, JsonSchema)]
7pub struct InstantiateMsg {
8 pub name: String,
9 pub symbol: String,
10 pub decimals: u8,
11 pub initial_balances: Vec<Cw20Coin>,
12 pub mint: Option<MinterResponse>,
13}
14
15impl InstantiateMsg {
16 pub fn get_cap(&self) -> Option<Uint128> {
17 self.mint.as_ref().and_then(|v| v.cap)
18 }
19
20 pub fn validate(&self) -> StdResult<()> {
21 if !is_valid_name(&self.name) {
23 return Err(StdError::generic_err(
24 "Name is not in the expected format (3-50 UTF-8 bytes)",
25 ));
26 }
27 if !is_valid_symbol(&self.symbol) {
28 return Err(StdError::generic_err(
29 "Ticker symbol is not in expected format [a-zA-Z\\-]{3,12}",
30 ));
31 }
32 if self.decimals > 18 {
33 return Err(StdError::generic_err("Decimals must not exceed 18"));
34 }
35 Ok(())
36 }
37}
38
39fn is_valid_name(name: &str) -> bool {
40 let bytes = name.as_bytes();
41 if bytes.len() < 3 || bytes.len() > 50 {
42 return false;
43 }
44 true
45}
46
47fn is_valid_symbol(symbol: &str) -> bool {
48 let bytes = symbol.as_bytes();
49 if bytes.len() < 3 || bytes.len() > 12 {
50 return false;
51 }
52 for byte in bytes.iter() {
53 if (*byte != 45) && (*byte < 65 || *byte > 90) && (*byte < 97 || *byte > 122) {
54 return false;
55 }
56 }
57 true
58}
59
60#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
61#[serde(rename_all = "snake_case")]
62pub enum ExecuteMsg {
63 Transfer { recipient: String, amount: Uint128 },
65 Burn { amount: Uint128 },
67 Send {
70 contract: String,
71 amount: Uint128,
72 msg: Binary,
73 },
74 Mint { recipient: String, amount: Uint128 },
77 IncreaseAllowance {
81 spender: String,
82 amount: Uint128,
83 expires: Option<Expiration>,
84 },
85 DecreaseAllowance {
89 spender: String,
90 amount: Uint128,
91 expires: Option<Expiration>,
92 },
93 TransferFrom {
96 owner: String,
97 recipient: String,
98 amount: Uint128,
99 },
100 SendFrom {
103 owner: String,
104 contract: String,
105 amount: Uint128,
106 msg: Binary,
107 },
108 BurnFrom { owner: String, amount: Uint128 },
110}
111
112#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
113#[serde(rename_all = "snake_case")]
114pub enum QueryMsg {
115 Balance { address: String },
118 TokenInfo {},
121 Minter {},
125 Allowance { owner: String, spender: String },
129 AllAllowances {
133 owner: String,
134 start_after: Option<String>,
135 limit: Option<u32>,
136 },
137 AllAccounts {
141 start_after: Option<String>,
142 limit: Option<u32>,
143 },
144}