Skip to content

Commit

Permalink
Style: move InstantiateMsg validation in impl
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-napoleone committed Aug 8, 2022
1 parent fc79cdd commit 453fabe
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions contracts/cw20-base/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
));
Expand All @@ -45,27 +45,27 @@ impl InstantiateMsg {
}
Ok(())
}
}

fn is_valid_name(name: &str) -> bool {
let bytes = name.as_bytes();
if bytes.len() < 3 || bytes.len() > 50 {
return false;
fn has_valid_name(&self) -> bool {
let bytes = self.name.as_bytes();
if bytes.len() < 3 || bytes.len() > 50 {
return false;
}
true
}
true
}

fn is_valid_symbol(symbol: &str) -> bool {
let bytes = symbol.as_bytes();
if bytes.len() < 3 || bytes.len() > 12 {
return false;
}
for byte in bytes.iter() {
if (*byte != 45) && (*byte < 65 || *byte > 90) && (*byte < 97 || *byte > 122) {
fn has_valid_symbol(&self) -> bool {
let bytes = self.symbol.as_bytes();
if bytes.len() < 3 || bytes.len() > 12 {
return false;
}
for byte in bytes.iter() {
if (*byte != 45) && (*byte < 65 || *byte > 90) && (*byte < 97 || *byte > 122) {
return false;
}
}
true
}
true
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
Expand Down

0 comments on commit 453fabe

Please sign in to comment.