Skip to content

Commit f5f22d5

Browse files
committed
Merge #485: Derive comparison traits for all secret key types
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
2 parents a7bfff4 + 8e781ca commit f5f22d5

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)