|
159 | 159 |
|
160 | 160 | #![warn(missing_docs)]
|
161 | 161 | use core::fmt;
|
| 162 | +#[cfg(feature = "wallet")] |
| 163 | +use core::{future::Future, pin::Pin}; |
162 | 164 | use std::collections::BTreeMap;
|
163 | 165 |
|
| 166 | +#[cfg(feature = "wallet")] |
| 167 | +type FutureResult<'a, T, E> = Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'a>>; |
| 168 | + |
164 | 169 | use bdk_chain::{
|
165 | 170 | keychain_txout::KeychainTxOutIndex,
|
166 | 171 | local_chain::{self, CheckPoint, LocalChain},
|
@@ -487,6 +492,37 @@ pub enum LogLevel {
|
487 | 492 | Warning,
|
488 | 493 | }
|
489 | 494 |
|
| 495 | +/// Extend the [`EventSender`] functionality to work conviently with a [`Wallet`](bdk_wallet). |
| 496 | +#[cfg(feature = "wallet")] |
| 497 | +pub trait EventSenderExt { |
| 498 | + /// Add all revealed scripts to the node to monitor. |
| 499 | + fn add_revealed_scripts<'a>( |
| 500 | + &'a self, |
| 501 | + wallet: &'a bdk_wallet::Wallet, |
| 502 | + ) -> FutureResult<(), kyoto::ClientError>; |
| 503 | +} |
| 504 | + |
| 505 | +impl EventSenderExt for EventSender { |
| 506 | + fn add_revealed_scripts<'a>( |
| 507 | + &'a self, |
| 508 | + wallet: &'a bdk_wallet::Wallet, |
| 509 | + ) -> FutureResult<(), kyoto::ClientError> { |
| 510 | + async fn _add_revealed( |
| 511 | + sender: &EventSender, |
| 512 | + wallet: &bdk_wallet::Wallet, |
| 513 | + ) -> Result<(), kyoto::ClientError> { |
| 514 | + for keychain in [KeychainKind::External, KeychainKind::Internal] { |
| 515 | + let scripts = wallet.spk_index().revealed_keychain_spks(keychain); |
| 516 | + for (_, script) in scripts { |
| 517 | + sender.add_script(script).await?; |
| 518 | + } |
| 519 | + } |
| 520 | + Ok(()) |
| 521 | + } |
| 522 | + Box::pin(_add_revealed(&self, wallet)) |
| 523 | + } |
| 524 | +} |
| 525 | + |
490 | 526 | trait StringExt {
|
491 | 527 | fn into_string(self) -> String;
|
492 | 528 | }
|
|
0 commit comments