github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/dev/wasm/cw20-base/src/msg.rs (about) 1 use cosmwasm_std::{StdError, StdResult, Uint128}; 2 use cw20::{Cw20Coin, Logo, MinterResponse}; 3 use schemars::JsonSchema; 4 use serde::{Deserialize, Serialize}; 5 6 pub use cw20::Cw20ExecuteMsg as ExecuteMsg; 7 8 #[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] 9 pub struct InstantiateMarketingInfo { 10 pub project: Option<String>, 11 pub description: Option<String>, 12 pub marketing: Option<String>, 13 pub logo: Option<Logo>, 14 } 15 16 #[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] 17 pub struct InstantiateMsg { 18 pub name: String, 19 pub symbol: String, 20 pub decimals: u8, 21 pub initial_balances: Vec<Cw20Coin>, 22 pub mint: Option<MinterResponse>, 23 pub marketing: Option<InstantiateMarketingInfo>, 24 } 25 26 impl InstantiateMsg { 27 pub fn get_cap(&self) -> Option<Uint128> { 28 self.mint.as_ref().and_then(|v| v.cap) 29 } 30 31 pub fn validate(&self) -> StdResult<()> { 32 // Check name, symbol, decimals 33 if !is_valid_name(&self.name) { 34 return Err(StdError::generic_err( 35 "Name is not in the expected format (3-50 UTF-8 bytes)", 36 )); 37 } 38 if !is_valid_symbol(&self.symbol) { 39 return Err(StdError::generic_err( 40 "Ticker symbol is not in expected format [a-zA-Z\\-]{3,12}", 41 )); 42 } 43 if self.decimals > 18 { 44 return Err(StdError::generic_err("Decimals must not exceed 18")); 45 } 46 Ok(()) 47 } 48 } 49 50 fn is_valid_name(name: &str) -> bool { 51 let bytes = name.as_bytes(); 52 if bytes.len() < 3 || bytes.len() > 50 { 53 return false; 54 } 55 true 56 } 57 58 fn is_valid_symbol(symbol: &str) -> bool { 59 let bytes = symbol.as_bytes(); 60 if bytes.len() < 3 || bytes.len() > 12 { 61 return false; 62 } 63 for byte in bytes.iter() { 64 if (*byte != 45) && (*byte < 65 || *byte > 90) && (*byte < 97 || *byte > 122) { 65 return false; 66 } 67 } 68 true 69 } 70 71 #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] 72 #[serde(rename_all = "snake_case")] 73 pub enum QueryMsg { 74 /// Returns the current balance of the given address, 0 if unset. 75 /// Return type: BalanceResponse. 76 Balance { address: String }, 77 /// Returns metadata on the contract - name, decimals, supply, etc. 78 /// Return type: TokenInfoResponse. 79 TokenInfo {}, 80 /// Only with "mintable" extension. 81 /// Returns who can mint and the hard cap on maximum tokens after minting. 82 /// Return type: MinterResponse. 83 Minter {}, 84 /// Only with "allowance" extension. 85 /// Returns how much spender can use from owner account, 0 if unset. 86 /// Return type: AllowanceResponse. 87 Allowance { owner: String, spender: String }, 88 /// Only with "enumerable" extension (and "allowances") 89 /// Returns all allowances this owner has approved. Supports pagination. 90 /// Return type: AllAllowancesResponse. 91 AllAllowances { 92 owner: String, 93 start_after: Option<String>, 94 limit: Option<u32>, 95 }, 96 /// Only with "enumerable" extension 97 /// Returns all accounts that have balances. Supports pagination. 98 /// Return type: AllAccountsResponse. 99 AllAccounts { 100 start_after: Option<String>, 101 limit: Option<u32>, 102 }, 103 /// Only with "marketing" extension 104 /// Returns more metadata on the contract to display in the client: 105 /// - description, logo, project url, etc. 106 /// Return type: MarketingInfoResponse 107 MarketingInfo {}, 108 /// Only with "marketing" extension 109 /// Downloads the embedded logo data (if stored on chain). Errors if no logo data is stored for this 110 /// contract. 111 /// Return type: DownloadLogoResponse. 112 DownloadLogo {}, 113 }