Skip to content

Commit

Permalink
Derive Hash for all structs that can
Browse files Browse the repository at this point in the history
Audit the whole crate and for any struct that can, derive `Hash`.
  • Loading branch information
tcharding committed Dec 16, 2022
1 parent 0daded4 commit c68f6e3
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use core::str::FromStr;
use crate::prelude::*;
use crate::{errstr, Error, MAX_RECURSION_DEPTH};

#[derive(Debug)]
#[derive(Debug, Hash)]
/// A token of the form `x(...)` or `x`
pub struct Tree<'a> {
/// The name `x`
Expand Down
6 changes: 3 additions & 3 deletions src/interpreter/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn script_from_stack_elem<Ctx: ScriptContext>(
}

/// Helper type to indicate the origin of the bare pubkey that the interpereter uses
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
pub enum PubkeyType {
Pk,
Pkh,
Expand All @@ -79,7 +79,7 @@ pub enum PubkeyType {
}

/// Helper type to indicate the origin of the bare miniscript that the interpereter uses
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
pub enum ScriptType {
Bare,
Sh,
Expand All @@ -89,7 +89,7 @@ pub enum ScriptType {
}

/// Structure representing a script under evaluation as a Miniscript
#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub(super) enum Inner {
/// The script being evaluated is a simple public key check (pay-to-pk,
/// pay-to-pkhash or pay-to-witness-pkhash)
Expand Down
2 changes: 2 additions & 0 deletions src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use self::stack::Stack;
use crate::MiniscriptKey;

/// An iterable Miniscript-structured representation of the spending of a coin
#[derive(Hash)]
pub struct Interpreter<'txin> {
inner: inner::Inner,
stack: Stack<'txin>,
Expand Down Expand Up @@ -505,6 +506,7 @@ pub enum SatisfiedConstraint {
///the top of the stack, we need to decide whether to execute right child or not.
///This is also useful for wrappers and thresholds which push a value on the stack
///depending on evaluation of the children.
#[derive(Hash)]
struct NodeEvaluationState<'intp> {
///The node which is being evaluated
node: &'intp Miniscript<BitcoinKey, NoChecks>,
Expand Down
4 changes: 2 additions & 2 deletions src/miniscript/satisfy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ impl_tuple_satisfier!(A, B, C, D, E, F, G);
impl_tuple_satisfier!(A, B, C, D, E, F, G, H);

/// A witness, if available, for a Miniscript fragment
#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub enum Witness {
/// Witness Available and the value of the witness
Stack(Vec<Vec<u8>>),
Expand Down Expand Up @@ -699,7 +699,7 @@ impl Witness {
}

/// A (dis)satisfaction of a Miniscript fragment
#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub struct Satisfaction {
/// The actual witness stack
pub stack: Witness,
Expand Down
4 changes: 2 additions & 2 deletions src/policy/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl hash::Hash for OrdF64 {

/// Compilation key: This represents the state of the best possible compilation
/// of a given policy(implicitly keyed).
#[derive(Copy, Clone, PartialEq, Eq, Debug, PartialOrd, Ord)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, PartialOrd, Ord, Hash)]
struct CompilationKey {
/// The type of the compilation result
ty: Type,
Expand Down Expand Up @@ -547,7 +547,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> AstElemExt<Pk, Ctx> {
}

/// Different types of casts possible for each node.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Hash)]
struct Cast<Pk: MiniscriptKey, Ctx: ScriptContext> {
node: fn(Arc<Miniscript<Pk, Ctx>>) -> Terminal<Pk, Ctx>,
ast_type: fn(types::Type) -> Result<types::Type, ErrorKind>,
Expand Down
1 change: 1 addition & 0 deletions src/psbt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ impl From<bitcoin::util::key::Error> for InputError {
/// the same psbt structure
/// All operations on this structure will panic if index
/// is more than number of inputs in pbst
#[derive(Hash)]
pub struct PsbtInputSatisfier<'psbt> {
/// pbst
pub psbt: &'psbt Psbt,
Expand Down

0 comments on commit c68f6e3

Please sign in to comment.