diff --git a/cosmrs/src/base/account_id.rs b/cosmrs/src/base/account_id.rs index d8260e84..199284c1 100644 --- a/cosmrs/src/base/account_id.rs +++ b/cosmrs/src/base/account_id.rs @@ -79,7 +79,12 @@ impl FromStr for AccountId { type Err = ErrorReport; fn from_str(s: &str) -> Result { - let (hrp, bytes) = bech32::decode(s).wrap_err(format!("invalid bech32: '{}'", s))?; + let (hrp, bytes) = if s.starts_with(|c: char| c.is_uppercase()) { + bech32::decode_upper(s) + } else { + bech32::decode(s) + } + .wrap_err(format!("invalid bech32: '{}'", s))?; Self::new(&hrp, &bytes) } } @@ -148,6 +153,14 @@ mod tests { .unwrap(); } + /// See https://en.bitcoin.it/wiki/BIP_0173 -- UPPERCASE is a valid bech32 + #[test] + fn with_uppercase() { + "STARS1JUME25TTJLCAQQJZJJQX9HUMVZE3VCC8QF2KWL" + .parse::() + .unwrap(); + } + #[test] fn to_string() { let account_id = "juno10j9gpw9t4jsz47qgnkvl5n3zlm2fz72k67rxsg"