Skip to content

Commit

Permalink
Merge #485: Derive comparison traits for all secret key types
Browse files Browse the repository at this point in the history
8e781ca Derive comparison traits for all secret key types (Scott Robinson)

Pull request description:

  The public key types (`DescriptorPublicKey`, `DescriptorXKey`, `SinglePubKey`, and `DefiniteDescriptorKey`) all have comparison derivations.

  The underlying private key types (`bitcoin::PrivateKey`, `Fingerprint`, `DerivationPath`, `DescriptorXKey`, and `ExtendedPrivKey`) all have comparison derivations.

  Let's catch 'em all.

ACKs for top commit:
  apoelstra:
    ACK 8e781ca
  sanket1729:
    ACK 8e781ca

Tree-SHA512: d4c11acf604ee1d0b752b137833ebeb8536b73724e491dee17babe30bfea65101f9f76d87e691e7ccf4e50f4491d7b15327c1abe33154081f456840bf3719768
  • Loading branch information
sanket1729 committed Dec 13, 2022
2 parents a7bfff4 + 8e781ca commit f5f22d5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/descriptor/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub enum DescriptorPublicKey {
}

/// The descriptor secret key, either a single private key or an xprv.
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq, Clone)]
pub enum DescriptorSecretKey {
/// Single private key.
Single(SinglePriv),
Expand All @@ -40,7 +40,7 @@ pub struct SinglePub {
}

/// A descriptor [`bitcoin::PrivateKey`] with optional origin information.
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq, Clone)]
pub struct SinglePriv {
/// Origin information (fingerprint and derivation path).
pub origin: Option<(bip32::Fingerprint, bip32::DerivationPath)>,
Expand Down
20 changes: 1 addition & 19 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,6 @@ serde_string_impl_pk!(Descriptor, "a script descriptor");

#[cfg(test)]
mod tests {
use core::cmp;
use core::str::FromStr;

use bitcoin::blockdata::opcodes::all::{OP_CLTV, OP_CSV};
Expand All @@ -850,7 +849,7 @@ mod tests {
use super::tr::Tr;
use super::*;
use crate::descriptor::key::Wildcard;
use crate::descriptor::{DescriptorPublicKey, DescriptorSecretKey, DescriptorXKey, SinglePub};
use crate::descriptor::{DescriptorPublicKey, DescriptorXKey, SinglePub};
#[cfg(feature = "compiler")]
use crate::policy;
use crate::{hex_script, Descriptor, DummyKey, Error, Miniscript, Satisfier};
Expand All @@ -859,23 +858,6 @@ mod tests {
const TEST_PK: &'static str =
"pk(020000000000000000000000000000000000000000000000000000000000000002)";

impl cmp::PartialEq for DescriptorSecretKey {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(&DescriptorSecretKey::Single(ref a), &DescriptorSecretKey::Single(ref b)) => {
a.origin == b.origin && a.key == b.key
}
(&DescriptorSecretKey::XPrv(ref a), &DescriptorSecretKey::XPrv(ref b)) => {
a.origin == b.origin
&& a.xkey == b.xkey
&& a.derivation_path == b.derivation_path
&& a.wildcard == b.wildcard
}
_ => false,
}
}
}

fn roundtrip_descriptor(s: &str) {
let desc = Descriptor::<DummyKey>::from_str(&s).unwrap();
let output = desc.to_string();
Expand Down

0 comments on commit f5f22d5

Please sign in to comment.