use bitcoin-bech32 v0.8.0 and adapt internal API usage

This commit is contained in:
Sebastian Geisler 2018-06-21 20:45:58 +02:00
parent 9ab2aa52fd
commit 00cca03edd
2 changed files with 11 additions and 7 deletions

View File

@ -20,7 +20,7 @@ bitcoinconsenus = ["bitcoinconsensus"]
fuzztarget = ["secp256k1/fuzztarget"] fuzztarget = ["secp256k1/fuzztarget"]
[dependencies] [dependencies]
bitcoin-bech32 = "0.5.1" bitcoin-bech32 = "0.8.0"
byteorder = "1.1" byteorder = "1.1"
rand = "0.3" rand = "0.3"
rust-crypto = "0.2" rust-crypto = "0.2"

View File

@ -18,7 +18,7 @@
use std::str::FromStr; use std::str::FromStr;
use std::string::ToString; use std::string::ToString;
use bitcoin_bech32::{self, WitnessProgram}; use bitcoin_bech32::{self, WitnessProgram, u5};
use secp256k1::key::PublicKey; use secp256k1::key::PublicKey;
use blockdata::script; use blockdata::script;
@ -100,7 +100,7 @@ impl Address {
network: network, network: network,
payload: Payload::WitnessProgram( payload: Payload::WitnessProgram(
// unwrap is safe as witness program is known to be correct as above // unwrap is safe as witness program is known to be correct as above
WitnessProgram::new(0, WitnessProgram::new(u5::try_from_u8(0).expect("0<32"),
Hash160::from_data(&pk.serialize()[..])[..].to_vec(), Hash160::from_data(&pk.serialize()[..])[..].to_vec(),
Address::bech_network(network)).unwrap()) Address::bech_network(network)).unwrap())
} }
@ -134,7 +134,11 @@ impl Address {
network: network, network: network,
payload: Payload::WitnessProgram( payload: Payload::WitnessProgram(
// unwrap is safe as witness program is known to be correct as above // unwrap is safe as witness program is known to be correct as above
WitnessProgram::new(0, d.to_vec(), Address::bech_network(network)).unwrap() WitnessProgram::new(
u5::try_from_u8(0).expect("0<32"),
d.to_vec(),
Address::bech_network(network)
).unwrap()
) )
} }
} }
@ -190,7 +194,7 @@ impl Address {
}, },
Payload::WitnessProgram(ref witprog) => { Payload::WitnessProgram(ref witprog) => {
script::Builder::new() script::Builder::new()
.push_int(witprog.version() as i64) .push_int(witprog.version().to_u8() as i64)
.push_slice(witprog.program()) .push_slice(witprog.program())
} }
}.into_script() }.into_script()
@ -250,8 +254,8 @@ impl FromStr for Address {
bitcoin_bech32::constants::Network::Testnet => Network::Testnet, bitcoin_bech32::constants::Network::Testnet => Network::Testnet,
_ => panic!("unknown network") _ => panic!("unknown network")
}; };
if witprog.version() != 0 { if witprog.version().to_u8() != 0 {
return Err(Error::UnsupportedWitnessVersion(witprog.version())); return Err(Error::UnsupportedWitnessVersion(witprog.version().to_u8()));
} }
return Ok(Address { return Ok(Address {
network: network, network: network,