diem_types/account_config/constants/
diem.rs1use crate::account_config::constants::CORE_CODE_ADDRESS;
9use anyhow::{bail, Result};
10use move_core_types::{
11 identifier::Identifier,
12 language_storage::{ModuleId, StructTag, TypeTag},
13};
14use once_cell::sync::Lazy;
15
16pub const DIEM_MODULE_NAME: &str = "Diem";
17static COIN_MODULE_NAME: Lazy<Identifier> =
18 Lazy::new(|| Identifier::new("Diem").unwrap());
19pub static COIN_MODULE: Lazy<ModuleId> =
20 Lazy::new(|| ModuleId::new(CORE_CODE_ADDRESS, COIN_MODULE_NAME.clone()));
21
22pub fn type_tag_for_currency_code(currency_code: Identifier) -> TypeTag {
29 TypeTag::Struct(StructTag {
30 address: CORE_CODE_ADDRESS,
31 module: currency_code.clone(),
32 name: currency_code,
33 type_params: vec![],
34 })
35}
36
37pub fn allowed_currency_code_string(
41 possible_currency_code_string: &str,
42) -> bool {
43 possible_currency_code_string
44 .chars()
45 .all(|chr| matches!(chr, 'A'..='Z' | '0'..='9'))
46 && Identifier::is_valid(possible_currency_code_string)
47}
48
49pub fn from_currency_code_string(
50 currency_code_string: &str,
51) -> Result<Identifier> {
52 if !allowed_currency_code_string(currency_code_string) {
53 bail!("Invalid currency code '{}'", currency_code_string)
54 }
55 Identifier::new(currency_code_string)
56}