Skip to content

Commit

Permalink
Implement hash::Hash for Miniscript
Browse files Browse the repository at this point in the history
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: rust-bitcoin#381
  • Loading branch information
tcharding authored and joemphilips committed Oct 31, 2022
1 parent 6135f66 commit 3100bd3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/miniscript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<Pk: MiniscriptKey, Ctx: ScriptContext> {
///A node in the Abstract Syntax Tree(
pub node: Terminal<Pk, Ctx>,
Expand Down Expand Up @@ -107,6 +107,12 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> fmt::Debug for Miniscript<Pk, Ctx> {
}
}

impl<Pk: MiniscriptKey, Ctx: ScriptContext> hash::Hash for Miniscript<Pk, Ctx> {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.node.hash(state);
}
}

impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
/// Add type information(Type and Extdata) to Miniscript based on
/// `AstElem` fragment. Dependent on display and clone because of Error
Expand Down

0 comments on commit 3100bd3

Please # to comment.