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