@@ -655,6 +655,24 @@ impl<A: Anchor> TxGraph<A> {
655655 /// * A smaller witness has precedence over a larger witness.
656656 /// * If the witness sizes are the same, we prioritize the two witnesses with lexicographical
657657 /// order.
658+ ///
659+ /// # Example
660+ ///
661+ /// ```
662+ /// use bdk_chain::{tx_graph::TxGraph, BlockId};
663+ /// use bitcoin::Transaction;
664+ ///
665+ /// let mut graph = TxGraph::<BlockId>::default();
666+ /// let tx = Transaction {
667+ /// version: bitcoin::transaction::Version::ONE,
668+ /// lock_time: bitcoin::locktime::absolute::LockTime::ZERO,
669+ /// input: vec![],
670+ /// output: vec![],
671+ /// };
672+ ///
673+ /// let changeset = graph.insert_tx(tx.clone());
674+ /// assert_eq!(changeset.txs.len(), 1);
675+ /// ```
658676 pub fn insert_tx < T : Into < Arc < Transaction > > > ( & mut self , tx : T ) -> ChangeSet < A > {
659677 // This returns `Some` only if the merged tx is different to the `original_tx`.
660678 fn _merge_tx_witnesses (
@@ -1247,6 +1265,37 @@ impl<A: Anchor> TxGraph<A> {
12471265 ///
12481266 /// This is the infallible version of [`try_filter_chain_unspents`].
12491267 ///
1268+ /// # Example
1269+ ///
1270+ /// ```
1271+ /// use bdk_chain::local_chain::LocalChain;
1272+ /// use bdk_chain::{tx_graph::TxGraph, BlockId, CanonicalizationParams};
1273+ /// use bitcoin::{Amount, OutPoint, TxOut};
1274+ /// use std::sync::Arc;
1275+ ///
1276+ /// let mut graph = TxGraph::<BlockId>::default();
1277+ /// let chain = LocalChain::from_blocks(
1278+ /// [(
1279+ /// 0,
1280+ /// bitcoin::constants::genesis_block(bitcoin::Network::Bitcoin).block_hash(),
1281+ /// )]
1282+ /// .into_iter()
1283+ /// .collect(),
1284+ /// )
1285+ /// .unwrap();
1286+ ///
1287+ /// // Get unspent outputs
1288+ /// let outpoints = vec![(0, OutPoint::default())];
1289+ /// let utxos: Vec<_> = graph
1290+ /// .filter_chain_unspents(
1291+ /// &chain,
1292+ /// chain.tip().block_id(),
1293+ /// CanonicalizationParams::default(),
1294+ /// outpoints,
1295+ /// )
1296+ /// .collect();
1297+ /// ```
1298+ ///
12501299 /// [`try_filter_chain_unspents`]: Self::try_filter_chain_unspents
12511300 pub fn filter_chain_unspents < ' a , C : ChainOracle < Error = Infallible > + ' a , OI : Clone + ' a > (
12521301 & ' a self ,
@@ -1315,6 +1364,34 @@ impl<A: Anchor> TxGraph<A> {
13151364 ///
13161365 /// This is the infallible version of [`try_balance`].
13171366 ///
1367+ /// # Example
1368+ ///
1369+ /// ```
1370+ /// use bdk_chain::local_chain::LocalChain;
1371+ /// use bdk_chain::{tx_graph::TxGraph, Balance, BlockId, CanonicalizationParams};
1372+ /// use bitcoin::OutPoint;
1373+ ///
1374+ /// let graph = TxGraph::<BlockId>::default();
1375+ /// let chain = LocalChain::from_blocks(
1376+ /// [(
1377+ /// 0,
1378+ /// bitcoin::constants::genesis_block(bitcoin::Network::Bitcoin).block_hash(),
1379+ /// )]
1380+ /// .into_iter()
1381+ /// .collect(),
1382+ /// )
1383+ /// .unwrap();
1384+ ///
1385+ /// let outpoints = vec![(0, OutPoint::default())];
1386+ /// let balance = graph.balance(
1387+ /// &chain,
1388+ /// chain.tip().block_id(),
1389+ /// CanonicalizationParams::default(),
1390+ /// outpoints,
1391+ /// |_, _| true,
1392+ /// );
1393+ /// ```
1394+ ///
13181395 /// [`try_balance`]: Self::try_balance
13191396 pub fn balance < C : ChainOracle < Error = Infallible > , OI : Clone > (
13201397 & self ,
0 commit comments