Skip to content

Commit f6e42a1

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 95811b2 commit f6e42a1

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

src/descriptor/bare.rs

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

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

187187
/// A bare PkH descriptor at top level
188-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
188+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
189189
pub struct Pkh<Pk: MiniscriptKey> {
190190
/// underlying publickey
191191
pk: Pk,

src/descriptor/mod.rs

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

151151
/// Script descriptor
152-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
152+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
153153
pub enum Descriptor<Pk: MiniscriptKey> {
154154
/// A raw scriptpubkey (including pay-to-pubkey) under Legacy context
155155
Bare(Bare<Pk>),

src/descriptor/segwitv0.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use super::{
3131
DescriptorTrait, SortedMultiVec,
3232
};
3333
/// A Segwitv0 wsh descriptor
34-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
34+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
3535
pub struct Wsh<Pk: MiniscriptKey> {
3636
/// underlying miniscript
3737
inner: WshInner<Pk>,
@@ -63,7 +63,7 @@ impl<Pk: MiniscriptKey> Wsh<Pk> {
6363
}
6464

6565
/// Wsh Inner
66-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
66+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
6767
pub enum WshInner<Pk: MiniscriptKey> {
6868
/// Sorted Multi
6969
SortedMulti(SortedMultiVec<Pk, Segwitv0>),
@@ -258,7 +258,7 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Wsh<P> {
258258
}
259259

260260
/// A bare Wpkh descriptor at top level
261-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
261+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
262262
pub struct Wpkh<Pk: MiniscriptKey> {
263263
/// underlying publickey
264264
pk: Pk,

src/descriptor/sh.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ use super::{
3535
};
3636

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

4444
/// Sh Inner
45-
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
45+
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
4646
enum ShInner<Pk: MiniscriptKey> {
4747
/// Nested Wsh
4848
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, 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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl fmt::Display for ScriptContextError {
9898
/// context under which the script is used.
9999
/// For example, disallowing uncompressed keys in Segwit context
100100
pub trait ScriptContext:
101-
fmt::Debug + Clone + Ord + PartialOrd + Eq + PartialEq + private::Sealed
101+
fmt::Debug + Clone + Ord + PartialOrd + Eq + PartialEq + std::hash::Hash + private::Sealed
102102
{
103103
/// Depending on ScriptContext, fragments can be malleable. For Example,
104104
/// under Legacy context, PkH is malleable because it is possible to
@@ -239,7 +239,7 @@ pub trait ScriptContext:
239239
/// To be used as P2SH scripts
240240
/// For creation of Bare scriptpubkeys, construct the Miniscript
241241
/// under `Bare` ScriptContext
242-
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
242+
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
243243
pub enum Legacy {}
244244

245245
impl ScriptContext for Legacy {
@@ -310,7 +310,7 @@ impl ScriptContext for Legacy {
310310
}
311311

312312
/// Segwitv0 ScriptContext
313-
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
313+
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
314314
pub enum Segwitv0 {}
315315

316316
impl ScriptContext for Segwitv0 {
@@ -395,7 +395,7 @@ impl ScriptContext for Segwitv0 {
395395
/// To be used as raw script pubkeys
396396
/// In general, it is not recommended to use Bare descriptors
397397
/// as they as strongly limited by standardness policies.
398-
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
398+
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
399399
pub enum BareCtx {}
400400

401401
impl ScriptContext for BareCtx {
@@ -457,7 +457,7 @@ impl ScriptContext for BareCtx {
457457
/// Used by the "satisified constraints" iterator, which is intended to read
458458
/// scripts off of the blockchain without doing any sanity checks on them.
459459
/// This context should not be used unless you know what you are doing.
460-
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
460+
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
461461
pub enum NoChecks {}
462462
impl ScriptContext for NoChecks {
463463
fn check_terminal_non_malleable<Pk: MiniscriptKey, Ctx: ScriptContext>(

0 commit comments

Comments
 (0)