Skip to content

Commit d7e0362

Browse files
committed
docs(rpc): add Emitter examples and remove example_bitcoind_rpc_polling
1 parent fb05873 commit d7e0362

7 files changed

Lines changed: 64 additions & 493 deletions

File tree

.github/workflows/cont_integration.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ jobs:
149149
matrix:
150150
example-dir:
151151
- example_cli
152-
- example_bitcoind_rpc_polling
153152
- example_electrum
154153
- example_esplora
155154
steps:

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ members = [
1111
"examples/example_cli",
1212
"examples/example_electrum",
1313
"examples/example_esplora",
14-
"examples/example_bitcoind_rpc_polling",
1514
]
1615

1716
[workspace.package]

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ Fully working examples of how to use these components are in `/examples`:
4646
- [`example_cli`](examples/example_cli): Library used by the `example_*` crates. Provides utilities for syncing, showing the balance, generating addresses and creating transactions without using the bdk_wallet `Wallet`.
4747
- [`example_electrum`](examples/example_electrum): A command line Bitcoin wallet application built on top of `example_cli` and the `electrum` crate. It shows the power of the bdk tools (`chain` + `file_store` + `electrum`), without depending on the main `bdk_wallet` library.
4848
- [`example_esplora`](examples/example_esplora): A command line Bitcoin wallet application built on top of `example_cli` and the `esplora` crate. It shows the power of the bdk tools (`chain` + `file_store` + `esplora`), without depending on the main `bdk_wallet` library.
49-
- [`example_bitcoind_rpc_polling`](examples/example_bitcoind_rpc_polling): A command line Bitcoin wallet application built on top of `example_cli` and the `bitcoind_rpc` crate. It shows the power of the bdk tools (`chain` + `file_store` + `bitcoind_rpc`), without depending on the main `bdk_wallet` library.
5049

5150
[`rust-miniscript`]: https://github.com/rust-bitcoin/rust-miniscript
5251
[`rust-bitcoin`]: https://github.com/rust-bitcoin/rust-bitcoin

crates/bitcoind_rpc/src/lib.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,38 @@ where
107107
/// are only reported once the emitter’s checkpoint matches the RPC’s best block in both height
108108
/// and hash. Until `next_block()` advances the checkpoint to tip, `mempool()` will always
109109
/// return an empty `evicted` set.
110+
///
111+
/// # Example
112+
///
113+
/// ```no_run
114+
/// use bdk_bitcoind_rpc::{
115+
/// bitcoincore_rpc::{Auth, Client},
116+
/// Emitter, NO_EXPECTED_MEMPOOL_TXS,
117+
/// };
118+
/// use bdk_core::CheckPoint;
119+
/// use bitcoin::{constants::genesis_block, Network};
120+
///
121+
/// let client = Client::new("127.0.0.1:8332", Auth::None)?;
122+
/// let genesis_hash = genesis_block(Network::Bitcoin).block_hash();
123+
/// let mut emitter = Emitter::new(
124+
/// &client,
125+
/// CheckPoint::new(0, genesis_hash),
126+
/// 0,
127+
/// NO_EXPECTED_MEMPOOL_TXS,
128+
/// );
129+
///
130+
/// // Drain blocks first so evictions can be reported once the checkpoint reaches tip.
131+
/// while emitter.next_block()?.is_some() {}
132+
///
133+
/// let event = emitter.mempool()?;
134+
/// for (tx, seen_at) in event.update {
135+
/// // index unconfirmed `tx` (first seen at `seen_at`)
136+
/// }
137+
/// for (txid, evicted_at) in event.evicted {
138+
/// // mark `txid` as evicted from the mempool at `evicted_at`
139+
/// }
140+
/// # Ok::<_, bdk_bitcoind_rpc::bitcoincore_rpc::Error>(())
141+
/// ```
110142
#[cfg(feature = "std")]
111143
pub fn mempool(&mut self) -> Result<MempoolEvent, bitcoincore_rpc::Error> {
112144
let sync_time = std::time::UNIX_EPOCH
@@ -199,6 +231,38 @@ where
199231
}
200232

201233
/// Emit the next block height and block (if any).
234+
///
235+
/// Call this repeatedly until it returns `Ok(None)`, which means the chain tip has been
236+
/// reached. Each [`BlockEvent`] carries the block alongside the [`CheckPoint`] it connects to,
237+
/// so it can be applied to BDK structures that require block connectivity.
238+
///
239+
/// # Example
240+
///
241+
/// ```no_run
242+
/// use bdk_bitcoind_rpc::{
243+
/// bitcoincore_rpc::{Auth, Client},
244+
/// Emitter, NO_EXPECTED_MEMPOOL_TXS,
245+
/// };
246+
/// use bdk_core::CheckPoint;
247+
/// use bitcoin::{constants::genesis_block, Network};
248+
///
249+
/// let client = Client::new("127.0.0.1:8332", Auth::None)?;
250+
/// let genesis_hash = genesis_block(Network::Bitcoin).block_hash();
251+
/// let start_height = 0;
252+
/// let mut emitter = Emitter::new(
253+
/// &client,
254+
/// CheckPoint::new(0, genesis_hash),
255+
/// start_height,
256+
/// NO_EXPECTED_MEMPOOL_TXS,
257+
/// );
258+
///
259+
/// while let Some(event) = emitter.next_block()? {
260+
/// let height = event.block_height();
261+
/// let connected_to = event.connected_to();
262+
/// // apply `event.block` to your chain and tx graph here
263+
/// }
264+
/// # Ok::<_, bdk_bitcoind_rpc::bitcoincore_rpc::Error>(())
265+
/// ```
202266
pub fn next_block(&mut self) -> Result<Option<BlockEvent<Block>>, bitcoincore_rpc::Error> {
203267
if let Some((checkpoint, block)) = poll(self, move |hash, client| client.get_block(hash))? {
204268
// Stop tracking unconfirmed transactions that have been confirmed in this block.

examples/example_bitcoind_rpc_polling/Cargo.toml

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/example_bitcoind_rpc_polling/README.md

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)