Merge rust-bitcoin/rust-bitcoin#990: Derive Hash on a bunch of types

ef7fef001c 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: https://github.com/rust-bitcoin/rust-miniscript/issues/226

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

Tree-SHA512: 1a1db8b4df2ea8f9e176434bb6fdee5b96f47dcdc6395ebc59e5f5ac5eb13a66fb61e1d90cdbbf12a027f7685fdff21060338c5f27b9d9bf5e9fee452c7c7e83
This commit is contained in:
Andrew Poelstra 2022-07-17 22:55:30 +00:00
commit 06a777d02d
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
6 changed files with 12 additions and 6 deletions

View File

@ -852,7 +852,7 @@ pub type SigHashType = EcdsaSighashType;
/// ///
/// Fixed values so they can be cast as integer types for encoding (see also /// Fixed values so they can be cast as integer types for encoding (see also
/// [`SchnorrSighashType`]). /// [`SchnorrSighashType`]).
#[derive(PartialEq, Eq, Debug, Copy, Clone)] #[derive(PartialEq, Eq, Debug, Copy, Clone, Hash)]
pub enum EcdsaSighashType { pub enum EcdsaSighashType {
/// 0x1: Sign all outputs. /// 0x1: Sign all outputs.
All = 0x01, All = 0x01,

View File

@ -14,7 +14,7 @@ use secp256k1;
use crate::EcdsaSighashType; use crate::EcdsaSighashType;
/// An ECDSA signature with the corresponding hash type. /// 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", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] #[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct EcdsaSig { pub struct EcdsaSig {

View File

@ -68,7 +68,7 @@ const PSBT_IN_PROPRIETARY: u8 = 0xFC;
/// A key-value map for an input of the corresponding index in the unsigned /// A key-value map for an input of the corresponding index in the unsigned
/// transaction. /// 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", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] #[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct Input { pub struct Input {

View File

@ -36,7 +36,7 @@ const PSBT_OUT_PROPRIETARY: u8 = 0xFC;
/// A key-value map for an output of the corresponding index in the unsigned /// A key-value map for an output of the corresponding index in the unsigned
/// transaction. /// 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", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] #[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct Output { pub struct Output {
@ -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 Eq for TapTree {}
impl From<TapTree> for TaprootBuilder { impl From<TapTree> for TaprootBuilder {

View File

@ -37,7 +37,7 @@ use crate::util::bip32::{ExtendedPubKey, KeySource};
pub type Psbt = PartiallySignedTransaction; pub type Psbt = PartiallySignedTransaction;
/// A Partially Signed Transaction. /// 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", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] #[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct PartiallySignedTransaction { pub struct PartiallySignedTransaction {

View File

@ -205,7 +205,7 @@ impl From<TweakedKeyPair> for crate::KeyPair {
} }
/// A BIP340-341 serialized schnorr signature with the corresponding hash type. /// 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", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] #[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct SchnorrSig { pub struct SchnorrSig {