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 Dec 16, 2022
1 parent c68f6e3 commit 5db18c5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/expression.rs
Expand Up @@ -39,6 +39,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 @@ -57,7 +57,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 @@ -452,7 +452,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 @@ -467,7 +467,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 @@ -96,7 +96,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 @@ -25,7 +25,7 @@ use super::Error;
use crate::prelude::*;

/// 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 5db18c5

Please sign in to comment.