Skip to content

Commit 4ac68c9

Browse files
committed
Implement hash::Hash for Miniscript
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
1 parent 5c466a8 commit 4ac68c9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/miniscript/mod.rs

Lines changed: 8 additions & 2 deletions
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)