util/address: avoid .expect/panic
This commit is contained in:
parent
ad83f6ae00
commit
f826316c25
|
@ -409,10 +409,7 @@ impl Payload {
|
||||||
/// Creates a pay to (compressed) public key hash payload from a public key
|
/// Creates a pay to (compressed) public key hash payload from a public key
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn p2pkh(pk: &ecdsa::PublicKey) -> Payload {
|
pub fn p2pkh(pk: &ecdsa::PublicKey) -> Payload {
|
||||||
let mut hash_engine = PubkeyHash::engine();
|
Payload::PubkeyHash(PubkeyHash::hash(&pk.to_bytes()))
|
||||||
pk.write_into(&mut hash_engine)
|
|
||||||
.expect("engines don't error");
|
|
||||||
Payload::PubkeyHash(PubkeyHash::from_engine(hash_engine))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a pay to script hash P2SH payload from a script
|
/// Creates a pay to script hash P2SH payload from a script
|
||||||
|
@ -430,13 +427,9 @@ impl Payload {
|
||||||
return Err(Error::UncompressedPubkey);
|
return Err(Error::UncompressedPubkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut hash_engine = WPubkeyHash::engine();
|
|
||||||
pk.write_into(&mut hash_engine)
|
|
||||||
.expect("engines don't error");
|
|
||||||
|
|
||||||
Ok(Payload::WitnessProgram {
|
Ok(Payload::WitnessProgram {
|
||||||
version: WitnessVersion::V0,
|
version: WitnessVersion::V0,
|
||||||
program: WPubkeyHash::from_engine(hash_engine)[..].to_vec(),
|
program: WPubkeyHash::hash(&pk.to_bytes())[..].to_vec(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,13 +439,9 @@ impl Payload {
|
||||||
return Err(Error::UncompressedPubkey);
|
return Err(Error::UncompressedPubkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut hash_engine = WPubkeyHash::engine();
|
|
||||||
pk.write_into(&mut hash_engine)
|
|
||||||
.expect("engines don't error");
|
|
||||||
|
|
||||||
let builder = script::Builder::new()
|
let builder = script::Builder::new()
|
||||||
.push_int(0)
|
.push_int(0)
|
||||||
.push_slice(&WPubkeyHash::from_engine(hash_engine)[..]);
|
.push_slice(&WPubkeyHash::hash(&pk.to_bytes())[..]);
|
||||||
|
|
||||||
Ok(Payload::ScriptHash(ScriptHash::hash(
|
Ok(Payload::ScriptHash(ScriptHash::hash(
|
||||||
builder.into_script().as_bytes(),
|
builder.into_script().as_bytes(),
|
||||||
|
|
Loading…
Reference in New Issue