refactor: use tuple struct for descriptorpublickey type
This commit is contained in:
parent
4cd6a80ce0
commit
df64a96dd2
@ -37,7 +37,7 @@ impl Descriptor {
|
|||||||
keychain_kind: KeychainKind,
|
keychain_kind: KeychainKind,
|
||||||
network: Network,
|
network: Network,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let derivable_key = &secret_key.inner;
|
let derivable_key = &secret_key.0;
|
||||||
|
|
||||||
match derivable_key {
|
match derivable_key {
|
||||||
BdkDescriptorSecretKey::Single(_) => {
|
BdkDescriptorSecretKey::Single(_) => {
|
||||||
@ -65,7 +65,7 @@ impl Descriptor {
|
|||||||
network: Network,
|
network: Network,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap();
|
let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap();
|
||||||
let derivable_key = &public_key.inner;
|
let derivable_key = &public_key.0;
|
||||||
|
|
||||||
match derivable_key {
|
match derivable_key {
|
||||||
BdkDescriptorPublicKey::Single(_) => {
|
BdkDescriptorPublicKey::Single(_) => {
|
||||||
@ -94,7 +94,7 @@ impl Descriptor {
|
|||||||
keychain_kind: KeychainKind,
|
keychain_kind: KeychainKind,
|
||||||
network: Network,
|
network: Network,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let derivable_key = &secret_key.inner;
|
let derivable_key = &secret_key.0;
|
||||||
|
|
||||||
match derivable_key {
|
match derivable_key {
|
||||||
BdkDescriptorSecretKey::Single(_) => {
|
BdkDescriptorSecretKey::Single(_) => {
|
||||||
@ -122,7 +122,7 @@ impl Descriptor {
|
|||||||
network: Network,
|
network: Network,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap();
|
let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap();
|
||||||
let derivable_key = &public_key.inner;
|
let derivable_key = &public_key.0;
|
||||||
|
|
||||||
match derivable_key {
|
match derivable_key {
|
||||||
BdkDescriptorPublicKey::Single(_) => {
|
BdkDescriptorPublicKey::Single(_) => {
|
||||||
@ -151,7 +151,7 @@ impl Descriptor {
|
|||||||
keychain_kind: KeychainKind,
|
keychain_kind: KeychainKind,
|
||||||
network: Network,
|
network: Network,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let derivable_key = &secret_key.inner;
|
let derivable_key = &secret_key.0;
|
||||||
|
|
||||||
match derivable_key {
|
match derivable_key {
|
||||||
BdkDescriptorSecretKey::Single(_) => {
|
BdkDescriptorSecretKey::Single(_) => {
|
||||||
@ -179,7 +179,7 @@ impl Descriptor {
|
|||||||
network: Network,
|
network: Network,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap();
|
let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap();
|
||||||
let derivable_key = &public_key.inner;
|
let derivable_key = &public_key.0;
|
||||||
|
|
||||||
match derivable_key {
|
match derivable_key {
|
||||||
BdkDescriptorPublicKey::Single(_) => {
|
BdkDescriptorPublicKey::Single(_) => {
|
||||||
@ -208,7 +208,7 @@ impl Descriptor {
|
|||||||
keychain_kind: KeychainKind,
|
keychain_kind: KeychainKind,
|
||||||
network: Network,
|
network: Network,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let derivable_key = &secret_key.inner;
|
let derivable_key = &secret_key.0;
|
||||||
|
|
||||||
match derivable_key {
|
match derivable_key {
|
||||||
BdkDescriptorSecretKey::Single(_) => {
|
BdkDescriptorSecretKey::Single(_) => {
|
||||||
@ -236,7 +236,7 @@ impl Descriptor {
|
|||||||
network: Network,
|
network: Network,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap();
|
let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap();
|
||||||
let derivable_key = &public_key.inner;
|
let derivable_key = &public_key.0;
|
||||||
|
|
||||||
match derivable_key {
|
match derivable_key {
|
||||||
BdkDescriptorPublicKey::Single(_) => {
|
BdkDescriptorPublicKey::Single(_) => {
|
||||||
|
@ -135,9 +135,7 @@ impl DescriptorSecretKey {
|
|||||||
pub(crate) fn as_public(&self) -> Arc<DescriptorPublicKey> {
|
pub(crate) fn as_public(&self) -> Arc<DescriptorPublicKey> {
|
||||||
let secp = Secp256k1::new();
|
let secp = Secp256k1::new();
|
||||||
let descriptor_public_key = self.0.to_public(&secp).unwrap();
|
let descriptor_public_key = self.0.to_public(&secp).unwrap();
|
||||||
Arc::new(DescriptorPublicKey {
|
Arc::new(DescriptorPublicKey(descriptor_public_key))
|
||||||
inner: descriptor_public_key,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn secret_bytes(&self) -> Vec<u8> {
|
pub(crate) fn secret_bytes(&self) -> Vec<u8> {
|
||||||
@ -163,22 +161,18 @@ impl DescriptorSecretKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DescriptorPublicKey {
|
pub struct DescriptorPublicKey(pub(crate) BdkDescriptorPublicKey);
|
||||||
pub(crate) inner: BdkDescriptorPublicKey,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DescriptorPublicKey {
|
impl DescriptorPublicKey {
|
||||||
pub(crate) fn from_string(public_key: String) -> Result<Self, DescriptorKeyError> {
|
pub(crate) fn from_string(public_key: String) -> Result<Self, DescriptorKeyError> {
|
||||||
let descriptor_public_key = BdkDescriptorPublicKey::from_str(public_key.as_str())
|
let descriptor_public_key = BdkDescriptorPublicKey::from_str(public_key.as_str())
|
||||||
.map_err(DescriptorKeyError::from)?;
|
.map_err(DescriptorKeyError::from)?;
|
||||||
Ok(Self {
|
Ok(Self(descriptor_public_key))
|
||||||
inner: descriptor_public_key,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn derive(&self, path: &DerivationPath) -> Result<Arc<Self>, DescriptorKeyError> {
|
pub(crate) fn derive(&self, path: &DerivationPath) -> Result<Arc<Self>, DescriptorKeyError> {
|
||||||
let secp = Secp256k1::new();
|
let secp = Secp256k1::new();
|
||||||
let descriptor_public_key = &self.inner;
|
let descriptor_public_key = &self.0;
|
||||||
let path = path.inner_mutex.lock().unwrap().deref().clone();
|
let path = path.inner_mutex.lock().unwrap().deref().clone();
|
||||||
|
|
||||||
match descriptor_public_key {
|
match descriptor_public_key {
|
||||||
@ -198,16 +192,14 @@ impl DescriptorPublicKey {
|
|||||||
derivation_path: BdkDerivationPath::default(),
|
derivation_path: BdkDerivationPath::default(),
|
||||||
wildcard: descriptor_x_key.wildcard,
|
wildcard: descriptor_x_key.wildcard,
|
||||||
});
|
});
|
||||||
Ok(Arc::new(Self {
|
Ok(Arc::new(Self(derived_descriptor_public_key)))
|
||||||
inner: derived_descriptor_public_key,
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
BdkDescriptorPublicKey::MultiXPub(_) => Err(DescriptorKeyError::InvalidKeyType),
|
BdkDescriptorPublicKey::MultiXPub(_) => Err(DescriptorKeyError::InvalidKeyType),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn extend(&self, path: &DerivationPath) -> Result<Arc<Self>, DescriptorKeyError> {
|
pub(crate) fn extend(&self, path: &DerivationPath) -> Result<Arc<Self>, Alpha3Error> {
|
||||||
let descriptor_public_key = &self.inner;
|
let descriptor_public_key = &self.0;
|
||||||
let path = path.inner_mutex.lock().unwrap().deref().clone();
|
let path = path.inner_mutex.lock().unwrap().deref().clone();
|
||||||
match descriptor_public_key {
|
match descriptor_public_key {
|
||||||
BdkDescriptorPublicKey::Single(_) => Err(DescriptorKeyError::InvalidKeyType),
|
BdkDescriptorPublicKey::Single(_) => Err(DescriptorKeyError::InvalidKeyType),
|
||||||
@ -219,16 +211,14 @@ impl DescriptorPublicKey {
|
|||||||
derivation_path: extended_path,
|
derivation_path: extended_path,
|
||||||
wildcard: descriptor_x_key.wildcard,
|
wildcard: descriptor_x_key.wildcard,
|
||||||
});
|
});
|
||||||
Ok(Arc::new(Self {
|
Ok(Arc::new(Self(extended_descriptor_public_key)))
|
||||||
inner: extended_descriptor_public_key,
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
BdkDescriptorPublicKey::MultiXPub(_) => Err(DescriptorKeyError::InvalidKeyType),
|
BdkDescriptorPublicKey::MultiXPub(_) => Err(DescriptorKeyError::InvalidKeyType),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn as_string(&self) -> String {
|
pub(crate) fn as_string(&self) -> String {
|
||||||
self.inner.to_string()
|
self.0.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user