Skip to content

Commit b3027a9

Browse files
committed
Derives Hash for pub items
This commit dervies `Hash` for enums and structs which also dervies `Eq`.
1 parent f6ffc3e commit b3027a9

File tree

8 files changed

+16
-16
lines changed

8 files changed

+16
-16
lines changed

src/interpreter/inner.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn script_from_stack_elem<Ctx: ScriptContext>(
5252
}
5353

5454
/// Helper type to indicate the origin of the bare pubkey that the interpereter uses
55-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
55+
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
5656
pub enum PubkeyType {
5757
Pk,
5858
Pkh,
@@ -62,7 +62,7 @@ pub enum PubkeyType {
6262
}
6363

6464
/// Helper type to indicate the origin of the bare miniscript that the interpereter uses
65-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
65+
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
6666
pub enum ScriptType {
6767
Bare,
6868
Sh,
@@ -72,7 +72,7 @@ pub enum ScriptType {
7272
}
7373

7474
/// Structure representing a script under evaluation as a Miniscript
75-
#[derive(Clone, PartialEq, Eq, Debug)]
75+
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
7676
pub(super) enum Inner {
7777
/// The script being evaluated is a simple public key check (pay-to-pk,
7878
/// pay-to-pkhash or pay-to-witness-pkhash)

src/interpreter/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub struct Interpreter<'txin> {
4343
// Ecdsa and Schnorr signatures
4444

4545
/// A type for representing signatures supported as of bitcoin core 22.0
46-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
46+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4747
pub enum KeySigPair {
4848
/// A Full public key and corresponding Ecdsa signature
4949
Ecdsa(bitcoin::PublicKey, bitcoin::ecdsa::Signature),
@@ -429,7 +429,7 @@ impl<'txin> Interpreter<'txin> {
429429
}
430430

431431
/// Type of HashLock used for SatisfiedConstraint structure
432-
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
432+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
433433
pub enum HashLockType {
434434
///SHA 256 hashlock
435435
Sha256(sha256::Hash),
@@ -444,7 +444,7 @@ pub enum HashLockType {
444444
/// A satisfied Miniscript condition (Signature, Hashlock, Timelock)
445445
/// 'intp represents the lifetime of descriptor and `stack represents
446446
/// the lifetime of witness
447-
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
447+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
448448
pub enum SatisfiedConstraint {
449449
///Public key and corresponding signature
450450
PublicKey {

src/miniscript/analyzable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::{Miniscript, MiniscriptKey, ScriptContext, Terminal};
2424
/// guarantees are not satisfied.
2525
/// 4. It has repeated public keys
2626
/// 5. raw pkh fragments without the pk. This could be obtained when parsing miniscript from script
27-
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default)]
27+
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)]
2828
pub struct ExtParams {
2929
/// Allow parsing of non-safe miniscripts
3030
pub top_unsafe: bool,

src/miniscript/lex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use super::Error;
1313
use crate::prelude::*;
1414

1515
/// Atom of a tokenized version of a script
16-
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
16+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1717
#[allow(missing_docs)]
1818
pub enum Token<'s> {
1919
BoolAnd,

src/miniscript/satisfy.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ impl_tuple_satisfier!(A, B, C, D, E, F);
551551
impl_tuple_satisfier!(A, B, C, D, E, F, G);
552552
impl_tuple_satisfier!(A, B, C, D, E, F, G, H);
553553

554-
#[derive(Debug, Clone, PartialEq, Eq)]
554+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
555555
/// Type of schnorr signature to produce
556556
pub enum SchnorrSigType {
557557
/// Key spend signature
@@ -566,7 +566,7 @@ pub enum SchnorrSigType {
566566
},
567567
}
568568

569-
#[derive(Debug, Clone, PartialEq, Eq)]
569+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
570570
/// Placeholder for some data in a [`Plan`]
571571
///
572572
/// [`Plan`]: crate::plan::Plan
@@ -697,7 +697,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Placeholder<Pk> {
697697
}
698698

699699
/// A witness, if available, for a Miniscript fragment
700-
#[derive(Clone, PartialEq, Eq, Debug)]
700+
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
701701
pub enum Witness<T> {
702702
/// Witness Available and the value of the witness
703703
Stack(Vec<T>),
@@ -874,7 +874,7 @@ impl<Pk: MiniscriptKey> Witness<Placeholder<Pk>> {
874874
}
875875

876876
/// A (dis)satisfaction of a Miniscript fragment
877-
#[derive(Clone, PartialEq, Eq, Debug)]
877+
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
878878
pub struct Satisfaction<T> {
879879
/// The actual witness stack
880880
pub stack: Witness<T>,

src/policy/compiler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Ord for OrdF64 {
4040
}
4141

4242
/// Detailed error type for compiler.
43-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
43+
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
4444
pub enum CompilerError {
4545
/// Compiler has non-safe input policy.
4646
TopLevelNonSafe,
@@ -96,7 +96,7 @@ impl hash::Hash for OrdF64 {
9696

9797
/// Compilation key: This represents the state of the best possible compilation
9898
/// of a given policy(implicitly keyed).
99-
#[derive(Copy, Clone, PartialEq, Eq, Debug, PartialOrd, Ord)]
99+
#[derive(Copy, Clone, PartialEq, Eq, Debug, PartialOrd, Ord, Hash)]
100100
struct CompilationKey {
101101
/// The type of the compilation result
102102
ty: Type,

src/policy/concrete.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub enum Policy<Pk: MiniscriptKey> {
7373
}
7474

7575
/// Detailed error type for concrete policies.
76-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
76+
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
7777
pub enum PolicyError {
7878
/// `And` fragments only support two args.
7979
NonBinaryArgAnd,

src/policy/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub trait Liftable<Pk: MiniscriptKey> {
5252
}
5353

5454
/// Error occurring during lifting.
55-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
55+
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
5656
pub enum LiftError {
5757
/// Cannot lift policies that have a combination of height and timelocks.
5858
HeightTimelockCombination,

0 commit comments

Comments
 (0)