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",
|
"Sled",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dictionary SledDbConfiguration {
|
||||||
|
string path;
|
||||||
|
string tree_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
[Enum]
|
||||||
|
interface DatabaseConfig {
|
||||||
|
Memory(string junk);
|
||||||
|
Sled(SledDbConfiguration configuration);
|
||||||
|
};
|
||||||
|
|
||||||
interface OfflineWallet {
|
interface OfflineWallet {
|
||||||
[Throws=BdkError]
|
[Throws=BdkError]
|
||||||
constructor(string descriptor);
|
constructor(string descriptor, DatabaseConfig database_config);
|
||||||
string get_new_address();
|
string get_new_address();
|
||||||
};
|
};
|
||||||
|
19
src/lib.rs
19
src/lib.rs
@ -1,5 +1,6 @@
|
|||||||
use bdk::bitcoin::Network;
|
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::wallet::AddressIndex;
|
||||||
use bdk::Error;
|
use bdk::Error;
|
||||||
use bdk::Wallet;
|
use bdk::Wallet;
|
||||||
@ -8,14 +9,24 @@ use std::sync::Mutex;
|
|||||||
|
|
||||||
type BdkError = Error;
|
type BdkError = Error;
|
||||||
|
|
||||||
|
pub enum DatabaseConfig {
|
||||||
|
Memory { junk: String },
|
||||||
|
Sled { configuration: SledDbConfiguration },
|
||||||
|
}
|
||||||
|
|
||||||
uniffi_macros::include_scaffolding!("bdk");
|
uniffi_macros::include_scaffolding!("bdk");
|
||||||
|
|
||||||
struct OfflineWallet {
|
struct OfflineWallet {
|
||||||
wallet: Mutex<Wallet<(), MemoryDatabase>>,
|
wallet: Mutex<Wallet<(), AnyDatabase>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OfflineWallet {
|
impl OfflineWallet {
|
||||||
fn new(descriptor: String) -> Result<Self, BdkError> {
|
fn new(descriptor: String, database_config: DatabaseConfig) -> Result<Self, BdkError> {
|
||||||
let database = MemoryDatabase::default();
|
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(
|
let wallet = Mutex::new(Wallet::new_offline(
|
||||||
&descriptor,
|
&descriptor,
|
||||||
None,
|
None,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user