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 comparison traits for all secret key types #485

Merged
merged 1 commit into from
Dec 13, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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