Skip to content

Commit 4493cbd

Browse files
committed
docs: Improve documentation
1 parent 46db8a2 commit 4493cbd

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

wallet/src/psbt/params.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ impl Default for PsbtParams {
5858

5959
impl PsbtParams {
6060
/// Add UTXOs by outpoint to fund the transaction.
61+
///
62+
/// A single outpoint may appear at most once in the list of UTXOs to spend. The caller is
63+
/// responsible for ensuring that elements of `outpoints` correspond to outputs of previous
64+
/// transactions and are currently unspent.
6165
pub fn add_utxos(&mut self, outpoints: &[OutPoint]) -> &mut Self {
6266
self.utxos.extend(outpoints);
6367
self
@@ -145,6 +149,8 @@ impl PsbtParams {
145149
}
146150
}
147151

152+
// TODO: Bring back `TxOrdering`
153+
148154
/// `ReplaceParams` provides a thin wrapper around [`PsbtParams`] and is intended for
149155
/// crafting Replace-By-Fee transactions (RBF).
150156
#[derive(Debug, Default)]
@@ -165,8 +171,8 @@ impl ReplaceParams {
165171
.replace(txs)
166172
}
167173

168-
/// Replace spends of the provided `txs`. This will internally set the inner
169-
/// params UTXOs to be spent.
174+
/// Replace spends of the provided `txs`. This will internally set the internal list
175+
/// of UTXOs to be spent.
170176
pub fn replace(self, txs: &[Arc<Transaction>]) -> Self {
171177
let txs: Vec<Arc<Transaction>> = txs.to_vec();
172178
let mut txids: HashSet<Txid> = txs.iter().map(|tx| tx.compute_txid()).collect();
@@ -277,9 +283,9 @@ mod test {
277283

278284
#[test]
279285
fn test_sanitize_rbf_set() {
280-
// To replace: { [A, B], [C] } (where B spends from A)
281-
// We can't replace the inputs of B, since we're already replacing A
282-
// therefore the inputs should only include the spends of [A, C].
286+
// To replace the set { [A, B], [C] }, where B is a descendant of A:
287+
// We shouldn't try to replace the inputs of B, because replacing A will render A's outputs
288+
// unspendable. Therefore the RBF inputs should only contain the inputs of A and C.
283289

284290
// A is an ancestor
285291
let tx_a = Transaction {

wallet/src/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ pub fn insert_checkpoint(wallet: &mut Wallet, block: BlockId) {
317317
.unwrap();
318318
}
319319

320-
/// Inserts a transaction with anchor (no last seen). This is useful for adding
320+
/// Inserts a transaction to be anchored by `block_id` (no last seen). This can be used to add
321321
/// a coinbase tx to the wallet for testing.
322322
///
323323
/// This will also insert the anchor `block_id`. See [`insert_anchor`] for more.

wallet/src/wallet/mod.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,13 @@ impl Wallet {
12101210
self.transactions_with_params(CanonicalizationParams::default())
12111211
}
12121212

1213-
/// Transactions with params.
1213+
/// Iterate over relevant and canonical transactions in this wallet.
1214+
///
1215+
/// - `params`: [`CanonicalizationParams`], modifies the wallet's internal logic for determining
1216+
/// which transaction is canonical. This can be used to resolve conflicts, or to assert that a
1217+
/// particular transaction should be treated as canonical.
1218+
///
1219+
/// See [`Wallet::transactions`] for more.
12141220
pub fn transactions_with_params<'a>(
12151221
&'a self,
12161222
params: CanonicalizationParams,
@@ -2486,19 +2492,20 @@ impl Wallet {
24862492
Ok(())
24872493
}
24882494

2489-
/// Inserts a transaction into the inner transaction graph with no additional metadata.
2495+
/// Inserts a transaction into the inner transaction graph, scanning for relevant txouts.
24902496
///
24912497
/// This is used to inform the wallet of newly created txs before they are known to exist
2492-
/// on chain (or in mempool), which is useful for discovering wallet-owned outputs of
2493-
/// not-yet-canonical transactions.
2498+
/// on chain or in mempool, which is useful for discovering wallet-owned outputs of
2499+
/// not-yet-canonical transactions. The inserted transaction carries no additional metadata,
2500+
/// like the time it was seen or the confirmation height. To later retrieve it, refer to
2501+
/// [`Wallet::transactions_with_params`].
24942502
///
24952503
/// The effect of insertion depends on the [relevance] of `tx` as determined by the indexer.
24962504
/// If the transaction was newly inserted and a txout matches a derived SPK, then the index
2497-
/// is updated with the relevant outpoint. This means the output may be selected in
2498-
/// subsequent transactions (if selected manually), enabling chains of dependent spends to
2499-
/// occur prior to broadcast time. If none of the outputs are relevant, the transaction is
2500-
/// kept but the index remains unchanged. If the transaction was already present in-graph,
2501-
/// the effect is a no-op.
2505+
/// is updated with the relevant outpoint(s). If no outputs are relevant, the transaction is
2506+
/// kept but the index remains unchanged. There should be no change to the wallet balance until
2507+
/// the transaction is accepted by the network and the wallet is synced. If `tx` was already
2508+
/// present in-graph, then the effect is a no-op.
25022509
///
25032510
/// **You must persist the change set staged as a result of this call.**
25042511
///

wallet/tests/psbt.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ fn test_create_psbt_cltv() {
136136
}
137137
}
138138

139+
// Test that replacing two unconfirmed txs A, B results in a transaction
140+
// that spends the inputs of both A and B.
139141
#[test]
140142
fn test_replace_by_fee() {
141143
use KeychainKind::*;
@@ -219,7 +221,7 @@ fn test_replace_by_fee() {
219221
.unwrap()
220222
.0;
221223

222-
// Expect re-select inputs of A, B
224+
// Expect replace inputs of A, B
223225
assert_eq!(
224226
psbt.unsigned_tx.input.len(),
225227
2,

0 commit comments

Comments
 (0)