Skip to content

Commit

Permalink
Derive Hash for enums
Browse files Browse the repository at this point in the history
Audit the whole crate and for any enum that can derive `Hash`. Exclude
error enums.

Derive `Hash` on any non-error enums that can.
  • Loading branch information
tcharding committed May 6, 2022
1 parent ab313b5 commit 23e5946
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/descriptor/key.rs
Expand Up @@ -22,7 +22,7 @@ pub enum DescriptorPublicKey {
}

/// The descriptor secret key, either a single private key or an xprv.
#[derive(Debug)]
#[derive(Debug, Hash)]
pub enum DescriptorSecretKey {
/// Single private key.
Single(SinglePriv),
Expand Down
1 change: 1 addition & 0 deletions src/expression.rs
Expand Up @@ -37,6 +37,7 @@ pub trait FromTree: Sized {
fn from_tree(top: &Tree) -> Result<Self, Error>;
}

#[derive(Hash)]
enum Found {
Nothing,
LBracket(usize), // Either a left ( or {
Expand Down
6 changes: 3 additions & 3 deletions src/interpreter/mod.rs
Expand Up @@ -59,7 +59,7 @@ pub struct Interpreter<'txin> {
// Ecdsa and Schnorr signatures

/// A type for representing signatures supported as of bitcoin core 22.0
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum KeySigPair {
/// A Full public key and corresponding Ecdsa signature
Ecdsa(bitcoin::PublicKey, bitcoin::EcdsaSig),
Expand Down Expand Up @@ -451,7 +451,7 @@ impl<'txin> Interpreter<'txin> {
}

/// Type of HashLock used for SatisfiedConstraint structure
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum HashLockType {
///SHA 256 hashlock
Sha256(sha256::Hash),
Expand All @@ -466,7 +466,7 @@ pub enum HashLockType {
/// A satisfied Miniscript condition (Signature, Hashlock, Timelock)
/// 'intp represents the lifetime of descriptor and `stack represents
/// the lifetime of witness
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum SatisfiedConstraint {
///Public key and corresponding signature
PublicKey {
Expand Down
2 changes: 1 addition & 1 deletion src/miniscript/decode.rs
Expand Up @@ -95,7 +95,7 @@ mod private {
impl Sealed for super::bitcoin::secp256k1::XOnlyPublicKey {}
}

#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, Hash)]
enum NonTerm {
Expression,
WExpression,
Expand Down
2 changes: 1 addition & 1 deletion src/miniscript/lex.rs
Expand Up @@ -24,7 +24,7 @@ use std::fmt;
use super::Error;

/// Atom of a tokenized version of a script
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[allow(missing_docs)]
pub enum Token<'s> {
BoolAnd,
Expand Down

0 comments on commit 23e5946

Please sign in to comment.