Skip to content

Commit

Permalink
Derive comparison traits for all secret key types
Browse files Browse the repository at this point in the history
  • Loading branch information
quad committed Nov 3, 2022
1 parent fd9ef55 commit 8e781ca
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 8e781ca

Please sign in to comment.