Skip to content

Commit 6609dd8

Browse files
Apply suggestions from code review
Co-authored-by: Hubert <lesny.rumcajs@gmail.com>
1 parent 336d8bf commit 6609dd8

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/address.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ fn check_address_prefix(s: &str, n: Network) -> bool {
1818
}
1919

2020
fn is_eth_address(s: &str) -> bool {
21-
s.len() > 2 && s[0..2].eq("0x")
21+
s.starts_with("0x")
22+
&& s.len() == ETH_ADDRESS_LENGTH
23+
&& s.chars().skip(2).all(|c| c.is_ascii_hexdigit())
2224
}
2325

2426
pub fn parse_address(raw: &str, n: Network) -> anyhow::Result<Address> {
@@ -29,10 +31,6 @@ pub fn parse_address(raw: &str, n: Network) -> anyhow::Result<Address> {
2931
}
3032

3133
if is_eth_address(&s) {
32-
if s.len() != ETH_ADDRESS_LENGTH {
33-
bail!("Invalid address length")
34-
}
35-
3634
let addr = hex::decode(&s[2..])?;
3735
Ok(Address::new_delegated(EAM_NAMESPACE, &addr)?)
3836
} else {

0 commit comments

Comments
 (0)