diff --git a/bdk-ffi/src/descriptor.rs b/bdk-ffi/src/descriptor.rs index e33df686..60f81787 100644 --- a/bdk-ffi/src/descriptor.rs +++ b/bdk-ffi/src/descriptor.rs @@ -35,7 +35,7 @@ impl Descriptor { keychain_kind: KeychainKind, network: Network, ) -> Self { - let derivable_key = secret_key.descriptor_secret_key_mutex.lock().unwrap(); + let derivable_key = secret_key.descriptor_secret_key.lock().unwrap(); match derivable_key.deref() { BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { @@ -60,7 +60,7 @@ impl Descriptor { network: Network, ) -> Self { let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap(); - let derivable_key = public_key.descriptor_public_key_mutex.lock().unwrap(); + let derivable_key = public_key.descriptor_public_key.lock().unwrap(); match derivable_key.deref() { BdkDescriptorPublicKey::XPub(descriptor_x_key) => { @@ -86,7 +86,7 @@ impl Descriptor { keychain_kind: KeychainKind, network: Network, ) -> Self { - let derivable_key = secret_key.descriptor_secret_key_mutex.lock().unwrap(); + let derivable_key = secret_key.descriptor_secret_key.lock().unwrap(); match derivable_key.deref() { BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { @@ -111,7 +111,7 @@ impl Descriptor { network: Network, ) -> Self { let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap(); - let derivable_key = public_key.descriptor_public_key_mutex.lock().unwrap(); + let derivable_key = public_key.descriptor_public_key.lock().unwrap(); match derivable_key.deref() { BdkDescriptorPublicKey::XPub(descriptor_x_key) => { @@ -137,7 +137,7 @@ impl Descriptor { keychain_kind: KeychainKind, network: Network, ) -> Self { - let derivable_key = secret_key.descriptor_secret_key_mutex.lock().unwrap(); + let derivable_key = secret_key.descriptor_secret_key.lock().unwrap(); match derivable_key.deref() { BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { @@ -162,7 +162,7 @@ impl Descriptor { network: Network, ) -> Self { let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap(); - let derivable_key = public_key.descriptor_public_key_mutex.lock().unwrap(); + let derivable_key = public_key.descriptor_public_key.lock().unwrap(); match derivable_key.deref() { BdkDescriptorPublicKey::XPub(descriptor_x_key) => { diff --git a/bdk-ffi/src/keys.rs b/bdk-ffi/src/keys.rs index 0d7513d7..43668544 100644 --- a/bdk-ffi/src/keys.rs +++ b/bdk-ffi/src/keys.rs @@ -66,7 +66,7 @@ impl DerivationPath { #[derive(Debug)] pub(crate) struct DescriptorSecretKey { - pub(crate) descriptor_secret_key_mutex: Mutex, + pub(crate) descriptor_secret_key: BdkDescriptorSecretKey, } impl DescriptorSecretKey { @@ -80,7 +80,7 @@ impl DescriptorSecretKey { wildcard: bdk::descriptor::Wildcard::Unhardened, }); Self { - descriptor_secret_key_mutex: Mutex::new(descriptor_secret_key), + descriptor_secret_key, } } @@ -88,13 +88,13 @@ impl DescriptorSecretKey { let descriptor_secret_key = BdkDescriptorSecretKey::from_str(private_key.as_str()) .map_err(|e| BdkError::Generic(e.to_string()))?; Ok(Self { - descriptor_secret_key_mutex: Mutex::new(descriptor_secret_key), + descriptor_secret_key, }) } pub(crate) fn derive(&self, path: Arc) -> Result, BdkError> { let secp = Secp256k1::new(); - let descriptor_secret_key = self.descriptor_secret_key_mutex.lock().unwrap(); + let descriptor_secret_key = self.descriptor_secret_key.lock().unwrap(); let path = path.derivation_path_mutex.lock().unwrap().deref().clone(); match descriptor_secret_key.deref() { BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { @@ -110,7 +110,7 @@ impl DescriptorSecretKey { wildcard: descriptor_x_key.wildcard, }); Ok(Arc::new(Self { - descriptor_secret_key_mutex: Mutex::new(derived_descriptor_secret_key), + descriptor_secret_key: derived_descriptor_secret_key, })) } BdkDescriptorSecretKey::Single(_) => Err(BdkError::Generic( @@ -120,7 +120,7 @@ impl DescriptorSecretKey { } pub(crate) fn extend(&self, path: Arc) -> Result, BdkError> { - let descriptor_secret_key = self.descriptor_secret_key_mutex.lock().unwrap(); + let descriptor_secret_key = self.descriptor_secret_key.lock().unwrap(); let path = path.derivation_path_mutex.lock().unwrap().deref().clone(); match descriptor_secret_key.deref() { BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { @@ -132,7 +132,7 @@ impl DescriptorSecretKey { wildcard: descriptor_x_key.wildcard, }); Ok(Arc::new(Self { - descriptor_secret_key_mutex: Mutex::new(extended_descriptor_secret_key), + descriptor_secret_key: extended_descriptor_secret_key, })) } BdkDescriptorSecretKey::Single(_) => Err(BdkError::Generic( @@ -144,19 +144,19 @@ impl DescriptorSecretKey { pub(crate) fn as_public(&self) -> Arc { let secp = Secp256k1::new(); let descriptor_public_key = self - .descriptor_secret_key_mutex + .descriptor_secret_key .lock() .unwrap() .to_public(&secp) .unwrap(); Arc::new(DescriptorPublicKey { - descriptor_public_key_mutex: Mutex::new(descriptor_public_key), + descriptor_public_key, }) } /// Get the private key as bytes. pub(crate) fn secret_bytes(&self) -> Vec { - let descriptor_secret_key = self.descriptor_secret_key_mutex.lock().unwrap(); + let descriptor_secret_key = self.descriptor_secret_key.lock().unwrap(); let secret_bytes: Vec = match descriptor_secret_key.deref() { BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { descriptor_x_key.xkey.private_key.secret_bytes().to_vec() @@ -170,13 +170,13 @@ impl DescriptorSecretKey { } pub(crate) fn as_string(&self) -> String { - self.descriptor_secret_key_mutex.lock().unwrap().to_string() + self.descriptor_secret_key.lock().unwrap().to_string() } } #[derive(Debug)] pub(crate) struct DescriptorPublicKey { - pub(crate) descriptor_public_key_mutex: Mutex, + pub(crate) descriptor_public_key: BdkDescriptorPublicKey, } impl DescriptorPublicKey { @@ -184,13 +184,13 @@ impl DescriptorPublicKey { let descriptor_public_key = BdkDescriptorPublicKey::from_str(public_key.as_str()) .map_err(|e| BdkError::Generic(e.to_string()))?; Ok(Self { - descriptor_public_key_mutex: Mutex::new(descriptor_public_key), + descriptor_public_key, }) } pub(crate) fn derive(&self, path: Arc) -> Result, BdkError> { let secp = Secp256k1::new(); - let descriptor_public_key = self.descriptor_public_key_mutex.lock().unwrap(); + let descriptor_public_key = self.descriptor_public_key.lock().unwrap(); let path = path.derivation_path_mutex.lock().unwrap().deref().clone(); match descriptor_public_key.deref() { @@ -207,7 +207,7 @@ impl DescriptorPublicKey { wildcard: descriptor_x_key.wildcard, }); Ok(Arc::new(Self { - descriptor_public_key_mutex: Mutex::new(derived_descriptor_public_key), + descriptor_public_key: derived_descriptor_public_key, })) } BdkDescriptorPublicKey::Single(_) => Err(BdkError::Generic( @@ -217,7 +217,7 @@ impl DescriptorPublicKey { } pub(crate) fn extend(&self, path: Arc) -> Result, BdkError> { - let descriptor_public_key = self.descriptor_public_key_mutex.lock().unwrap(); + let descriptor_public_key = self.descriptor_public_key.lock().unwrap(); let path = path.derivation_path_mutex.lock().unwrap().deref().clone(); match descriptor_public_key.deref() { BdkDescriptorPublicKey::XPub(descriptor_x_key) => { @@ -229,7 +229,7 @@ impl DescriptorPublicKey { wildcard: descriptor_x_key.wildcard, }); Ok(Arc::new(Self { - descriptor_public_key_mutex: Mutex::new(extended_descriptor_public_key), + descriptor_public_key: extended_descriptor_public_key, })) } BdkDescriptorPublicKey::Single(_) => Err(BdkError::Generic( @@ -239,7 +239,7 @@ impl DescriptorPublicKey { } pub(crate) fn as_string(&self) -> String { - self.descriptor_public_key_mutex.lock().unwrap().to_string() + self.descriptor_public_key.lock().unwrap().to_string() } }