From b78d7a74284bfbc4d334644c6ec5b648f2f83ca8 Mon Sep 17 00:00:00 2001 From: Jean Pierre Dudey Date: Mon, 20 Aug 2018 18:11:14 -0400 Subject: [PATCH] Use `str::starts_with` method to check bech32 address prefixes. Signed-off-by: Jean Pierre Dudey --- src/util/address.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/util/address.rs b/src/util/address.rs index 1d2cee45..d4175708 100644 --- a/src/util/address.rs +++ b/src/util/address.rs @@ -247,11 +247,9 @@ impl FromStr for Address { fn from_str(s: &str) -> Result { // bech32 (note that upper or lowercase is allowed but NOT mixed case) - if (s.len() >= 3 && - (&s.as_bytes()[0..3] == b"bc1" || &s.as_bytes()[0..3] == b"BC1" || - &s.as_bytes()[0..3] == b"tb1" || &s.as_bytes()[0..3] == b"TB1" )) || - (s.len() >= 5 && - (&s.as_bytes()[0..5] == b"bcrt1" || &s.as_bytes()[0..5] == b"BCRT1")) + if s.starts_with("bc1") || s.starts_with("BC1") || + s.starts_with("tb1") || s.starts_with("TB1") || + s.starts_with("bcrt1") || s.starts_with("BCRT1") { let witprog = WitnessProgram::from_address(s)?; let network = match witprog.network() {