Skip to content

Commit

Permalink
Merge pull request #96 from rustaceanrob/return-type-1-20
Browse files Browse the repository at this point in the history
Return `Update` from `UpdateSubscriber`
  • Loading branch information
rustaceanrob authored Jan 20, 2025
2 parents dff01cd + e52c6fb commit 8f550e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ use std::collections::HashSet;
type FutureResult<'a, T, E> = Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'a>>;

pub use bdk_wallet::chain::local_chain::MissingGenesisError;
pub use bdk_wallet::Update;

use bdk_wallet::chain::{
keychain_txout::KeychainTxOutIndex,
local_chain::{self, CheckPoint, LocalChain},
spk_client::FullScanResponse,
IndexedTxGraph,
};
use bdk_wallet::chain::{ConfirmationBlockTime, TxUpdate};
Expand Down Expand Up @@ -120,7 +120,7 @@ impl UpdateSubscriber {
/// A reference to a [`NodeEventHandler`] is required, which handles events emitted from a
/// running node. Production applications should define how the application handles
/// these events and displays them to end users.
pub async fn update(&mut self) -> Option<FullScanResponse<KeychainKind>> {
pub async fn update(&mut self) -> Option<Update> {
let mut chain_changeset = BTreeMap::new();
while let Some(message) = self.receiver.recv().await {
match message {
Expand Down Expand Up @@ -161,15 +161,15 @@ impl UpdateSubscriber {

// When the client is believed to have synced to the chain tip of most work,
// we can return a wallet update.
fn get_scan_response(&mut self) -> FullScanResponse<KeychainKind> {
fn get_scan_response(&mut self) -> Update {
let tx_update = TxUpdate::from(self.graph.graph().clone());
let graph = core::mem::take(&mut self.graph);
let last_active_indices = graph.index.last_used_indices();
self.graph = IndexedTxGraph::new(graph.index);
FullScanResponse {
Update {
tx_update,
last_active_indices,
chain_update: Some(self.chain.tip()),
chain: Some(self.chain.tip()),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use bdk_testenv::bitcoincore_rpc::RpcApi;
use bdk_testenv::bitcoind;
use bdk_testenv::TestEnv;
use bdk_wallet::bitcoin::{Amount, Network};
use bdk_wallet::chain::spk_client::FullScanResponse;
use bdk_wallet::CreateParams;
use bdk_wallet::KeychainKind;
use bdk_wallet::Update;

const EXTERNAL_DESCRIPTOR: &str = "tr([7d94197e/86'/1'/0']tpubDCyQVJj8KzjiQsFjmb3KwECVXPvMwvAxxZGCP9XmWSopmjW3bCV3wD7TgxrUhiGSueDS1MU5X1Vb1YjYcp8jitXc5fXfdC1z68hDDEyKRNr/0/*)";
const INTERNAL_DESCRIPTOR: &str = "tr([7d94197e/86'/1'/0']tpubDCyQVJj8KzjiQsFjmb3KwECVXPvMwvAxxZGCP9XmWSopmjW3bCV3wD7TgxrUhiGSueDS1MU5X1Vb1YjYcp8jitXc5fXfdC1z68hDDEyKRNr/1/*)";
Expand Down Expand Up @@ -98,9 +98,9 @@ async fn update_returns_blockchain_data() -> anyhow::Result<()> {
.update()
.await
.expect("should have update");
let FullScanResponse {
let Update {
tx_update,
chain_update,
chain,
last_active_indices,
} = res;
// graph tx and anchor
Expand All @@ -112,7 +112,7 @@ async fn update_returns_blockchain_data() -> anyhow::Result<()> {
let txout = tx.output.iter().find(|txout| txout.value == amt).unwrap();
assert_eq!(txout.script_pubkey, addr.script_pubkey());
// chain
let update_cp = chain_update.unwrap();
let update_cp = chain.unwrap();
assert_eq!(update_cp.height(), 102);
// keychain
assert_eq!(
Expand Down

0 comments on commit 8f550e4

Please sign in to comment.