Skip to content

Commit e125014

Browse files
evanlinjinValuedMammal
authored andcommitted
feat(examples): Change example_wallet_rpc to detect evictions.
1 parent 12b00e0 commit e125014

File tree

1 file changed

+17
-10
lines changed
  • examples/example_wallet_rpc/src

1 file changed

+17
-10
lines changed

examples/example_wallet_rpc/src/main.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ use bdk_bitcoind_rpc::{
33
Emitter, MempoolEvent,
44
};
55
use bdk_wallet::{
6-
bitcoin::{Block, Network, Txid},
6+
bitcoin::{Block, Network},
77
file_store::Store,
88
KeychainKind, Wallet,
99
};
1010
use clap::{self, Parser};
11-
use std::{path::PathBuf, sync::mpsc::sync_channel, thread::spawn, time::Instant};
11+
use std::{
12+
path::PathBuf,
13+
sync::{mpsc::sync_channel, Arc},
14+
thread::spawn,
15+
time::Instant,
16+
};
1217

1318
const DB_MAGIC: &str = "bdk-rpc-wallet-example";
1419

@@ -79,7 +84,7 @@ enum Emission {
7984
fn main() -> anyhow::Result<()> {
8085
let args = Args::parse();
8186

82-
let rpc_client = args.client()?;
87+
let rpc_client = Arc::new(args.client()?);
8388
println!(
8489
"Connected to Bitcoin Core RPC at {:?}",
8590
rpc_client.get_blockchain_info().unwrap()
@@ -129,14 +134,15 @@ fn main() -> anyhow::Result<()> {
129134
.expect("failed to send sigterm")
130135
});
131136

132-
let emitter_tip = wallet_tip.clone();
137+
let mut emitter = Emitter::new(
138+
rpc_client,
139+
wallet_tip,
140+
args.start_height,
141+
wallet
142+
.transactions()
143+
.filter(|tx| tx.chain_position.is_unconfirmed()),
144+
);
133145
spawn(move || -> Result<(), anyhow::Error> {
134-
let mut emitter = Emitter::new(
135-
&rpc_client,
136-
emitter_tip,
137-
args.start_height,
138-
core::iter::empty::<Txid>(),
139-
);
140146
while let Some(emission) = emitter.next_block()? {
141147
sender.send(Emission::Block(emission))?;
142148
}
@@ -167,6 +173,7 @@ fn main() -> anyhow::Result<()> {
167173
}
168174
Emission::Mempool(event) => {
169175
let start_apply_mempool = Instant::now();
176+
wallet.apply_evicted_txs(event.evicted_ats());
170177
wallet.apply_unconfirmed_txs(event.new_txs);
171178
wallet.persist(&mut db)?;
172179
println!(

0 commit comments

Comments
 (0)