Return Result<(), io::Error> from PublicKey::write_into
This commit is contained in:
parent
90e1125eff
commit
9699c622fc
|
@ -222,7 +222,7 @@ impl Address {
|
|||
#[inline]
|
||||
pub fn p2pkh(pk: &key::PublicKey, network: Network) -> Address {
|
||||
let mut hash_engine = PubkeyHash::engine();
|
||||
pk.write_into(&mut hash_engine);
|
||||
pk.write_into(&mut hash_engine).expect("engines don't error");
|
||||
|
||||
Address {
|
||||
network: network,
|
||||
|
@ -250,7 +250,7 @@ impl Address {
|
|||
}
|
||||
|
||||
let mut hash_engine = WPubkeyHash::engine();
|
||||
pk.write_into(&mut hash_engine);
|
||||
pk.write_into(&mut hash_engine).expect("engines don't error");
|
||||
|
||||
Ok(Address {
|
||||
network: network,
|
||||
|
@ -271,7 +271,7 @@ impl Address {
|
|||
}
|
||||
|
||||
let mut hash_engine = WPubkeyHash::engine();
|
||||
pk.write_into(&mut hash_engine);
|
||||
pk.write_into(&mut hash_engine).expect("engines don't error");
|
||||
|
||||
let builder = script::Builder::new()
|
||||
.push_int(0)
|
||||
|
|
|
@ -575,7 +575,7 @@ impl ExtendedPubKey {
|
|||
/// Returns the HASH160 of the public key of the xpub
|
||||
pub fn identifier(&self) -> XpubIdentifier {
|
||||
let mut engine = XpubIdentifier::engine();
|
||||
self.public_key.write_into(&mut engine);
|
||||
self.public_key.write_into(&mut engine).expect("engines don't error");
|
||||
XpubIdentifier::from_engine(engine)
|
||||
}
|
||||
|
||||
|
|
|
@ -101,18 +101,18 @@ impl PublicKey {
|
|||
}
|
||||
|
||||
/// Write the public key into a writer
|
||||
pub fn write_into<W: io::Write>(&self, mut writer: W) {
|
||||
let _: io::Result<()> = if self.compressed {
|
||||
pub fn write_into<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
|
||||
if self.compressed {
|
||||
writer.write_all(&self.key.serialize())
|
||||
} else {
|
||||
writer.write_all(&self.key.serialize_uncompressed())
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// Serialize the public key to bytes
|
||||
pub fn to_bytes(&self) -> Vec<u8> {
|
||||
let mut buf = Vec::new();
|
||||
self.write_into(&mut buf);
|
||||
self.write_into(&mut buf).expect("vecs don't error");
|
||||
buf
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ impl Deserialize for Script {
|
|||
impl Serialize for PublicKey {
|
||||
fn serialize(&self) -> Vec<u8> {
|
||||
let mut buf = Vec::new();
|
||||
self.write_into(&mut buf);
|
||||
self.write_into(&mut buf).expect("vecs don't error");
|
||||
buf
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue