diem_types/account_config/constants/
diem.rs1use anyhow::{bail, Result};
9use move_core_types::identifier::Identifier;
10
11pub fn allowed_currency_code_string(
15 possible_currency_code_string: &str,
16) -> bool {
17 possible_currency_code_string
18 .chars()
19 .all(|chr| matches!(chr, 'A'..='Z' | '0'..='9'))
20 && Identifier::is_valid(possible_currency_code_string)
21}
22
23pub fn from_currency_code_string(
24 currency_code_string: &str,
25) -> Result<Identifier> {
26 if !allowed_currency_code_string(currency_code_string) {
27 bail!("Invalid currency code '{}'", currency_code_string)
28 }
29 Identifier::new(currency_code_string)
30}