Add Network enum as wallet constructor param
This commit is contained in:
parent
6d7939c88f
commit
31710ac77b
@ -41,4 +41,4 @@ See the [UniFFI User Guide](https://mozilla.github.io/uniffi-rs/)
|
||||
|
||||
1. Use `build.sh` script (TODO do it all in build.rs instead)
|
||||
2. Create tests in `bindings/bdk-kotlin` and/or `bindings/bdk-swift`
|
||||
3. Use `test.sh` to run all bindings tests
|
||||
3. Use `test.sh` to run all bindings tests
|
||||
|
@ -44,6 +44,13 @@ enum BdkError {
|
||||
"Sled",
|
||||
};
|
||||
|
||||
enum Network {
|
||||
"Bitcoin",
|
||||
"Testnet",
|
||||
"Signet",
|
||||
"Regtest",
|
||||
};
|
||||
|
||||
dictionary SledDbConfiguration {
|
||||
string path;
|
||||
string tree_name;
|
||||
@ -57,6 +64,6 @@ interface DatabaseConfig {
|
||||
|
||||
interface OfflineWallet {
|
||||
[Throws=BdkError]
|
||||
constructor(string descriptor, DatabaseConfig database_config);
|
||||
constructor(Network network, string descriptor, DatabaseConfig database_config);
|
||||
string get_new_address();
|
||||
};
|
||||
|
17
src/lib.rs
17
src/lib.rs
@ -7,6 +7,8 @@ use bdk::Wallet;
|
||||
|
||||
use std::sync::Mutex;
|
||||
|
||||
uniffi_macros::include_scaffolding!("bdk");
|
||||
|
||||
type BdkError = Error;
|
||||
|
||||
pub enum DatabaseConfig {
|
||||
@ -14,25 +16,22 @@ pub enum DatabaseConfig {
|
||||
Sled { configuration: SledDbConfiguration },
|
||||
}
|
||||
|
||||
uniffi_macros::include_scaffolding!("bdk");
|
||||
|
||||
struct OfflineWallet {
|
||||
wallet: Mutex<Wallet<(), AnyDatabase>>,
|
||||
}
|
||||
|
||||
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 {
|
||||
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,
|
||||
Network::Regtest,
|
||||
database,
|
||||
)?);
|
||||
let wallet = Mutex::new(Wallet::new_offline(&descriptor, None, network, database)?);
|
||||
Ok(OfflineWallet { wallet })
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user