Skip to content

Commit 75f8b81

Browse files
committed
Update documentation
* Add `warn(missing_docs)` for `bdk_wallet` and `bdk_chain`. * Add missing documentation. * Remove `LocalChain::heights` method. * Remove old TODOs.
1 parent cff9211 commit 75f8b81

File tree

8 files changed

+54
-14
lines changed

8 files changed

+54
-14
lines changed

crates/bdk/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![doc = include_str!("../README.md")]
22
#![no_std]
3+
#![warn(missing_docs)]
4+
35
#[cfg(feature = "std")]
46
#[macro_use]
57
extern crate std;

crates/bdk/src/wallet/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ use alloc::{
2121
};
2222
pub use bdk_chain::keychain::Balance;
2323
use bdk_chain::{
24-
indexed_tx_graph::{IndexedAdditions, IndexedTxGraph},
24+
indexed_tx_graph::IndexedAdditions,
2525
keychain::{KeychainTxOutIndex, LocalChangeSet, LocalUpdate},
2626
local_chain::{self, LocalChain, UpdateNotConnectedError},
2727
tx_graph::{CanonicalTx, TxGraph},
28-
Append, BlockId, ChainPosition, ConfirmationTime, ConfirmationTimeAnchor, FullTxOut, Persist,
29-
PersistBackend,
28+
Append, BlockId, ChainPosition, ConfirmationTime, ConfirmationTimeAnchor, FullTxOut,
29+
IndexedTxGraph, Persist, PersistBackend,
3030
};
3131
use bitcoin::consensus::encode::serialize;
3232
use bitcoin::secp256k1::Secp256k1;
@@ -88,15 +88,15 @@ pub struct Wallet<D = ()> {
8888
change_signers: Arc<SignersContainer>,
8989
chain: LocalChain,
9090
indexed_graph: IndexedTxGraph<ConfirmationTimeAnchor, KeychainTxOutIndex<KeychainKind>>,
91-
persist: Persist<D, ChangeSet>, // [TODO] Use a different `ChangeSet`
91+
persist: Persist<D, ChangeSet>,
9292
network: Network,
9393
secp: SecpCtx,
9494
}
9595

9696
/// The update to a [`Wallet`] used in [`Wallet::apply_update`]. This is usually returned from blockchain data sources.
9797
pub type Update = LocalUpdate<KeychainKind, ConfirmationTimeAnchor>;
9898

99-
// /// The changeset produced internally by applying an update.
99+
/// The changeset produced internally by [`Wallet`] when mutated.
100100
pub type ChangeSet = LocalChangeSet<KeychainKind, ConfirmationTimeAnchor>;
101101

102102
/// The address index selection strategy to use to derived an address from the wallet's external
@@ -184,10 +184,15 @@ where
184184
}
185185
}
186186

187+
/// An error that may occur when inserting a transaction into [`Wallet`].
187188
#[derive(Debug)]
188189
pub enum InsertTxError {
190+
/// The error variant that occurs when the caller attempts to insert a transaction with a
191+
/// confirmation height that is greater than the internal chain tip.
189192
ConfirmationHeightCannotBeGreaterThanTip {
193+
/// The internal chain's tip height.
190194
tip_height: Option<u32>,
195+
/// The introduced transaction's confirmation height.
191196
tx_height: u32,
192197
},
193198
}

crates/chain/src/chain_data.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ impl<A> ChainPosition<A> {
2121
}
2222

