Skip to content

Commit 3092830

Browse files
committed
Simplify to_pubkeyhash
All the non-string keys use hash160 hashes, we can simplify the logic by mirroring the current implementation for `XOnlyPublicKey`.
1 parent d495945 commit 3092830

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

src/lib.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ pub mod psbt;
116116

117117
mod util;
118118

119-
use std::io::Write;
120119
use std::str::FromStr;
121120
use std::{error, fmt, hash, str};
122121

@@ -157,11 +156,7 @@ impl MiniscriptKey for bitcoin::secp256k1::PublicKey {
157156
type Hash = hash160::Hash;
158157

159158
fn to_pubkeyhash(&self) -> Self::Hash {
160-
let mut engine = hash160::Hash::engine();
161-
engine
162-
.write_all(&self.serialize())
163-
.expect("engines don't error");
164-
hash160::Hash::from_engine(engine)
159+
hash160::Hash::hash(&self.serialize())
165160
}
166161
}
167162

@@ -174,9 +169,7 @@ impl MiniscriptKey for bitcoin::PublicKey {
174169
type Hash = hash160::Hash;
175170

176171
fn to_pubkeyhash(&self) -> Self::Hash {
177-
let mut engine = hash160::Hash::engine();
178-
self.write_into(&mut engine).expect("engines don't error");
179-
hash160::Hash::from_engine(engine)
172+
hash160::Hash::hash(&self.to_bytes())
180173
}
181174
}
182175

0 commit comments

Comments
 (0)