Skip to content

Commit

Permalink
Merge #402: Implement hash::Hash for Miniscript
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sanket1729 committed May 15, 2022
2 parents 4071548 + 4ac68c9 commit 104eb55
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 104eb55

Please # to comment.