Derive Hash on a bunch of types

In preparation for being able to derive `Hash` on all types in
`miniscript`, derive `Hash` on all of the required types.
This commit is contained in:
Tobin C. Harding 2022-05-06 13:37:24 +10:00
parent 9cfa9bd9df
commit ef7fef001c
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 {