Regtest has a longer hrp, need to adjust length safety check

This commit is contained in:
Franck Royer 2018-07-26 17:06:35 +10:00
parent 0f31608796
commit f05f831569
1 changed files with 6 additions and 4 deletions

View File

@ -246,11 +246,13 @@ impl FromStr for Address {
fn from_str(s: &str) -> Result<Address, Error> {
// bech32 (note that upper or lowercase is allowed but NOT mixed case)
if s.len() >= 3 &&
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.as_bytes()[0..5] == b"bcrt1" || &s.as_bytes()[0..5] == b"BCRT1") {
let witprog = try!(WitnessProgram::from_address(s));
&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"))
{
let witprog = WitnessProgram::from_address(s)?;
let network = match witprog.network() {
bitcoin_bech32::constants::Network::Bitcoin => Network::Bitcoin,
bitcoin_bech32::constants::Network::Testnet => Network::Testnet,