Skip to content

Commit cb7bd09

Browse files
committed
Derive std::hash::Hash for Descriptor et al
Bunch of other types that needed hash to be able to derive it.
1 parent 86a63d8 commit cb7bd09

File tree

6 files changed

+13
-11
lines changed

6 files changed

+13
-11
lines changed

src/descriptor/bare.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use super::{
3838

3939
/// Create a Bare Descriptor. That is descriptor that is
4040
/// not wrapped in sh or wsh. This covers the Pk descriptor
41-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
41+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
4242
pub struct Bare<Pk: MiniscriptKey> {
4343
/// underlying miniscript
4444
ms: Miniscript<Pk, BareCtx>,
@@ -203,7 +203,7 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Bare<P> {
203203
}
204204

205205
/// A bare PkH descriptor at top level
206-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
206+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
207207
pub struct Pkh<Pk: MiniscriptKey> {
208208
/// underlying publickey
209209
pk: Pk,

src/descriptor/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub trait DescriptorTrait<Pk: MiniscriptKey> {
154154
}
155155

156156
/// Script descriptor
157-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
157+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
158158
pub enum Descriptor<Pk: MiniscriptKey> {
159159
/// A raw scriptpubkey (including pay-to-pubkey) under Legacy context
160160
Bare(Bare<Pk>),

src/descriptor/segwitv0.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use super::{
3434
DescriptorTrait, SortedMultiVec,
3535
};
3636
/// A Segwitv0 wsh descriptor
37-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
37+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
3838
pub struct Wsh<Pk: MiniscriptKey> {
3939
/// underlying miniscript
4040
inner: WshInner<Pk>,
@@ -79,7 +79,7 @@ impl<Pk: MiniscriptKey> Wsh<Pk> {
7979
}
8080

8181
/// Wsh Inner
82-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
82+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
8383
pub enum WshInner<Pk: MiniscriptKey> {
8484
/// Sorted Multi
8585
SortedMulti(SortedMultiVec<Pk, Segwitv0>),
@@ -282,7 +282,7 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Wsh<P> {
282282
}
283283

284284
/// A bare Wpkh descriptor at top level
285-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
285+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
286286
pub struct Wpkh<Pk: MiniscriptKey> {
287287
/// underlying publickey
288288
pk: Pk,

src/descriptor/sh.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ use super::{
3838
};
3939

4040
/// A Legacy p2sh Descriptor
41-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
41+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
4242
pub struct Sh<Pk: MiniscriptKey> {
4343
/// underlying miniscript
4444
inner: ShInner<Pk>,
4545
}
4646

4747
/// Sh Inner
48-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
48+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
4949
pub enum ShInner<Pk: MiniscriptKey> {
5050
/// Nested Wsh
5151
Wsh(Wsh<Pk>),

src/descriptor/sortedmulti.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use script_num_size;
2727
use {errstr, Error, ForEach, ForEachKey, Miniscript, MiniscriptKey, Satisfier, ToPublicKey};
2828

2929
/// Contents of a "sortedmulti" descriptor
30-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
30+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
3131
pub struct SortedMultiVec<Pk: MiniscriptKey, Ctx: ScriptContext> {
3232
/// signatures required
3333
pub k: usize,

src/miniscript/context.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@
1212
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
1313
//
1414

15+
use std::{fmt, hash};
16+
1517
use miniscript::limits::{
1618
MAX_OPS_PER_SCRIPT, MAX_SCRIPTSIG_SIZE, MAX_SCRIPT_ELEMENT_SIZE, MAX_SCRIPT_SIZE,
1719
MAX_STANDARD_P2WSH_SCRIPT_SIZE, MAX_STANDARD_P2WSH_STACK_ITEMS,
1820
};
1921
use miniscript::types;
20-
use std::fmt;
2122
use util::witness_to_scriptsig;
2223
use Error;
2324
use {Miniscript, MiniscriptKey, Terminal};
25+
2426
/// Error for Script Context
2527
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
2628
pub enum ScriptContextError {
@@ -106,7 +108,7 @@ impl fmt::Display for ScriptContextError {
106108
/// context under which the script is used.
107109
/// For example, disallowing uncompressed keys in Segwit context
108110
pub trait ScriptContext:
109-
fmt::Debug + Clone + Ord + PartialOrd + Eq + PartialEq + private::Sealed
111+
fmt::Debug + Clone + Ord + PartialOrd + Eq + PartialEq + hash::Hash + private::Sealed
110112
{
111113
/// Depending on ScriptContext, fragments can be malleable. For Example,
112114
/// under Legacy context, PkH is malleable because it is possible to

0 commit comments

Comments
 (0)