From f90b901b4ef7f9e8ac0057e3d400b501c88df3fb Mon Sep 17 00:00:00 2001 From: 2581015450 <2581015450@qq.com> Date: Thu, 26 Oct 2023 05:02:34 +0800 Subject: [PATCH] feat: validation for NeoAddress --- anychain-neo/src/address.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/anychain-neo/src/address.rs b/anychain-neo/src/address.rs index 17eefd5..d9246f7 100644 --- a/anychain-neo/src/address.rs +++ b/anychain-neo/src/address.rs @@ -61,6 +61,14 @@ impl FromStr for NeoAddress { type Err = AddressError; fn from_str(s: &str) -> Result { + let bytes = s.from_base58()?; + let checksum_provided = bytes[21..].to_vec(); + let checksum_gen = checksum(&bytes[..21])[..4].to_vec(); + + if checksum_gen != checksum_provided { + return Err(AddressError::Message(format!("Invalid address {}", s))); + } + Ok(Self(s.to_string())) } }