Skip to content

Commit b9c9caa

Browse files
authored
cosmrs: update AccountId validation to match Cosmos SDK (#197)
This Cosmos SDK change allows variable-sized addresses: cosmos/cosmos-sdk#8363 This commit changes the validation logic to support addresses whose lengths are `1..=255`.
1 parent c0c9277 commit b9c9caa

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

cosmrs/src/base.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ use serde::{de, de::Error as _, ser, Deserialize, Serialize};
66
use std::{fmt, str::FromStr};
77
use subtle_encoding::bech32;
88

9+
/// Maximum allowed length (in bytes) for an address.
10+
pub const MAX_ADDRESS_LENGTH: usize = 255;
11+
912
/// Account identifiers
1013
#[derive(Clone, Eq, PartialEq, PartialOrd, Ord)]
1114
pub struct AccountId {
@@ -72,16 +75,16 @@ impl FromStr for AccountId {
7275
fn from_str(s: &str) -> Result<Self> {
7376
let (hrp, bytes) = bech32::decode(s).wrap_err("failed to decode bech32")?;
7477

75-
if bytes.len() == tendermint::account::LENGTH {
78+
if matches!(bytes.len(), 1..=MAX_ADDRESS_LENGTH) {
7679
Ok(Self {
7780
bech32: s.to_owned(),
7881
hrp_length: hrp.len(),
7982
})
8083
} else {
8184
Err(Error::AccountId { id: s.to_owned() }).wrap_err_with(|| {
8285
format!(
83-
"account ID should be at least {} bytes long, but was {} bytes long",
84-
tendermint::account::LENGTH,
86+
"account ID should be at most {} bytes long, but was {} bytes long",
87+
MAX_ADDRESS_LENGTH,
8588
bytes.len()
8689
)
8790
})

0 commit comments

Comments
 (0)