Merge pull request #144 from jeandudey/2018-08-address-starts-with

trivial: Use `str::starts_with` method to check bech32 address prefixes.
This commit is contained in:
Andrew Poelstra 2018-08-20 23:12:03 +00:00 committed by GitHub
commit 77e2fe3dda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 5 deletions

View File

@ -247,11 +247,9 @@ impl FromStr for Address {
fn from_str(s: &str) -> Result<Address, Error> { fn from_str(s: &str) -> Result<Address, Error> {
// bech32 (note that upper or lowercase is allowed but NOT mixed case) // bech32 (note that upper or lowercase is allowed but NOT mixed case)
if (s.len() >= 3 && if s.starts_with("bc1") || s.starts_with("BC1") ||
(&s.as_bytes()[0..3] == b"bc1" || &s.as_bytes()[0..3] == b"BC1" || s.starts_with("tb1") || s.starts_with("TB1") ||
&s.as_bytes()[0..3] == b"tb1" || &s.as_bytes()[0..3] == b"TB1" )) || s.starts_with("bcrt1") || s.starts_with("BCRT1")
(s.len() >= 5 &&
(&s.as_bytes()[0..5] == b"bcrt1" || &s.as_bytes()[0..5] == b"BCRT1"))
{ {
let witprog = WitnessProgram::from_address(s)?; let witprog = WitnessProgram::from_address(s)?;
let network = match witprog.network() { let network = match witprog.network() {