Refactor: separate database from lib.rs
This commit is contained in:
parent
46bd9a1f15
commit
202dcfa2b5
14
bdk-ffi/src/database.rs
Normal file
14
bdk-ffi/src/database.rs
Normal file
@ -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 },
|
||||
}
|
@ -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<AddressIndex> 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;
|
||||
|
@ -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)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user