Add Network enum as wallet constructor param
This commit is contained in:
parent
6d7939c88f
commit
31710ac77b
@ -44,6 +44,13 @@ enum BdkError {
|
|||||||
"Sled",
|
"Sled",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum Network {
|
||||||
|
"Bitcoin",
|
||||||
|
"Testnet",
|
||||||
|
"Signet",
|
||||||
|
"Regtest",
|
||||||
|
};
|
||||||
|
|
||||||
dictionary SledDbConfiguration {
|
dictionary SledDbConfiguration {
|
||||||
string path;
|
string path;
|
||||||
string tree_name;
|
string tree_name;
|
||||||
@ -57,6 +64,6 @@ interface DatabaseConfig {
|
|||||||
|
|
||||||
interface OfflineWallet {
|
interface OfflineWallet {
|
||||||
[Throws=BdkError]
|
[Throws=BdkError]
|
||||||
constructor(string descriptor, DatabaseConfig database_config);
|
constructor(Network network, string descriptor, DatabaseConfig database_config);
|
||||||
string get_new_address();
|
string get_new_address();
|
||||||
};
|
};
|
||||||
|
17
src/lib.rs
17
src/lib.rs
@ -7,6 +7,8 @@ use bdk::Wallet;
|
|||||||
|
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
|
uniffi_macros::include_scaffolding!("bdk");
|
||||||
|
|
||||||
type BdkError = Error;
|
type BdkError = Error;
|
||||||
|
|
||||||
pub enum DatabaseConfig {
|
pub enum DatabaseConfig {
|
||||||
@ -14,25 +16,22 @@ pub enum DatabaseConfig {
|
|||||||
Sled { configuration: SledDbConfiguration },
|
Sled { configuration: SledDbConfiguration },
|
||||||
}
|
}
|
||||||
|
|
||||||
uniffi_macros::include_scaffolding!("bdk");
|
|
||||||
|
|
||||||
struct OfflineWallet {
|
struct OfflineWallet {
|
||||||
wallet: Mutex<Wallet<(), AnyDatabase>>,
|
wallet: Mutex<Wallet<(), AnyDatabase>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OfflineWallet {
|
impl OfflineWallet {
|
||||||
fn new(descriptor: String, database_config: DatabaseConfig) -> Result<Self, BdkError> {
|
fn new(
|
||||||
|
network: Network,
|
||||||
|
descriptor: String,
|
||||||
|
database_config: DatabaseConfig,
|
||||||
|
) -> Result<Self, BdkError> {
|
||||||
let any_database_config = match database_config {
|
let any_database_config = match database_config {
|
||||||
DatabaseConfig::Memory { .. } => AnyDatabaseConfig::Memory(()),
|
DatabaseConfig::Memory { .. } => AnyDatabaseConfig::Memory(()),
|
||||||
DatabaseConfig::Sled { configuration } => AnyDatabaseConfig::Sled(configuration),
|
DatabaseConfig::Sled { configuration } => AnyDatabaseConfig::Sled(configuration),
|
||||||
};
|
};
|
||||||
let database = AnyDatabase::from_config(&any_database_config)?;
|
let database = AnyDatabase::from_config(&any_database_config)?;
|
||||||
let wallet = Mutex::new(Wallet::new_offline(
|
let wallet = Mutex::new(Wallet::new_offline(&descriptor, None, network, database)?);
|
||||||
&descriptor,
|
|
||||||
None,
|
|
||||||
Network::Regtest,
|
|
||||||
database,
|
|
||||||
)?);
|
|
||||||
Ok(OfflineWallet { wallet })
|
Ok(OfflineWallet { wallet })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user