Allow using configs for database
This commit is contained in:
parent
598d08b3bc
commit
6d7939c88f
13
src/bdk.udl
13
src/bdk.udl
@ -44,8 +44,19 @@ enum BdkError {
|
||||
"Sled",
|
||||
};
|
||||
|
||||
dictionary SledDbConfiguration {
|
||||
string path;
|
||||
string tree_name;
|
||||
};
|
||||
|
||||
[Enum]
|
||||
interface DatabaseConfig {
|
||||
Memory(string junk);
|
||||
Sled(SledDbConfiguration configuration);
|
||||
};
|
||||
|
||||
interface OfflineWallet {
|
||||
[Throws=BdkError]
|
||||
constructor(string descriptor);
|
||||
constructor(string descriptor, DatabaseConfig database_config);
|
||||
string get_new_address();
|
||||
};
|
||||
|
19
src/lib.rs
19
src/lib.rs
@ -1,5 +1,6 @@
|
||||
use bdk::bitcoin::Network;
|
||||
use bdk::database::MemoryDatabase;
|
||||
use bdk::database::any::{AnyDatabase, SledDbConfiguration};
|
||||
use bdk::database::{AnyDatabaseConfig, ConfigurableDatabase};
|
||||
use bdk::wallet::AddressIndex;
|
||||
use bdk::Error;
|
||||
use bdk::Wallet;
|
||||
@ -8,14 +9,24 @@ use std::sync::Mutex;
|
||||
|
||||
type BdkError = Error;
|
||||
|
||||
pub enum DatabaseConfig {
|
||||
Memory { junk: String },
|
||||
Sled { configuration: SledDbConfiguration },
|
||||
}
|
||||
|
||||
uniffi_macros::include_scaffolding!("bdk");
|
||||
|
||||
struct OfflineWallet {
|
||||
wallet: Mutex<Wallet<(), MemoryDatabase>>,
|
||||
wallet: Mutex<Wallet<(), AnyDatabase>>,
|
||||
}
|
||||
|
||||
impl OfflineWallet {
|
||||
fn new(descriptor: String) -> Result<Self, BdkError> {
|
||||
let database = MemoryDatabase::default();
|
||||
fn new(descriptor: String, database_config: DatabaseConfig) -> Result<Self, BdkError> {
|
||||
let any_database_config = match database_config {
|
||||
DatabaseConfig::Memory { .. } => AnyDatabaseConfig::Memory(()),
|
||||
DatabaseConfig::Sled { configuration } => AnyDatabaseConfig::Sled(configuration),
|
||||
};
|
||||
let database = AnyDatabase::from_config(&any_database_config)?;
|
||||
let wallet = Mutex::new(Wallet::new_offline(
|
||||
&descriptor,
|
||||
None,
|
||||
|
Loading…
x
Reference in New Issue
Block a user