-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
I was recently looking into native denom validation, and it turns out there are actually some reasonably strict rules in the SDK as to what strings may be denominations. We should be able to perform that validation in a contract reasonably enough. From dao-contracts:
/// Follows cosmos SDK validation logic. Specifically, the regex
/// string `[a-zA-Z][a-zA-Z0-9/:._-]{2,127}`.
///
/// <https://github.com/cosmos/cosmos-sdk/blob/7728516abfab950dc7a9120caad4870f1f962df5/types/coin.go#L865-L867>
pub fn validate_native_denom(denom: String) -> Result<String, DenomError> {
if denom.len() < 3 || denom.len() > 128 {
return Err(DenomError::NativeDenomLength { len: denom.len() });
}
let mut chars = denom.chars();
// Really this means that a non utf-8 character is in here, but
// non-ascii is also correct.
let first = chars.next().ok_or(DenomError::NonAlphabeticAscii)?;
if !first.is_ascii_alphabetic() {
return Err(DenomError::NonAlphabeticAscii);
}
for c in chars {
if !(c.is_ascii_alphanumeric() || c == '/' || c == ':' || c == '.' || c == '_' || c == '-')
{
return Err(DenomError::InvalidCharacter { c });
}
}
Ok(denom)
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels