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 blockchain;
|
||||||
|
mod database;
|
||||||
mod descriptor;
|
mod descriptor;
|
||||||
mod keys;
|
mod keys;
|
||||||
mod psbt;
|
mod psbt;
|
||||||
@ -7,22 +8,17 @@ mod wallet;
|
|||||||
use crate::blockchain::{
|
use crate::blockchain::{
|
||||||
Auth, Blockchain, BlockchainConfig, ElectrumConfig, EsploraConfig, RpcConfig, RpcSyncParams,
|
Auth, Blockchain, BlockchainConfig, ElectrumConfig, EsploraConfig, RpcConfig, RpcSyncParams,
|
||||||
};
|
};
|
||||||
|
use crate::database::DatabaseConfig;
|
||||||
use crate::descriptor::Descriptor;
|
use crate::descriptor::Descriptor;
|
||||||
use crate::keys::DerivationPath;
|
use crate::keys::DerivationPath;
|
||||||
use crate::keys::{DescriptorPublicKey, DescriptorSecretKey, Mnemonic};
|
use crate::keys::{DescriptorPublicKey, DescriptorSecretKey, Mnemonic};
|
||||||
use crate::psbt::PartiallySignedTransaction;
|
use crate::psbt::PartiallySignedTransaction;
|
||||||
use crate::wallet::{BumpFeeTxBuilder, TxBuilder, Wallet};
|
use crate::wallet::{BumpFeeTxBuilder, TxBuilder, Wallet};
|
||||||
use bdk::bitcoin::blockdata::script::Script as BdkScript;
|
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::bitcoin::{Address as BdkAddress, Network, OutPoint as BdkOutPoint, Txid};
|
||||||
use bdk::blockchain::Progress as BdkProgress;
|
use bdk::blockchain::Progress as BdkProgress;
|
||||||
use bdk::database::any::{SledDbConfiguration, SqliteDbConfiguration};
|
use bdk::database::any::{SledDbConfiguration, SqliteDbConfiguration};
|
||||||
use bdk::descriptor::{DescriptorXKey};
|
use bdk::keys::bip39::WordCount;
|
||||||
use bdk::keys::bip39::{Language, WordCount};
|
|
||||||
use bdk::keys::{
|
|
||||||
DerivableKey, ExtendedKey, GeneratableKey, GeneratedKey,
|
|
||||||
};
|
|
||||||
use bdk::miniscript::BareCtx;
|
|
||||||
use bdk::wallet::AddressIndex as BdkAddressIndex;
|
use bdk::wallet::AddressIndex as BdkAddressIndex;
|
||||||
use bdk::wallet::AddressInfo as BdkAddressInfo;
|
use bdk::wallet::AddressInfo as BdkAddressInfo;
|
||||||
use bdk::{Balance as BdkBalance, BlockTime, Error as BdkError, FeeRate, KeychainKind};
|
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
|
/// A wallet transaction
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||||
pub struct TransactionDetails {
|
pub struct TransactionDetails {
|
||||||
@ -288,6 +271,7 @@ uniffi::deps::static_assertions::assert_impl_all!(Wallet: Sync, Send);
|
|||||||
// crate.
|
// crate.
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use crate::database::DatabaseConfig;
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use assert_matches::assert_matches;
|
use assert_matches::assert_matches;
|
||||||
use bdk::bitcoin::hashes::hex::ToHex;
|
use bdk::bitcoin::hashes::hex::ToHex;
|
||||||
|
@ -10,12 +10,12 @@ use std::str::FromStr;
|
|||||||
use std::sync::{Arc, Mutex, MutexGuard};
|
use std::sync::{Arc, Mutex, MutexGuard};
|
||||||
|
|
||||||
use crate::blockchain::Blockchain;
|
use crate::blockchain::Blockchain;
|
||||||
|
use crate::database::DatabaseConfig;
|
||||||
use crate::descriptor::Descriptor;
|
use crate::descriptor::Descriptor;
|
||||||
use crate::psbt::PartiallySignedTransaction;
|
use crate::psbt::PartiallySignedTransaction;
|
||||||
use crate::{
|
use crate::{
|
||||||
AddressIndex, AddressInfo, Balance, BdkError, DatabaseConfig, LocalUtxo, NetworkLocalUtxo,
|
AddressIndex, AddressInfo, Balance, BdkError, LocalUtxo, NetworkLocalUtxo, OutPoint, Progress,
|
||||||
OutPoint, Progress, ProgressHolder, RbfValue, Script, ScriptAmount, TransactionDetails,
|
ProgressHolder, RbfValue, Script, ScriptAmount, TransactionDetails, TxBuilderResult,
|
||||||
TxBuilderResult,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user