From 2e43efda80820ce99b210a5eecd083a04679cfa6 Mon Sep 17 00:00:00 2001 From: Matthew Date: Sat, 14 Oct 2023 20:16:38 -0500 Subject: [PATCH] delete unused code except for tests --- Cargo.lock | 10 +- bdk-ffi/src/bdk.udl | 1 - bdk-ffi/src/blockchain.rs | 203 +------------- bdk-ffi/src/database.rs | 15 +- bdk-ffi/src/descriptor.rs | 253 +---------------- bdk-ffi/src/keys.rs | 247 +---------------- bdk-ffi/src/lib.rs | 472 +------------------------------ bdk-ffi/src/psbt.rs | 79 ------ bdk-ffi/src/wallet.rs | 565 +------------------------------------- 9 files changed, 18 insertions(+), 1827 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8821c9de..6fe214a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -84,8 +84,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "bdk" -version = "1.0.0-alpha.1" -source = "git+https://github.com/bitcoindevkit/bdk.git?rev=59fc1b341ba94212b2ea3e888e51fb6fcd00589f#59fc1b341ba94212b2ea3e888e51fb6fcd00589f" +version = "1.0.0-alpha.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99559c90df27c7dac369182a47ec96425f71764540765bba6558ea79877e50ee" dependencies = [ "bdk_chain", "bip39", @@ -110,8 +111,9 @@ dependencies = [ [[package]] name = "bdk_chain" -version = "0.5.0" -source = "git+https://github.com/bitcoindevkit/bdk.git?rev=59fc1b341ba94212b2ea3e888e51fb6fcd00589f#59fc1b341ba94212b2ea3e888e51fb6fcd00589f" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5043c1254d39534da6b2ca67e139aac8e9a4719671ae6b4063ecd2c791179879" dependencies = [ "bitcoin", "miniscript", diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index cf2f3c97..921283fe 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -173,7 +173,6 @@ interface AddressIndex { Peek(u32 index); }; - interface Balance { u64 immature(); u64 trusted_pending(); diff --git a/bdk-ffi/src/blockchain.rs b/bdk-ffi/src/blockchain.rs index c65edeeb..8b137891 100644 --- a/bdk-ffi/src/blockchain.rs +++ b/bdk-ffi/src/blockchain.rs @@ -1,202 +1 @@ -// // use crate::BlockchainConfig; -// use crate::{BdkError, Transaction}; -// use crate::BdkError; -// use bdk::bitcoin::Network; -// use bdk::blockchain::any::{AnyBlockchain, AnyBlockchainConfig}; -// use bdk::blockchain::rpc::Auth as BdkAuth; -// use bdk::blockchain::rpc::RpcSyncParams as BdkRpcSyncParams; -// use bdk::blockchain::Blockchain as BdkBlockchain; -// use bdk::blockchain::GetBlockHash; -// use bdk::blockchain::GetHeight; -// use bdk::blockchain::{ -// electrum::ElectrumBlockchainConfig, esplora::EsploraBlockchainConfig, -// rpc::RpcConfig as BdkRpcConfig, ConfigurableBlockchain, -// }; -// use bdk::FeeRate; -// use std::convert::{From, TryFrom}; -// use std::path::PathBuf; -// use std::sync::{Arc, Mutex, MutexGuard}; -// -// pub(crate) struct Blockchain { -// inner_mutex: Mutex, -// } -// -// impl Blockchain { -// pub(crate) fn new(blockchain_config: BlockchainConfig) -> Result { -// let any_blockchain_config = match blockchain_config { -// BlockchainConfig::Electrum { config } => { -// AnyBlockchainConfig::Electrum(ElectrumBlockchainConfig { -// retry: config.retry, -// socks5: config.socks5, -// timeout: config.timeout, -// url: config.url, -// stop_gap: usize::try_from(config.stop_gap).unwrap(), -// validate_domain: config.validate_domain, -// }) -// } -// BlockchainConfig::Esplora { config } => { -// AnyBlockchainConfig::Esplora(EsploraBlockchainConfig { -// base_url: config.base_url, -// proxy: config.proxy, -// concurrency: config.concurrency, -// stop_gap: usize::try_from(config.stop_gap).unwrap(), -// timeout: config.timeout, -// }) -// } -// BlockchainConfig::Rpc { config } => AnyBlockchainConfig::Rpc(BdkRpcConfig { -// url: config.url, -// auth: config.auth.into(), -// network: config.network, -// wallet_name: config.wallet_name, -// sync_params: config.sync_params.map(|p| p.into()), -// }), -// }; -// let blockchain = AnyBlockchain::from_config(&any_blockchain_config)?; -// Ok(Self { -// inner_mutex: Mutex::new(blockchain), -// }) -// } -// -// pub(crate) fn get_blockchain(&self) -> MutexGuard { -// self.inner_mutex.lock().expect("blockchain") -// } -// -// pub(crate) fn broadcast(&self, transaction: &Transaction) -> Result<(), BdkError> { -// let tx = &transaction.inner; -// self.get_blockchain().broadcast(tx) -// } -// -// pub(crate) fn estimate_fee(&self, target: u64) -> Result, BdkError> { -// let result: Result = -// self.get_blockchain().estimate_fee(target as usize); -// result.map(Arc::new) -// } -// -// pub(crate) fn get_height(&self) -> Result { -// self.get_blockchain().get_height() -// } -// -// pub(crate) fn get_block_hash(&self, height: u32) -> Result { -// self.get_blockchain() -// .get_block_hash(u64::from(height)) -// .map(|hash| hash.to_string()) -// } -// } -// -// /// Configuration for an ElectrumBlockchain -// pub struct ElectrumConfig { -// /// URL of the Electrum server (such as ElectrumX, Esplora, BWT) may start with ssl:// or tcp:// and include a port -// /// e.g. ssl://electrum.blockstream.info:60002 -// pub url: String, -// /// URL of the socks5 proxy server or a Tor service -// pub socks5: Option, -// /// Request retry count -// pub retry: u8, -// /// Request timeout (seconds) -// pub timeout: Option, -// /// Stop searching addresses for transactions after finding an unused gap of this length -// pub stop_gap: u64, -// /// Validate the domain when using SSL -// pub validate_domain: bool, -// } -// -// /// Configuration for an EsploraBlockchain -// pub struct EsploraConfig { -// /// Base URL of the esplora service -// /// e.g. https://blockstream.info/api/ -// pub base_url: String, -// /// Optional URL of the proxy to use to make requests to the Esplora server -// /// The string should be formatted as: ://:@host:. -// /// Note that the format of this value and the supported protocols change slightly between the -// /// sync version of esplora (using ureq) and the async version (using reqwest). For more -// /// details check with the documentation of the two crates. Both of them are compiled with -// /// the socks feature enabled. -// /// The proxy is ignored when targeting wasm32. -// pub proxy: Option, -// /// Number of parallel requests sent to the esplora service (default: 4) -// pub concurrency: Option, -// /// Stop searching addresses for transactions after finding an unused gap of this length. -// pub stop_gap: u64, -// /// Socket timeout. -// pub timeout: Option, -// } -// -// pub enum Auth { -// /// No authentication -// None, -// /// Authentication with username and password, usually [Auth::Cookie] should be preferred -// UserPass { -// /// Username -// username: String, -// /// Password -// password: String, -// }, -// /// Authentication with a cookie file -// Cookie { -// /// Cookie file -// file: String, -// }, -// } -// -// impl From for BdkAuth { -// fn from(auth: Auth) -> Self { -// match auth { -// Auth::None => BdkAuth::None, -// Auth::UserPass { username, password } => BdkAuth::UserPass { username, password }, -// Auth::Cookie { file } => BdkAuth::Cookie { -// file: PathBuf::from(file), -// }, -// } -// } -// } -// -// /// Sync parameters for Bitcoin Core RPC. -// /// -// /// In general, BDK tries to sync `scriptPubKey`s cached in `Database` with -// /// `scriptPubKey`s imported in the Bitcoin Core Wallet. These parameters are used for determining -// /// how the `importdescriptors` RPC calls are to be made. -// pub struct RpcSyncParams { -// /// The minimum number of scripts to scan for on initial sync. -// pub start_script_count: u64, -// /// Time in unix seconds in which initial sync will start scanning from (0 to start from genesis). -// pub start_time: u64, -// /// Forces every sync to use `start_time` as import timestamp. -// pub force_start_time: bool, -// /// RPC poll rate (in seconds) to get state updates. -// pub poll_rate_sec: u64, -// } -// -// impl From for BdkRpcSyncParams { -// fn from(params: RpcSyncParams) -> Self { -// BdkRpcSyncParams { -// start_script_count: params.start_script_count as usize, -// start_time: params.start_time, -// force_start_time: params.force_start_time, -// poll_rate_sec: params.poll_rate_sec, -// } -// } -// } -// -// /// RpcBlockchain configuration options -// pub struct RpcConfig { -// /// The bitcoin node url -// pub url: String, -// /// The bitcoin node authentication mechanism -// pub auth: Auth, -// /// The network we are using (it will be checked the bitcoin node network matches this) -// pub network: Network, -// /// The wallet name in the bitcoin node, consider using [crate::wallet::wallet_name_from_descriptor] for this -// pub wallet_name: String, -// /// Sync parameters -// pub sync_params: Option, -// } -// -// /// Type that can contain any of the blockchain configurations defined by the library. -// pub enum BlockchainConfig { -// /// Electrum client -// Electrum { config: ElectrumConfig }, -// /// Esplora client -// Esplora { config: EsploraConfig }, -// /// Bitcoin Core RPC client -// Rpc { config: RpcConfig }, -// } + diff --git a/bdk-ffi/src/database.rs b/bdk-ffi/src/database.rs index 63cbfb59..8b137891 100644 --- a/bdk-ffi/src/database.rs +++ b/bdk-ffi/src/database.rs @@ -1,14 +1 @@ -// use bdk::database::any::{SledDbConfiguration, SqliteDbConfiguration}; -// -// /// Type that can contain any of the database configurations defined by the library -// /// This allows storing a single configuration that can be loaded into an AnyDatabaseConfig -// /// instance. Wallets that plan to offer users the ability to switch blockchain backend at runtime -// /// will find this particularly useful. -// pub enum DatabaseConfig { -// /// Memory database has no config -// Memory, -// /// Simple key-value embedded database based on sled -// Sled { config: SledDbConfiguration }, -// /// Sqlite embedded database using rusqlite -// Sqlite { config: SqliteDbConfiguration }, -// } + diff --git a/bdk-ffi/src/descriptor.rs b/bdk-ffi/src/descriptor.rs index ee2d4217..61f75753 100644 --- a/bdk-ffi/src/descriptor.rs +++ b/bdk-ffi/src/descriptor.rs @@ -1,5 +1,8 @@ // use crate::{BdkError, DescriptorPublicKey, DescriptorSecretKey}; +use crate::keys::DescriptorPublicKey; +use crate::keys::DescriptorSecretKey; use crate::BdkError; +use crate::Network; use bdk::bitcoin::bip32::Fingerprint; use bdk::bitcoin::key::Secp256k1; use bdk::descriptor::{ExtendedDescriptor, IntoWalletDescriptor}; @@ -13,10 +16,6 @@ use bdk::KeychainKind; use std::str::FromStr; use std::sync::Arc; -use crate::keys::DescriptorPublicKey; -use crate::keys::DescriptorSecretKey; -use crate::Network; - #[derive(Debug)] pub(crate) struct Descriptor { pub extended_descriptor: ExtendedDescriptor, @@ -277,252 +276,6 @@ impl Descriptor { } } -// use bdk::bitcoin::secp256k1::Secp256k1; -// use bdk::bitcoin::util::bip32::Fingerprint; -// use bdk::bitcoin::Network; -// use bdk::descriptor::{ExtendedDescriptor, IntoWalletDescriptor, KeyMap}; -// use bdk::keys::{ -// DescriptorPublicKey as BdkDescriptorPublicKey, DescriptorSecretKey as BdkDescriptorSecretKey, -// }; -// use bdk::template::{ -// Bip44, Bip44Public, Bip49, Bip49Public, Bip84, Bip84Public, Bip86, Bip86Public, -// DescriptorTemplate, -// }; -// use bdk::KeychainKind; -// use std::str::FromStr; -// use std::sync::Arc; -// -// #[derive(Debug)] -// pub(crate) struct Descriptor { -// pub(crate) extended_descriptor: ExtendedDescriptor, -// pub(crate) key_map: KeyMap, -// } -// -// 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)?; -// Ok(Self { -// extended_descriptor, -// key_map, -// }) -// } -// -// pub(crate) fn new_bip44( -// secret_key: Arc, -// keychain_kind: KeychainKind, -// network: Network, -// ) -> Self { -// let derivable_key = &secret_key.inner; -// -// match derivable_key { -// BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { -// let derivable_key = descriptor_x_key.xkey; -// let (extended_descriptor, key_map, _) = -// Bip44(derivable_key, keychain_kind).build(network).unwrap(); -// Self { -// extended_descriptor, -// key_map, -// } -// } -// BdkDescriptorSecretKey::Single(_) => { -// unreachable!() -// } -// } -// } -// -// pub(crate) fn new_bip44_public( -// public_key: Arc, -// fingerprint: String, -// keychain_kind: KeychainKind, -// network: Network, -// ) -> Self { -// let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap(); -// let derivable_key = &public_key.inner; -// -// match derivable_key { -// BdkDescriptorPublicKey::XPub(descriptor_x_key) => { -// let derivable_key = descriptor_x_key.xkey; -// let (extended_descriptor, key_map, _) = -// Bip44Public(derivable_key, fingerprint, keychain_kind) -// .build(network) -// .unwrap(); -// -// Self { -// extended_descriptor, -// key_map, -// } -// } -// BdkDescriptorPublicKey::Single(_) => { -// unreachable!() -// } -// } -// } -// -// pub(crate) fn new_bip49( -// secret_key: Arc, -// keychain_kind: KeychainKind, -// network: Network, -// ) -> Self { -// let derivable_key = &secret_key.inner; -// -// match derivable_key { -// BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { -// let derivable_key = descriptor_x_key.xkey; -// let (extended_descriptor, key_map, _) = -// Bip49(derivable_key, keychain_kind).build(network).unwrap(); -// Self { -// extended_descriptor, -// key_map, -// } -// } -// BdkDescriptorSecretKey::Single(_) => { -// unreachable!() -// } -// } -// } -// -// pub(crate) fn new_bip49_public( -// public_key: Arc, -// fingerprint: String, -// keychain_kind: KeychainKind, -// network: Network, -// ) -> Self { -// let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap(); -// let derivable_key = &public_key.inner; -// -// match derivable_key { -// BdkDescriptorPublicKey::XPub(descriptor_x_key) => { -// let derivable_key = descriptor_x_key.xkey; -// let (extended_descriptor, key_map, _) = -// Bip49Public(derivable_key, fingerprint, keychain_kind) -// .build(network) -// .unwrap(); -// -// Self { -// extended_descriptor, -// key_map, -// } -// } -// BdkDescriptorPublicKey::Single(_) => { -// unreachable!() -// } -// } -// } -// -// pub(crate) fn new_bip84( -// secret_key: Arc, -// keychain_kind: KeychainKind, -// network: Network, -// ) -> Self { -// let derivable_key = &secret_key.inner; -// -// match derivable_key { -// BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { -// let derivable_key = descriptor_x_key.xkey; -// let (extended_descriptor, key_map, _) = -// Bip84(derivable_key, keychain_kind).build(network).unwrap(); -// Self { -// extended_descriptor, -// key_map, -// } -// } -// BdkDescriptorSecretKey::Single(_) => { -// unreachable!() -// } -// } -// } -// -// pub(crate) fn new_bip84_public( -// public_key: Arc, -// fingerprint: String, -// keychain_kind: KeychainKind, -// network: Network, -// ) -> Self { -// let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap(); -// let derivable_key = &public_key.inner; -// -// match derivable_key { -// BdkDescriptorPublicKey::XPub(descriptor_x_key) => { -// let derivable_key = descriptor_x_key.xkey; -// let (extended_descriptor, key_map, _) = -// Bip84Public(derivable_key, fingerprint, keychain_kind) -// .build(network) -// .unwrap(); -// -// Self { -// extended_descriptor, -// key_map, -// } -// } -// BdkDescriptorPublicKey::Single(_) => { -// unreachable!() -// } -// } -// } -// -// pub(crate) fn new_bip86( -// secret_key: Arc, -// keychain_kind: KeychainKind, -// network: Network, -// ) -> Self { -// let derivable_key = &secret_key.inner; -// -// match derivable_key { -// BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { -// let derivable_key = descriptor_x_key.xkey; -// let (extended_descriptor, key_map, _) = -// Bip86(derivable_key, keychain_kind).build(network).unwrap(); -// Self { -// extended_descriptor, -// key_map, -// } -// } -// BdkDescriptorSecretKey::Single(_) => { -// unreachable!() -// } -// } -// } -// -// pub(crate) fn new_bip86_public( -// public_key: Arc, -// fingerprint: String, -// keychain_kind: KeychainKind, -// network: Network, -// ) -> Self { -// let fingerprint = Fingerprint::from_str(fingerprint.as_str()).unwrap(); -// let derivable_key = &public_key.inner; -// -// match derivable_key { -// BdkDescriptorPublicKey::XPub(descriptor_x_key) => { -// let derivable_key = descriptor_x_key.xkey; -// let (extended_descriptor, key_map, _) = -// Bip86Public(derivable_key, fingerprint, keychain_kind) -// .build(network) -// .unwrap(); -// -// Self { -// extended_descriptor, -// key_map, -// } -// } -// BdkDescriptorPublicKey::Single(_) => { -// unreachable!() -// } -// } -// } -// -// pub(crate) fn as_string_private(&self) -> String { -// let descriptor = &self.extended_descriptor; -// let key_map = &self.key_map; -// descriptor.to_string_with_secret(key_map) -// } -// -// pub(crate) fn as_string(&self) -> String { -// self.extended_descriptor.to_string() -// } -// } -// // // The goal of these tests to to ensure `bdk-ffi` intermediate code correctly calls `bdk` APIs. // // These tests should not be used to verify `bdk` behavior that is already tested in the `bdk` // // crate. diff --git a/bdk-ffi/src/keys.rs b/bdk-ffi/src/keys.rs index d6cec202..b491c3fc 100644 --- a/bdk-ffi/src/keys.rs +++ b/bdk-ffi/src/keys.rs @@ -1,5 +1,3 @@ -// use crate::BdkError; - use bdk::bitcoin::bip32::DerivationPath as BdkDerivationPath; use bdk::Error as BdkError; use std::str::FromStr; @@ -19,21 +17,18 @@ impl DerivationPath { } } +use crate::Network; 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::WordCount; use bdk::keys::bip39::{Language, Mnemonic as BdkMnemonic}; use bdk::keys::{ DerivableKey, DescriptorPublicKey as BdkDescriptorPublicKey, DescriptorSecretKey as BdkDescriptorSecretKey, ExtendedKey, GeneratableKey, GeneratedKey, }; -use bdk::miniscript::BareCtx; - use bdk::miniscript::descriptor::{DescriptorXKey, Wildcard}; - -use crate::Network; +use bdk::miniscript::BareCtx; pub(crate) struct Mnemonic { inner: BdkMnemonic, @@ -263,247 +258,9 @@ impl DescriptorPublicKey { } } -// -// use bdk::bitcoin::secp256k1::Secp256k1; -// use bdk::bitcoin::util::bip32::DerivationPath as BdkDerivationPath; -// use bdk::bitcoin::Network; -// use bdk::descriptor::DescriptorXKey; -// use bdk::keys::bip39::{Language, Mnemonic as BdkMnemonic, WordCount}; -// use bdk::keys::{ -// DerivableKey, DescriptorPublicKey as BdkDescriptorPublicKey, -// DescriptorSecretKey as BdkDescriptorSecretKey, ExtendedKey, GeneratableKey, GeneratedKey, -// }; -// use bdk::miniscript::BareCtx; use std::ops::Deref; use std::sync::Arc; -// use std::str::FromStr; -// use std::sync::{Arc, Mutex}; -// -// /// Mnemonic phrases are a human-readable version of the private keys. -// /// Supported number of words are 12, 15, 18, 21 and 24. -// pub(crate) struct Mnemonic { -// inner: BdkMnemonic, -// } -// -// impl Mnemonic { -// /// Generates Mnemonic with a random entropy -// pub(crate) fn new(word_count: WordCount) -> Self { -// let generated_key: GeneratedKey<_, BareCtx> = -// BdkMnemonic::generate((word_count, Language::English)).unwrap(); -// let mnemonic = BdkMnemonic::parse_in(Language::English, generated_key.to_string()).unwrap(); -// Mnemonic { inner: mnemonic } -// } -// -// /// Parse a Mnemonic with given string -// pub(crate) fn from_string(mnemonic: String) -> Result { -// BdkMnemonic::from_str(&mnemonic) -// .map(|m| Mnemonic { inner: m }) -// .map_err(|e| BdkError::Generic(e.to_string())) -// } -// -// /// Create a new Mnemonic in the specified language from the given entropy. -// /// Entropy must be a multiple of 32 bits (4 bytes) and 128-256 bits in length. -// pub(crate) fn from_entropy(entropy: Vec) -> Result { -// BdkMnemonic::from_entropy(entropy.as_slice()) -// .map(|m| Mnemonic { inner: m }) -// .map_err(|e| BdkError::Generic(e.to_string())) -// } -// -// /// Returns Mnemonic as string -// pub(crate) fn as_string(&self) -> String { -// self.inner.to_string() -// } -// } -// -// pub(crate) struct DerivationPath { -// inner_mutex: Mutex, -// } -// -// impl DerivationPath { -// pub(crate) fn new(path: String) -> Result { -// BdkDerivationPath::from_str(&path) -// .map(|x| DerivationPath { -// inner_mutex: Mutex::new(x), -// }) -// .map_err(|e| BdkError::Generic(e.to_string())) -// } -// } -// -// #[derive(Debug)] -// pub(crate) struct DescriptorSecretKey { -// pub(crate) inner: BdkDescriptorSecretKey, -// } -// -// impl DescriptorSecretKey { -// pub(crate) fn new(network: Network, mnemonic: Arc, password: Option) -> Self { -// let mnemonic = mnemonic.inner.clone(); -// let xkey: ExtendedKey = (mnemonic, password).into_extended_key().unwrap(); -// let descriptor_secret_key = BdkDescriptorSecretKey::XPrv(DescriptorXKey { -// origin: None, -// xkey: xkey.into_xprv(network).unwrap(), -// derivation_path: BdkDerivationPath::master(), -// wildcard: bdk::descriptor::Wildcard::Unhardened, -// }); -// Self { -// inner: descriptor_secret_key, -// } -// } -// -// pub(crate) fn from_string(private_key: String) -> Result { -// let descriptor_secret_key = BdkDescriptorSecretKey::from_str(private_key.as_str()) -// .map_err(|e| BdkError::Generic(e.to_string()))?; -// Ok(Self { -// inner: descriptor_secret_key, -// }) -// } -// -// pub(crate) fn derive(&self, path: Arc) -> Result, BdkError> { -// let secp = Secp256k1::new(); -// let descriptor_secret_key = &self.inner; -// let path = path.inner_mutex.lock().unwrap().deref().clone(); -// match descriptor_secret_key { -// BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { -// let derived_xprv = descriptor_x_key.xkey.derive_priv(&secp, &path)?; -// let key_source = match descriptor_x_key.origin.clone() { -// Some((fingerprint, origin_path)) => (fingerprint, origin_path.extend(path)), -// None => (descriptor_x_key.xkey.fingerprint(&secp), path), -// }; -// let derived_descriptor_secret_key = BdkDescriptorSecretKey::XPrv(DescriptorXKey { -// origin: Some(key_source), -// xkey: derived_xprv, -// derivation_path: BdkDerivationPath::default(), -// wildcard: descriptor_x_key.wildcard, -// }); -// Ok(Arc::new(Self { -// inner: derived_descriptor_secret_key, -// })) -// } -// BdkDescriptorSecretKey::Single(_) => Err(BdkError::Generic( -// "Cannot derive from a single key".to_string(), -// )), -// } -// } -// -// pub(crate) fn extend(&self, path: Arc) -> Result, BdkError> { -// let descriptor_secret_key = &self.inner; -// let path = path.inner_mutex.lock().unwrap().deref().clone(); -// match descriptor_secret_key { -// BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { -// let extended_path = descriptor_x_key.derivation_path.extend(path); -// let extended_descriptor_secret_key = BdkDescriptorSecretKey::XPrv(DescriptorXKey { -// origin: descriptor_x_key.origin.clone(), -// xkey: descriptor_x_key.xkey, -// derivation_path: extended_path, -// wildcard: descriptor_x_key.wildcard, -// }); -// Ok(Arc::new(Self { -// inner: extended_descriptor_secret_key, -// })) -// } -// BdkDescriptorSecretKey::Single(_) => Err(BdkError::Generic( -// "Cannot extend from a single key".to_string(), -// )), -// } -// } -// -// pub(crate) fn as_public(&self) -> Arc { -// let secp = Secp256k1::new(); -// let descriptor_public_key = self.inner.to_public(&secp).unwrap(); -// Arc::new(DescriptorPublicKey { -// inner: descriptor_public_key, -// }) -// } -// -// /// Get the private key as bytes. -// pub(crate) fn secret_bytes(&self) -> Vec { -// let inner = &self.inner; -// let secret_bytes: Vec = match inner.deref() { -// BdkDescriptorSecretKey::XPrv(descriptor_x_key) => { -// descriptor_x_key.xkey.private_key.secret_bytes().to_vec() -// } -// BdkDescriptorSecretKey::Single(_) => { -// unreachable!() -// } -// }; -// -// secret_bytes -// } -// -// pub(crate) fn as_string(&self) -> String { -// self.inner.to_string() -// } -// } -// -// #[derive(Debug)] -// pub(crate) struct DescriptorPublicKey { -// pub(crate) inner: BdkDescriptorPublicKey, -// } -// -// impl DescriptorPublicKey { -// pub(crate) fn from_string(public_key: String) -> Result { -// let descriptor_public_key = BdkDescriptorPublicKey::from_str(public_key.as_str()) -// .map_err(|e| BdkError::Generic(e.to_string()))?; -// Ok(Self { -// inner: descriptor_public_key, -// }) -// } -// -// pub(crate) fn derive(&self, path: Arc) -> Result, BdkError> { -// let secp = Secp256k1::new(); -// let descriptor_public_key = &self.inner; -// let path = path.inner_mutex.lock().unwrap().deref().clone(); -// -// match descriptor_public_key.deref() { -// BdkDescriptorPublicKey::XPub(descriptor_x_key) => { -// let derived_xpub = descriptor_x_key.xkey.derive_pub(&secp, &path)?; -// let key_source = match descriptor_x_key.origin.clone() { -// Some((fingerprint, origin_path)) => (fingerprint, origin_path.extend(path)), -// None => (descriptor_x_key.xkey.fingerprint(), path), -// }; -// let derived_descriptor_public_key = BdkDescriptorPublicKey::XPub(DescriptorXKey { -// origin: Some(key_source), -// xkey: derived_xpub, -// derivation_path: BdkDerivationPath::default(), -// wildcard: descriptor_x_key.wildcard, -// }); -// Ok(Arc::new(Self { -// inner: derived_descriptor_public_key, -// })) -// } -// BdkDescriptorPublicKey::Single(_) => Err(BdkError::Generic( -// "Cannot derive from a single key".to_string(), -// )), -// } -// } -// -// pub(crate) fn extend(&self, path: Arc) -> Result, BdkError> { -// let descriptor_public_key = &self.inner; -// let path = path.inner_mutex.lock().unwrap().deref().clone(); -// match descriptor_public_key.deref() { -// BdkDescriptorPublicKey::XPub(descriptor_x_key) => { -// let extended_path = descriptor_x_key.derivation_path.extend(path); -// let extended_descriptor_public_key = BdkDescriptorPublicKey::XPub(DescriptorXKey { -// origin: descriptor_x_key.origin.clone(), -// xkey: descriptor_x_key.xkey, -// derivation_path: extended_path, -// wildcard: descriptor_x_key.wildcard, -// }); -// Ok(Arc::new(Self { -// inner: extended_descriptor_public_key, -// })) -// } -// BdkDescriptorPublicKey::Single(_) => Err(BdkError::Generic( -// "Cannot extend from a single key".to_string(), -// )), -// } -// } -// -// pub(crate) fn as_string(&self) -> String { -// self.inner.to_string() -// } -// } -// // // The goal of these tests to to ensure `bdk-ffi` intermediate code correctly calls `bdk` APIs. // // These tests should not be used to verify `bdk` behavior that is already tested in the `bdk` // // crate. diff --git a/bdk-ffi/src/lib.rs b/bdk-ffi/src/lib.rs index 68312c7f..4189daa1 100644 --- a/bdk-ffi/src/lib.rs +++ b/bdk-ffi/src/lib.rs @@ -47,170 +47,16 @@ mod descriptor; mod keys; mod psbt; mod wallet; -// -// use crate::blockchain::{ -// Auth, Blockchain, BlockchainConfig, ElectrumConfig, EsploraConfig, RpcConfig, RpcSyncParams, -// }; -// use crate::database::DatabaseConfig; -// use crate::descriptor::Descriptor; -use crate::keys::DerivationPath; -// use crate::keys::{DescriptorPublicKey, DescriptorSecretKey, Mnemonic}; -// use crate::psbt::PartiallySignedTransaction; -// use crate::wallet::SignOptions; -// use crate::wallet::{BumpFeeTxBuilder, TxBuilder, Wallet}; -// use bdk::bitcoin::blockdata::script::Script as BdkScript; -// use bdk::bitcoin::blockdata::transaction::TxIn as BdkTxIn; -// use bdk::bitcoin::blockdata::transaction::TxOut as BdkTxOut; -// use bdk::bitcoin::consensus::Decodable; -// use bdk::bitcoin::psbt::serialize::Serialize; -// use bdk::bitcoin::util::address::{Payload as BdkPayload, WitnessVersion}; -// use bdk::bitcoin::{ -// Address as BdkAddress, Network, OutPoint as BdkOutPoint, Transaction as BdkTransaction, Txid, -// }; -// use bdk::blockchain::Progress as BdkProgress; -// use bdk::database::any::{SledDbConfiguration, SqliteDbConfiguration}; -use bdk::keys::bip39::WordCount; -// use bdk::wallet::AddressIndex as BdkAddressIndex; -// use bdk::wallet::AddressInfo as BdkAddressInfo; -// use bdk::LocalUtxo as BdkLocalUtxo; -// use bdk::TransactionDetails as BdkTransactionDetails; -// use bdk::{Balance as BdkBalance, BlockTime, Error as BdkError, FeeRate, KeychainKind}; + use crate::descriptor::Descriptor; +use crate::keys::DerivationPath; use crate::keys::DescriptorPublicKey; use crate::keys::DescriptorSecretKey; use crate::keys::Mnemonic; +use bdk::keys::bip39::WordCount; use bdk::Error as BdkError; use bdk::KeychainKind; -// use std::convert::From; -// use std::fmt; -// use std::fmt::Debug; -// use std::io::Cursor; -// use std::str::FromStr; -// use std::sync::Arc; -// -// uniffi::include_scaffolding!("bdk"); -// -// /// A output script and an amount of satoshis. -// pub struct ScriptAmount { -// pub script: Arc