Style: move `InstantiateMsg` validation in impl
@@ -30,12 +30,12 @@ impl InstantiateMsg {
pub fn validate(&self) -> StdResult<()> {
// Check name, symbol, decimals
- if !is_valid_name(&self.name) {
+ if !self.has_valid_name() {
return Err(StdError::generic_err(
"Name is not in the expected format (3-50 UTF-8 bytes)",
));
}
- if !is_valid_symbol(&self.symbol) {
+ if !self.has_valid_symbol() {
return Err(StdError::generic_err(
"Ticker symbol is not in expected format [a-zA-Z\\-]{3,12}",
));
@@ -45,18 +45,17 @@ impl InstantiateMsg {
}
Ok(())
}
-}
-fn is_valid_name(name: &str) -> bool {
- let bytes = name.as_bytes();
+ fn has_valid_name(&self) -> bool {
+ let bytes = self.name.as_bytes();
if bytes.len() < 3 || bytes.len() > 50 {
return false;
}
true
}
-fn is_valid_symbol(symbol: &str) -> bool {
- let bytes = symbol.as_bytes();
+ fn has_valid_symbol(&self) -> bool {
+ let bytes = self.symbol.as_bytes();
if bytes.len() < 3 || bytes.len() > 12 {
return false;
}
@@ -67,6 +66,7 @@ fn is_valid_symbol(symbol: &str) -> bool {
}
true
}
+}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
