Test a callback
This commit is contained in:
parent
47651f3681
commit
41afeafcd3
@ -91,8 +91,14 @@ interface BlockchainConfig {
|
|||||||
Esplora(EsploraConfig config);
|
Esplora(EsploraConfig config);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
callback interface BdkProgress {
|
||||||
|
void update(f32 progress, string? message);
|
||||||
|
};
|
||||||
|
|
||||||
interface OnlineWallet {
|
interface OnlineWallet {
|
||||||
[Throws=BdkError]
|
[Throws=BdkError]
|
||||||
constructor(string descriptor, Network network, DatabaseConfig database_config, BlockchainConfig blockchain_config);
|
constructor(string descriptor, Network network, DatabaseConfig database_config, BlockchainConfig blockchain_config);
|
||||||
Network get_network();
|
Network get_network();
|
||||||
|
[Throws=BdkError]
|
||||||
|
void sync(BdkProgress progress_update, u32? max_address_param);
|
||||||
};
|
};
|
||||||
|
33
src/lib.rs
33
src/lib.rs
@ -1,5 +1,6 @@
|
|||||||
use bdk::bitcoin::Network;
|
use bdk::bitcoin::Network;
|
||||||
use bdk::blockchain::any::{AnyBlockchain, AnyBlockchainConfig};
|
use bdk::blockchain::any::{AnyBlockchain, AnyBlockchainConfig};
|
||||||
|
use bdk::blockchain::Progress;
|
||||||
use bdk::blockchain::{
|
use bdk::blockchain::{
|
||||||
electrum::ElectrumBlockchainConfig, esplora::EsploraBlockchainConfig, ConfigurableBlockchain,
|
electrum::ElectrumBlockchainConfig, esplora::EsploraBlockchainConfig, ConfigurableBlockchain,
|
||||||
};
|
};
|
||||||
@ -75,6 +76,24 @@ struct OnlineWallet {
|
|||||||
wallet: Mutex<Wallet<AnyBlockchain, AnyDatabase>>,
|
wallet: Mutex<Wallet<AnyBlockchain, AnyDatabase>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait BdkProgress: Send {
|
||||||
|
fn update(&self, progress: f32, message: Option<String>);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct BdkProgressHolder {
|
||||||
|
progress_update: Mutex<Box<dyn BdkProgress>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Progress for BdkProgressHolder {
|
||||||
|
fn update(&self, progress: f32, message: Option<String>) -> Result<(), Error> {
|
||||||
|
self.progress_update
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.update(progress, message);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl OnlineWallet {
|
impl OnlineWallet {
|
||||||
fn new(
|
fn new(
|
||||||
descriptor: String,
|
descriptor: String,
|
||||||
@ -121,6 +140,20 @@ impl OnlineWallet {
|
|||||||
fn get_network(&self) -> Network {
|
fn get_network(&self) -> Network {
|
||||||
self.wallet.lock().unwrap().network()
|
self.wallet.lock().unwrap().network()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn sync(
|
||||||
|
&self,
|
||||||
|
progress_update: Box<dyn BdkProgress>,
|
||||||
|
max_address_param: Option<u32>,
|
||||||
|
) -> Result<(), BdkError> {
|
||||||
|
progress_update.update(21.0, Some("message".to_string()));
|
||||||
|
self.wallet.lock().unwrap().sync(
|
||||||
|
BdkProgressHolder {
|
||||||
|
progress_update: Mutex::new(progress_update),
|
||||||
|
},
|
||||||
|
max_address_param,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uniffi::deps::static_assertions::assert_impl_all!(OfflineWallet: Sync, Send);
|
uniffi::deps::static_assertions::assert_impl_all!(OfflineWallet: Sync, Send);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user