diff --git a/bdk-ffi/src/descriptor.rs b/bdk-ffi/src/descriptor.rs index 3fac5dbb..ee2d4217 100644 --- a/bdk-ffi/src/descriptor.rs +++ b/bdk-ffi/src/descriptor.rs @@ -1,20 +1,22 @@ // use crate::{BdkError, DescriptorPublicKey, DescriptorSecretKey}; use crate::BdkError; -use std::str::FromStr; -use std::sync::Arc; +use bdk::bitcoin::bip32::Fingerprint; use bdk::bitcoin::key::Secp256k1; use bdk::descriptor::{ExtendedDescriptor, IntoWalletDescriptor}; -use bdk::keys::{DescriptorSecretKey as BdkDescriptorSecretKey, KeyMap}; use bdk::keys::DescriptorPublicKey as BdkDescriptorPublicKey; -use bdk::bitcoin::bip32::Fingerprint; +use bdk::keys::{DescriptorSecretKey as BdkDescriptorSecretKey, KeyMap}; +use bdk::template::{ + Bip44, Bip44Public, Bip49, Bip49Public, Bip84, Bip84Public, Bip86, Bip86Public, + DescriptorTemplate, +}; use bdk::KeychainKind; -use bdk::template::{Bip44, Bip44Public, Bip49, Bip49Public, Bip84, Bip84Public, Bip86, Bip86Public, DescriptorTemplate}; +use std::str::FromStr; +use std::sync::Arc; -use crate::keys::DescriptorSecretKey; use crate::keys::DescriptorPublicKey; +use crate::keys::DescriptorSecretKey; use crate::Network; - #[derive(Debug)] pub(crate) struct Descriptor { pub extended_descriptor: ExtendedDescriptor, @@ -24,7 +26,8 @@ pub(crate) struct Descriptor { impl Descriptor { pub(crate) fn new(descriptor: String, network: Network) -> Result { let secp = Secp256k1::new(); - let (extended_descriptor, key_map) = descriptor.into_wallet_descriptor(&secp, network.into())?; + let (extended_descriptor, key_map) = + descriptor.into_wallet_descriptor(&secp, network.into())?; Ok(Self { extended_descriptor, key_map, @@ -44,7 +47,9 @@ impl Descriptor { } BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { let derivable_key = descriptor_x_key.xkey; - let (extended_descriptor, key_map, _) = Bip44(derivable_key, keychain_kind).build(network.into()).unwrap(); + let (extended_descriptor, key_map, _) = Bip44(derivable_key, keychain_kind) + .build(network.into()) + .unwrap(); Self { extended_descriptor, key_map, @@ -100,8 +105,9 @@ impl Descriptor { } BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { let derivable_key = descriptor_x_key.xkey; - let (extended_descriptor, key_map, _) = - Bip49(derivable_key, keychain_kind).build(network.into()).unwrap(); + let (extended_descriptor, key_map, _) = Bip49(derivable_key, keychain_kind) + .build(network.into()) + .unwrap(); Self { extended_descriptor, key_map, @@ -157,8 +163,9 @@ impl Descriptor { } BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { let derivable_key = descriptor_x_key.xkey; - let (extended_descriptor, key_map, _) = - Bip84(derivable_key, keychain_kind).build(network.into()).unwrap(); + let (extended_descriptor, key_map, _) = Bip84(derivable_key, keychain_kind) + .build(network.into()) + .unwrap(); Self { extended_descriptor, key_map, @@ -214,8 +221,9 @@ impl Descriptor { } BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { let derivable_key = descriptor_x_key.xkey; - let (extended_descriptor, key_map, _) = - Bip86(derivable_key, keychain_kind).build(network.into()).unwrap(); + let (extended_descriptor, key_map, _) = Bip86(derivable_key, keychain_kind) + .build(network.into()) + .unwrap(); Self { extended_descriptor, key_map, @@ -269,8 +277,6 @@ impl Descriptor { } } - - // use bdk::bitcoin::secp256k1::Secp256k1; // use bdk::bitcoin::util::bip32::Fingerprint; // use bdk::bitcoin::Network; diff --git a/bdk-ffi/src/keys.rs b/bdk-ffi/src/keys.rs index 86204c86..d6cec202 100644 --- a/bdk-ffi/src/keys.rs +++ b/bdk-ffi/src/keys.rs @@ -1,9 +1,9 @@ // use crate::BdkError; +use bdk::bitcoin::bip32::DerivationPath as BdkDerivationPath; +use bdk::Error as BdkError; use std::str::FromStr; use std::sync::Mutex; -use bdk::Error as BdkError; -use bdk::bitcoin::bip32::DerivationPath as BdkDerivationPath; pub(crate) struct DerivationPath { inner_mutex: Mutex, @@ -23,18 +23,13 @@ use bdk::bitcoin::key::Secp256k1; use bdk::bitcoin::secp256k1::rand; use bdk::bitcoin::secp256k1::rand::Rng; // use bdk::keys::{DescriptorSecretKey as BdkDescriptorSecretKey, GeneratableKey, GeneratedKey}; -use bdk::keys::bip39::{Language, Mnemonic as BdkMnemonic}; use bdk::keys::bip39::WordCount; -use bdk::miniscript::BareCtx; +use bdk::keys::bip39::{Language, Mnemonic as BdkMnemonic}; use bdk::keys::{ - DerivableKey, - DescriptorSecretKey as BdkDescriptorSecretKey, - DescriptorPublicKey as BdkDescriptorPublicKey, - ExtendedKey, - GeneratableKey, - GeneratedKey + DerivableKey, DescriptorPublicKey as BdkDescriptorPublicKey, + DescriptorSecretKey as BdkDescriptorSecretKey, ExtendedKey, GeneratableKey, GeneratedKey, }; - +use bdk::miniscript::BareCtx; use bdk::miniscript::descriptor::{DescriptorXKey, Wildcard}; @@ -52,10 +47,8 @@ impl Mnemonic { let mut entropy = [0u8; 32]; rng.fill(&mut entropy); - let generated_key: GeneratedKey<_, BareCtx> = BdkMnemonic::generate_with_entropy( - (word_count, Language::English), - entropy - ).unwrap(); + let generated_key: GeneratedKey<_, BareCtx> = + BdkMnemonic::generate_with_entropy((word_count, Language::English), entropy).unwrap(); let mnemonic = BdkMnemonic::parse_in(Language::English, generated_key.to_string()).unwrap(); Mnemonic { inner: mnemonic } } @@ -135,7 +128,7 @@ impl DescriptorSecretKey { } BdkDescriptorSecretKey::MultiXPrv(_) => Err(BdkError::Generic( "Cannot derive from a multi key".to_string(), - )) + )), } } @@ -157,10 +150,10 @@ impl DescriptorSecretKey { Ok(Arc::new(Self { inner: extended_descriptor_secret_key, })) - }, + } BdkDescriptorSecretKey::MultiXPrv(_) => Err(BdkError::Generic( "Cannot derive from a multi key".to_string(), - )) + )), } } @@ -233,10 +226,10 @@ impl DescriptorPublicKey { Ok(Arc::new(Self { inner: derived_descriptor_public_key, })) - }, + } BdkDescriptorPublicKey::MultiXPub(_) => Err(BdkError::Generic( "Cannot derive from a multi xpub".to_string(), - )) + )), } } @@ -258,10 +251,10 @@ impl DescriptorPublicKey { Ok(Arc::new(Self { inner: extended_descriptor_public_key, })) - }, + } BdkDescriptorPublicKey::MultiXPub(_) => Err(BdkError::Generic( "Cannot derive from a multi xpub".to_string(), - )) + )), } } @@ -270,7 +263,6 @@ impl DescriptorPublicKey { } } - // // use bdk::bitcoin::secp256k1::Secp256k1; // use bdk::bitcoin::util::bip32::DerivationPath as BdkDerivationPath; @@ -774,4 +766,4 @@ mod test { // "e93315d6ce401eb4db803a56232f0ed3e69b053774e6047df54f1bd00e5ea936" // ) // } -} \ No newline at end of file +} diff --git a/bdk-ffi/src/lib.rs b/bdk-ffi/src/lib.rs index ee884006..bc60850f 100644 --- a/bdk-ffi/src/lib.rs +++ b/bdk-ffi/src/lib.rs @@ -22,7 +22,7 @@ impl From for BdkNetwork { match network { Network::Bitcoin => BdkNetwork::Bitcoin, Network::Testnet => BdkNetwork::Testnet, - Network::Signet => BdkNetwork::Signet, + Network::Signet => BdkNetwork::Signet, Network::Regtest => BdkNetwork::Regtest, } } @@ -33,9 +33,9 @@ impl From for Network { match network { BdkNetwork::Bitcoin => Network::Bitcoin, BdkNetwork::Testnet => Network::Testnet, - BdkNetwork::Signet => Network::Signet, + BdkNetwork::Signet => Network::Signet, BdkNetwork::Regtest => Network::Regtest, - _ => panic!("Network {} not supported", network), + _ => panic!("Network {} not supported", network), } } } @@ -74,12 +74,12 @@ use bdk::keys::bip39::WordCount; // use bdk::LocalUtxo as BdkLocalUtxo; // use bdk::TransactionDetails as BdkTransactionDetails; // use bdk::{Balance as BdkBalance, BlockTime, Error as BdkError, FeeRate, KeychainKind}; -use bdk::Error as BdkError; -use bdk::KeychainKind; use crate::descriptor::Descriptor; -use crate::keys::Mnemonic; use crate::keys::DescriptorPublicKey; use crate::keys::DescriptorSecretKey; +use crate::keys::Mnemonic; +use bdk::Error as BdkError; +use bdk::KeychainKind; // use std::convert::From; // use std::fmt; @@ -409,12 +409,12 @@ use crate::keys::DescriptorSecretKey; use std::sync::Arc; +use crate::wallet::Wallet; +use crate::wallet::WalletType; +use bdk::bitcoin::address::{NetworkChecked, NetworkUnchecked}; use bdk::bitcoin::Address as BdkAddress; use bdk::wallet::AddressIndex as BdkAddressIndex; use bdk::wallet::AddressInfo as BdkAddressInfo; -use bdk::bitcoin::address::{NetworkChecked, NetworkUnchecked}; -use crate::wallet::Wallet; -use crate::wallet::WalletType; /// A derived address and the index it was found at. pub struct AddressInfo { /// Child index of this address. @@ -425,7 +425,6 @@ pub struct AddressInfo { pub keychain: KeychainKind, } - impl From for AddressInfo { fn from(address_info: BdkAddressInfo) -> Self { AddressInfo { @@ -471,12 +470,8 @@ pub struct Address { inner: BdkAddress, } - impl Address { - fn new( - address: String, - network: Network, - ) -> Result { + fn new(address: String, network: Network) -> Result { Ok(Address { inner: address .parse::>() diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index 165e9aca..8eba3e13 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -857,10 +857,10 @@ // assert_matches!(is_mine_2, false); // } // } -use std::sync::{Arc, Mutex, MutexGuard}; -use bdk::Wallet as BdkWallet; use crate::descriptor::Descriptor; use crate::{AddressIndex, AddressInfo, Network}; +use bdk::Wallet as BdkWallet; +use std::sync::{Arc, Mutex, MutexGuard}; // use bdk::wallet::AddressIndex as BdkAddressIndex; use bdk::Error as BdkError; pub enum WalletType { @@ -907,5 +907,4 @@ impl Wallet { pub(crate) fn get_wallet(&self) -> MutexGuard { self.inner_mutex.lock().expect("wallet") } - -} \ No newline at end of file +}