Skip to content

Commit

Permalink
doc: futher library documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rustaceanrob committed Sep 11, 2024
1 parent ff57a06 commit 62cabfb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const PEEK_INDEX: u32 = 20;
const RECOMMENDED_PEERS: u8 = 2;

#[derive(Debug)]
/// Construct a light client from higher level components.
/// Construct a light client from a [`Wallet`] reference.
pub struct LightClientBuilder<'a> {
wallet: &'a Wallet,
peers: Option<Vec<TrustedPeer>>,
Expand All @@ -73,7 +73,7 @@ pub struct LightClientBuilder<'a> {
}

impl<'a> LightClientBuilder<'a> {
/// Construct a new node builder
/// Construct a new node builder.
pub fn new(wallet: &'a Wallet) -> Self {
Self {
wallet,
Expand Down Expand Up @@ -163,7 +163,7 @@ impl<'a> LightClientBuilder<'a> {
cp
}

/// Build a light client node and a client to interact with the node
/// Build a light client node and a client to interact with the node.
pub fn build(self) -> Result<(Node, Client<KeychainKind>), Error> {
let network = self.wallet.network();
let mut node_builder = NodeBuilder::new(network);
Expand Down
14 changes: 10 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ use bdk_chain::{
IndexedTxGraph,
};
use bdk_chain::{ConfirmationBlockTime, TxUpdate};
use kyoto::{IndexedBlock, TxBroadcast};
use kyoto::{IndexedBlock, SyncUpdate, TxBroadcast};

use crate::logger::NodeMessageHandler;

Expand All @@ -147,7 +147,7 @@ pub mod logger;
pub use bdk_chain::local_chain::MissingGenesisError;
pub use kyoto::{
ClientError, DatabaseError, HeaderCheckpoint, Node, NodeBuilder, NodeMessage, NodeState,
Receiver, ScriptBuf, SyncUpdate, Transaction, TrustedPeer, TxBroadcastPolicy, Txid, Warning,
Receiver, ScriptBuf, Transaction, TrustedPeer, TxBroadcastPolicy, Txid, Warning,
MAINNET_HEADER_CP, SIGNET_HEADER_CP,
};

Expand All @@ -168,7 +168,7 @@ impl<K> Client<K>
where
K: fmt::Debug + Clone + Ord,
{
/// Build a light client from a [`KeychainTxOutIndex`] and checkpoint
/// Build a light client from a [`KeychainTxOutIndex`] and [`CheckPoint`].
pub fn from_index(
cp: CheckPoint,
index: &KeychainTxOutIndex<K>,
Expand All @@ -185,6 +185,11 @@ where

/// Return the most recent update from the node once it has synced to the network's tip.
/// This may take a significant portion of time during wallet recoveries or dormant wallets.
/// Note that you may call this method in a loop as long as the [`Node`] is running.
///
/// A reference to a [`NodeMessageHandler`] 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, logger: &dyn NodeMessageHandler) -> Option<FullScanResult<K>> {
let mut chain_changeset = BTreeMap::new();
while let Ok(message) = self.receiver.recv().await {
Expand Down Expand Up @@ -274,7 +279,8 @@ where
.map_err(Error::from)
}

/// Add more scripts to the node. Could this just check a SPK index?
/// Add more scripts to the node. For example, a user may reveal a Bitcoin address to receive a payment,
/// so this script should be added to the [`Node`].
pub async fn add_script(&self, script: impl Into<ScriptBuf>) -> Result<(), Error> {
self.sender.add_script(script).await.map_err(Error::from)
}
Expand Down

0 comments on commit 62cabfb

Please sign in to comment.