2323
impl<A: Clone> ChainPosition<&A> {
24+
/// Maps a [`ChainPosition<&A>`] into a [`ChainPosition<A>`] by cloning the contents.
2425
pub fn cloned(self) -> ChainPosition<A> {
2526
match self {
2627
ChainPosition::Confirmed(a) => ChainPosition::Confirmed(a.clone()),
@@ -30,6 +31,7 @@ impl<A: Clone> ChainPosition<&A> {
3031
}
3132

3233
impl<A: Anchor> ChainPosition<A> {
34+
/// Determines the upper bound of the confirmation height.
3335
pub fn confirmation_height_upper_bound(&self) -> Option<u32> {
3436
match self {
3537
ChainPosition::Confirmed(a) => Some(a.confirmation_height_upper_bound()),
@@ -46,15 +48,27 @@ impl<A: Anchor> ChainPosition<A> {
4648
serde(crate = "serde_crate")
4749
)]
4850
pub enum ConfirmationTime {
49-
Confirmed { height: u32, time: u64 },
50-
Unconfirmed { last_seen: u64 },
51+
/// The confirmed variant.
52+
Confirmed {
53+
/// Confirmation height.
54+
height: u32,
55+
/// Confirmation time in unix seconds.
56+
time: u64,
57+
},
58+
/// The unconfirmed variant.
59+
Unconfirmed {
60+
/// The last-seen timestamp in unix seconds.
61+
last_seen: u64,
62+
},
5163
}
5264

5365
impl ConfirmationTime {
66+
/// Construct an unconfirmed variant using the given `last_seen` time in unix seconds.
5467
pub fn unconfirmed(last_seen: u64) -> Self {
5568
Self::Unconfirmed { last_seen }
5669
}
5770

71+
/// Returns whether [`ConfirmationTime`] is the confirmed variant.
5872
pub fn is_confirmed(&self) -> bool {
5973
matches!(self, Self::Confirmed { .. })
6074
}
@@ -154,8 +168,9 @@ impl Anchor for ConfirmationHeightAnchor {
154168
pub struct ConfirmationTimeAnchor {
155169
/// The anchor block.
156170
pub anchor_block: BlockId,
157-
171+
/// The confirmation height of the chain data being anchored.
158172
pub confirmation_height: u32,
173+
/// The confirmation time of the chain data being anchored.
159174
pub confirmation_time: u64,
160175
}
161176

crates/chain/src/indexed_tx_graph.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Contains the [`IndexedTxGraph`] structure and associated types.
2+
//!
3+
//! This is essentially a [`TxGraph`] combined with an indexer.
4+
15
use alloc::vec::Vec;
26
use bitcoin::{OutPoint, Transaction, TxOut};
37

crates/chain/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,23 @@
1717
//! cache or how you fetch it.
1818
//!
1919
//! [Bitcoin Dev Kit]: https://bitcoindevkit.org/
20+
2021
#![no_std]
22+
#![warn(missing_docs)]
23+
2124
pub use bitcoin;
2225
mod spk_txout_index;
2326
pub use spk_txout_index::*;
2427
mod chain_data;
2528
pub use chain_data::*;
2629
pub mod indexed_tx_graph;
30+
pub use indexed_tx_graph::IndexedTxGraph;
2731
pub mod keychain;
2832
pub mod local_chain;
2933
mod tx_data_traits;
3034
pub mod tx_graph;
3135
pub use tx_data_traits::*;
36+
pub use tx_graph::TxGraph;
3237
mod chain_oracle;
3338
pub use chain_oracle::*;
3439
mod persist;

crates/chain/src/local_chain.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
//! The [`LocalChain`] is a local implementation of [`ChainOracle`].
2+
13
use core::convert::Infallible;
24

3-
use alloc::collections::{BTreeMap, BTreeSet};
5+
use alloc::collections::BTreeMap;
46
use bitcoin::BlockHash;
57

68
use crate::{BlockId, ChainOracle};
@@ -59,6 +61,7 @@ impl From<BTreeMap<u32, BlockHash>> for LocalChain {
5961
}
6062

6163
impl LocalChain {
64+
/// Contruct a [`LocalChain`] from a list of [`BlockId`]s.
6265
pub fn from_blocks<B>(blocks: B) -> Self
6366
where
6467
B: IntoIterator<Item = BlockId>,
@@ -73,6 +76,7 @@ impl LocalChain {
7376
&self.blocks
7477
}
7578

79+
/// Get the chain tip.
7680
pub fn tip(&self) -> Option<BlockId> {
7781
self.blocks
7882
.iter()
@@ -158,17 +162,16 @@ impl LocalChain {
158162
Ok(changeset)
159163
}
160164

165+
/// Derives a [`ChangeSet`] that assumes that there are no preceding changesets.
166+
///
167+
/// The changeset returned will record additions of all blocks included in [`Self`].
161168
pub fn initial_changeset(&self) -> ChangeSet {
162169
self.blocks
163170
.iter()
164171
.map(|(&height, &hash)| (height, Some(hash)))
165172
.collect()
166173
}
167174

168-
pub fn heights(&self) -> BTreeSet<u32> {
169-
self.blocks.keys().cloned().collect()
170-
}
171-
172175
/// Insert a block of [`BlockId`] into the [`LocalChain`].
173176
///
174177
/// # Error
@@ -225,8 +228,11 @@ impl std::error::Error for UpdateNotConnectedError {}
225228
/// Represents a failure when trying to insert a checkpoint into [`LocalChain`].
226229
#[derive(Clone, Debug, PartialEq)]
227230
pub struct InsertBlockNotMatchingError {
231+
/// The checkpoints' height.
228232
pub height: u32,
233+
/// Original checkpoint's block hash.
229234
pub original_hash: BlockHash,
235+
/// Update checkpoint's block hash.
230236
pub update_hash: BlockHash,
231237
}
232238

crates/chain/src/tx_graph.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,9 +983,13 @@ impl<A: Anchor> TxGraph<A> {
983983
)]
984984
#[must_use]
985985
pub struct Additions<A = ()> {
986+
/// Added transactions.
986987
pub txs: BTreeSet<Transaction>,
988+
/// Added txouts.
987989
pub txouts: BTreeMap<OutPoint, TxOut>,
990+
/// Added anchors.
988991
pub anchors: BTreeSet<(A, Txid)>,
992+
/// Added last-seen unix timestamps of transactions.
989993
pub last_seen: BTreeMap<Txid, u64>,
990994
}
991995

crates/electrum/src/electrum_ext.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ impl ElectrumExt<ConfirmationHeightAnchor> for Client {
236236

237237
populate_with_txids(self, anchor_block, &mut update, &mut txids.iter().cloned())?;
238238

239-
// [TODO] cache transactions to reduce bandwidth
240239
let _txs = populate_with_outpoints(
241240
self,
242241
anchor_block,

0 commit comments

Comments
 (0)