From 4ac68c9b24745e5ec28ef865ed0e9ea8af97b30c Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 11 May 2022 14:20:26 +1000 Subject: [PATCH] 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 --- src/miniscript/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/miniscript/mod.rs b/src/miniscript/mod.rs index d72a51d9a..4d580c94b 100644 --- a/src/miniscript/mod.rs +++ b/src/miniscript/mod.rs @@ -25,7 +25,7 @@ //! use std::marker::PhantomData; -use std::{fmt, str}; +use std::{fmt, hash, str}; use bitcoin::blockdata::script; use bitcoin::util::taproot::{LeafVersion, TapLeafHash}; @@ -57,7 +57,7 @@ use crate::{expression, Error, ForEach, ForEachKey, MiniscriptKey, ToPublicKey, mod ms_tests; /// Top-level script AST type -#[derive(Clone, Hash)] +#[derive(Clone)] pub struct Miniscript { ///A node in the Abstract Syntax Tree( pub node: Terminal, @@ -107,6 +107,12 @@ impl fmt::Debug for Miniscript { } } +impl hash::Hash for Miniscript { + fn hash(&self, state: &mut H) { + self.node.hash(state); + } +} + impl Miniscript { /// Add type information(Type and Extdata) to Miniscript based on /// `AstElem` fragment. Dependent on display and clone because of Error