Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive Hash on a bunch of types #990

Merged
merged 1 commit into from Jul 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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