Skip to content

Commit

Permalink
feat: validation for NeoAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
aya015757881 committed Oct 25, 2023
1 parent 1bc84f9 commit f90b901
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions anychain-neo/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ impl FromStr for NeoAddress {
type Err = AddressError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
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()))
}
}
Expand Down

0 comments on commit f90b901

Please sign in to comment.