Skip to content

Commit 3bed0db

Browse files
committed
Re-order key structs
Source files are easier to read if the most important stuff comes first. We have a bunch of key structs, order them pub/priv and in order of importance i.e., declare things below where they are first used. Refactor only, no logic changes.
1 parent dcc9d0f commit 3bed0db

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

src/descriptor/key.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@ use bitcoin::{
1212

1313
use {MiniscriptKey, ToPublicKey};
1414

15-
/// Single public key without any origin or range information
16-
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash)]
17-
pub enum SinglePubKey {
18-
/// FullKey (compressed or uncompressed)
19-
FullKey(bitcoin::PublicKey),
20-
/// XOnlyPublicKey
21-
XOnly(XOnlyPublicKey),
22-
}
23-
2415
/// The MiniscriptKey corresponding to Descriptors. This can
2516
/// either be Single public key or a Xpub
2617
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash)]
@@ -31,6 +22,15 @@ pub enum DescriptorPublicKey {
3122
XPub(DescriptorXKey<bip32::ExtendedPubKey>),
3223
}
3324

25+
/// A Secret Key that can be either a single key or an Xprv
26+
#[derive(Debug)]
27+
pub enum DescriptorSecretKey {
28+
/// Single Secret Key
29+
SinglePriv(DescriptorSinglePriv),
30+
/// Xprv
31+
XPrv(DescriptorXKey<bip32::ExtendedPrivKey>),
32+
}
33+
3434
/// A Single Descriptor Key with optional origin information
3535
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash)]
3636
pub struct DescriptorSinglePub {
@@ -49,13 +49,26 @@ pub struct DescriptorSinglePriv {
4949
pub key: bitcoin::PrivateKey,
5050
}
5151

52-
/// A Secret Key that can be either a single key or an Xprv
53-
#[derive(Debug)]
54-
pub enum DescriptorSecretKey {
55-
/// Single Secret Key
56-
SinglePriv(DescriptorSinglePriv),
57-
/// Xprv
58-
XPrv(DescriptorXKey<bip32::ExtendedPrivKey>),
52+
/// Instance of an extended key with origin and derivation path
53+
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash)]
54+
pub struct DescriptorXKey<K: InnerXKey> {
55+
/// Origin information
56+
pub origin: Option<(bip32::Fingerprint, bip32::DerivationPath)>,
57+
/// The extended key
58+
pub xkey: K,
59+
/// The derivation path
60+
pub derivation_path: bip32::DerivationPath,
61+
/// Whether the descriptor is wildcard
62+
pub wildcard: Wildcard,
63+
}
64+
65+
/// Single public key without any origin or range information
66+
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash)]
67+
pub enum SinglePubKey {
68+
/// FullKey (compressed or uncompressed)
69+
FullKey(bitcoin::PublicKey),
70+
/// XOnlyPublicKey
71+
XOnly(XOnlyPublicKey),
5972
}
6073

6174
impl fmt::Display for DescriptorSecretKey {
@@ -124,19 +137,6 @@ pub enum Wildcard {
124137
Hardened,
125138
}
126139

127-
/// Instance of an extended key with origin and derivation path
128-
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash)]
129-
pub struct DescriptorXKey<K: InnerXKey> {
130-
/// Origin information
131-
pub origin: Option<(bip32::Fingerprint, bip32::DerivationPath)>,
132-
/// The extended key
133-
pub xkey: K,
134-
/// The derivation path
135-
pub derivation_path: bip32::DerivationPath,
136-
/// Whether the descriptor is wildcard
137-
pub wildcard: Wildcard,
138-
}
139-
140140
impl DescriptorSinglePriv {
141141
/// Returns the public key of this key
142142
fn as_public<C: Signing>(

0 commit comments

Comments
 (0)