From 202dcfa2b505bc4f6f54d4c18e4f6d063255a5e9 Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Mon, 19 Dec 2022 14:18:24 -0500 Subject: [PATCH] Refactor: separate database from lib.rs --- bdk-ffi/src/database.rs | 14 ++++++++++++++ bdk-ffi/src/lib.rs | 24 ++++-------------------- bdk-ffi/src/wallet.rs | 6 +++--- 3 files changed, 21 insertions(+), 23 deletions(-) create mode 100644 bdk-ffi/src/database.rs diff --git a/bdk-ffi/src/database.rs b/bdk-ffi/src/database.rs new file mode 100644 index 0000000..b5b98b8 --- /dev/null +++ b/bdk-ffi/src/database.rs @@ -0,0 +1,14 @@ +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/lib.rs b/bdk-ffi/src/lib.rs index 7d9b178..bf030b6 100644 --- a/bdk-ffi/src/lib.rs +++ b/bdk-ffi/src/lib.rs @@ -1,4 +1,5 @@ mod blockchain; +mod database; mod descriptor; mod keys; mod psbt; @@ -7,22 +8,17 @@ 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::{BumpFeeTxBuilder, TxBuilder, Wallet}; use bdk::bitcoin::blockdata::script::Script as BdkScript; -use bdk::bitcoin::secp256k1::Secp256k1; use bdk::bitcoin::{Address as BdkAddress, Network, OutPoint as BdkOutPoint, Txid}; use bdk::blockchain::Progress as BdkProgress; use bdk::database::any::{SledDbConfiguration, SqliteDbConfiguration}; -use bdk::descriptor::{DescriptorXKey}; -use bdk::keys::bip39::{Language, WordCount}; -use bdk::keys::{ - DerivableKey, ExtendedKey, GeneratableKey, GeneratedKey, -}; -use bdk::miniscript::BareCtx; +use bdk::keys::bip39::WordCount; use bdk::wallet::AddressIndex as BdkAddressIndex; use bdk::wallet::AddressInfo as BdkAddressInfo; use bdk::{Balance as BdkBalance, BlockTime, Error as BdkError, FeeRate, KeychainKind}; @@ -80,19 +76,6 @@ impl From for BdkAddressIndex { } } -/// 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 }, -} - /// A wallet transaction #[derive(Debug, Clone, PartialEq, Eq, Default)] pub struct TransactionDetails { @@ -288,6 +271,7 @@ uniffi::deps::static_assertions::assert_impl_all!(Wallet: Sync, Send); // crate. #[cfg(test)] mod test { + use crate::database::DatabaseConfig; use crate::*; use assert_matches::assert_matches; use bdk::bitcoin::hashes::hex::ToHex; diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index 0de949f..2459aaf 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -10,12 +10,12 @@ use std::str::FromStr; use std::sync::{Arc, Mutex, MutexGuard}; use crate::blockchain::Blockchain; +use crate::database::DatabaseConfig; use crate::descriptor::Descriptor; use crate::psbt::PartiallySignedTransaction; use crate::{ - AddressIndex, AddressInfo, Balance, BdkError, DatabaseConfig, LocalUtxo, NetworkLocalUtxo, - OutPoint, Progress, ProgressHolder, RbfValue, Script, ScriptAmount, TransactionDetails, - TxBuilderResult, + AddressIndex, AddressInfo, Balance, BdkError, LocalUtxo, NetworkLocalUtxo, OutPoint, Progress, + ProgressHolder, RbfValue, Script, ScriptAmount, TransactionDetails, TxBuilderResult, }; #[derive(Debug)]