Skip to content

Commit 104eb55

Browse files
committed
Merge #402: Implement hash::Hash for Miniscript
4ac68c9 Implement hash::Hash for Miniscript (Tobin C. Harding) Pull request description: We manually implement a bunch of traits on `Miniscript` that pass through to the `node` field (e.g. `PartialEq`). We should do the same for `hash::Hash` instead of deriving it. Found by clippy. Fixes: #381 ACKs for top commit: apoelstra: ACK 4ac68c9 Tree-SHA512: 7920481034bee12fbfdbdfac2f38e9598e25a13a8a89b6b50cc7f63ce528c2de47e959ad073ac1c8f1ab64d4b0e432d264a5caf74ddb656c1a0ffbd8923faf6f
2 parents 4071548 + 4ac68c9 commit 104eb55

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/miniscript/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
//!
2626
2727
use std::marker::PhantomData;
28-
use std::{fmt, str};
28+
use std::{fmt, hash, str};
2929

3030
use bitcoin::blockdata::script;
3131
use bitcoin::util::taproot::{LeafVersion, TapLeafHash};
@@ -57,7 +57,7 @@ use crate::{expression, Error, ForEach, ForEachKey, MiniscriptKey, ToPublicKey,
5757
mod ms_tests;
5858

5959
/// Top-level script AST type
60-
#[derive(Clone, Hash)]
60+
#[derive(Clone)]
6161
pub struct Miniscript<Pk: MiniscriptKey, Ctx: ScriptContext> {
6262
///A node in the Abstract Syntax Tree(
6363
pub node: Terminal<Pk, Ctx>,
@@ -107,6 +107,12 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> fmt::Debug for Miniscript<Pk, Ctx> {
107107
}
108108
}
109109

110+
impl<Pk: MiniscriptKey, Ctx: ScriptContext> hash::Hash for Miniscript<Pk, Ctx> {
111+
fn hash<H: hash::Hasher>(&self, state: &mut H) {
112+
self.node.hash(state);
113+
}
114+
}
115+
110116
impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
111117
/// Add type information(Type and Extdata) to Miniscript based on
112118
/// `AstElem` fragment. Dependent on display and clone because of Error

0 commit comments

Comments
 (0)