Skip to content

Commit

Permalink
Merge rust-bitcoin/rust-bitcoin#990: Derive Hash on a bunch of types
Browse files Browse the repository at this point in the history
ef7fef0 Derive Hash on a bunch of types (Tobin C. Harding)

Pull request description:

  In preparation for being able to derive `Hash` on all types in `miniscript`, derive `Hash` on all of the required types.

  This PR includes all the changes in https://github.com/rust-bitcoin/rust-bitcoin/pull/933/files and hence supersedes it.

  ref: rust-bitcoin/rust-miniscript#226

ACKs for top commit:
  Kixunil:
    ACK ef7fef0
  apoelstra:
    ACK ef7fef0

Tree-SHA512: 1a1db8b4df2ea8f9e176434bb6fdee5b96f47dcdc6395ebc59e5f5ac5eb13a66fb61e1d90cdbbf12a027f7685fdff21060338c5f27b9d9bf5e9fee452c7c7e83
  • Loading branch information
apoelstra committed Jul 17, 2022
2 parents 3945004 + aa2041c commit b44620b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/blockdata/transaction.rs
Expand Up @@ -852,7 +852,7 @@ pub type SigHashType = EcdsaSighashType;
///
/// Fixed values so they can be cast as integer types for encoding (see also
/// [`SchnorrSighashType`]).
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
#[derive(PartialEq, Eq, Debug, Copy, Clone, Hash)]
pub enum EcdsaSighashType {
/// 0x1: Sign all outputs.
All = 0x01,
Expand Down
2 changes: 1 addition & 1 deletion src/util/ecdsa.rs
Expand Up @@ -14,7 +14,7 @@ use secp256k1;
use crate::EcdsaSighashType;

/// An ECDSA signature with the corresponding hash type.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct EcdsaSig {
Expand Down
2 changes: 1 addition & 1 deletion src/util/psbt/map/input.rs
Expand Up @@ -68,7 +68,7 @@ const PSBT_IN_PROPRIETARY: u8 = 0xFC;

/// A key-value map for an input of the corresponding index in the unsigned
/// transaction.
#[derive(Clone, Default, Debug, PartialEq, Eq)]
#[derive(Clone, Default, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct Input {
Expand Down
8 changes: 7 additions & 1 deletion src/util/psbt/map/output.rs
Expand Up @@ -36,7 +36,7 @@ const PSBT_OUT_PROPRIETARY: u8 = 0xFC;

/// A key-value map for an output of the corresponding index in the unsigned
/// transaction.
#[derive(Clone, Default, Debug, PartialEq, Eq)]
#[derive(Clone, Default, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct Output {
Expand Down Expand Up @@ -123,6 +123,12 @@ impl PartialEq for TapTree {
}
}

impl core::hash::Hash for TapTree {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.node_info().hash(state)
}
}

impl Eq for TapTree {}

impl From<TapTree> for TaprootBuilder {
Expand Down
2 changes: 1 addition & 1 deletion src/util/psbt/mod.rs
Expand Up @@ -37,7 +37,7 @@ use crate::util::bip32::{ExtendedPubKey, KeySource};
pub type Psbt = PartiallySignedTransaction;

/// A Partially Signed Transaction.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct PartiallySignedTransaction {
Expand Down
2 changes: 1 addition & 1 deletion src/util/schnorr.rs
Expand Up @@ -205,7 +205,7 @@ impl From<TweakedKeyPair> for crate::KeyPair {
}

/// A BIP340-341 serialized schnorr signature with the corresponding hash type.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct SchnorrSig {
Expand Down

0 comments on commit b44620b

Please sign in to comment.