Skip to content

Commit 8e781ca

Browse files
author
Scott Robinson
committed
Derive comparison traits for all secret key types
1 parent fd9ef55 commit 8e781ca

File tree

2 files changed

+3
-21
lines changed

2 files changed

+3
-21
lines changed

src/descriptor/key.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub enum DescriptorPublicKey {
2222
}
2323

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

4242
/// A descriptor [`bitcoin::PrivateKey`] with optional origin information.
43-
#[derive(Debug)]
43+
#[derive(Debug, Eq, PartialEq, Clone)]
4444
pub struct SinglePriv {
4545
/// Origin information (fingerprint and derivation path).
4646
pub origin: Option<(bip32::Fingerprint, bip32::DerivationPath)>,

src/descriptor/mod.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,6 @@ serde_string_impl_pk!(Descriptor, "a script descriptor");
835835

836836
#[cfg(test)]
837837
mod tests {
838-
use core::cmp;
839838
use core::str::FromStr;
840839

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

862-
impl cmp::PartialEq for DescriptorSecretKey {
863-
fn eq(&self, other: &Self) -> bool {
864-
match (self, other) {
865-
(&DescriptorSecretKey::Single(ref a), &DescriptorSecretKey::Single(ref b)) => {
866-
a.origin == b.origin && a.key == b.key
867-
}
868-
(&DescriptorSecretKey::XPrv(ref a), &DescriptorSecretKey::XPrv(ref b)) => {
869-
a.origin == b.origin
870-
&& a.xkey == b.xkey
871-
&& a.derivation_path == b.derivation_path
872-
&& a.wildcard == b.wildcard
873-
}
874-
_ => false,
875-
}
876-
}
877-
}
878-
879861
fn roundtrip_descriptor(s: &str) {
880862
let desc = Descriptor::<DummyKey>::from_str(&s).unwrap();
881863
let output = desc.to_string();

0 commit comments

Comments
 (0)