From ef7fef001cd4e5234343b4574e0d9dee31961c3c Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 6 May 2022 13:37:24 +1000 Subject: [PATCH] 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. --- src/blockdata/transaction.rs | 2 +- src/util/ecdsa.rs | 2 +- src/util/psbt/map/input.rs | 2 +- src/util/psbt/map/output.rs | 8 +++++++- src/util/psbt/mod.rs | 2 +- src/util/schnorr.rs | 2 +- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index c92b73c3b1..c8241f5e56 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -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, diff --git a/src/util/ecdsa.rs b/src/util/ecdsa.rs index 8c4282d14f..4d85c37c67 100644 --- a/src/util/ecdsa.rs +++ b/src/util/ecdsa.rs @@ -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 { diff --git a/src/util/psbt/map/input.rs b/src/util/psbt/map/input.rs index a6277066b9..754df14bcd 100644 --- a/src/util/psbt/map/input.rs +++ b/src/util/psbt/map/input.rs @@ -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 { diff --git a/src/util/psbt/map/output.rs b/src/util/psbt/map/output.rs index 71dcf939c4..74d27d5ac2 100644 --- a/src/util/psbt/map/output.rs +++ b/src/util/psbt/map/output.rs @@ -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 { @@ -123,6 +123,12 @@ impl PartialEq for TapTree { } } +impl core::hash::Hash for TapTree { + fn hash(&self, state: &mut H) { + self.node_info().hash(state) + } +} + impl Eq for TapTree {} impl From for TaprootBuilder { diff --git a/src/util/psbt/mod.rs b/src/util/psbt/mod.rs index 6b6469bd1c..d978e88492 100644 --- a/src/util/psbt/mod.rs +++ b/src/util/psbt/mod.rs @@ -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 { diff --git a/src/util/schnorr.rs b/src/util/schnorr.rs index 7c13cc26f5..0185938725 100644 --- a/src/util/schnorr.rs +++ b/src/util/schnorr.rs @@ -205,7 +205,7 @@ impl From 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 {