Skip to content

Commit e205a0f

Browse files
reezthunderbiscuit
authored andcommitted
feat: expose insert_txout on Wallet
1 parent 7c57414 commit e205a0f

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

bdk-ffi/src/wallet.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::bitcoin::{Amount, FeeRate, OutPoint, Psbt, Script, Transaction, Txid};
1+
use crate::bitcoin::{Amount, FeeRate, OutPoint, Psbt, Script, Transaction, TxOut, Txid};
22
use crate::descriptor::Descriptor;
33
use crate::error::{
44
CalculateFeeError, CannotConnectError, CreateWithPersistError, DescriptorError,
@@ -443,6 +443,28 @@ impl Wallet {
443443
Ok(self.get_wallet().get_tx(txid.0).map(|tx| tx.into()))
444444
}
445445

446+
/// Inserts a [`TxOut`] at [`OutPoint`] into the wallet's transaction graph.
447+
///
448+
/// This is used for providing a previous output's value so that we can use [`calculate_fee`]
449+
/// or [`calculate_fee_rate`] on a given transaction. Outputs inserted with this method will
450+
/// not be returned in [`list_unspent`] or [`list_output`].
451+
///
452+
/// **WARNINGS:** This should only be used to add `TxOut`s that the wallet does not own. Only
453+
/// insert `TxOut`s that you trust the values for!
454+
///
455+
/// You must persist the changes resulting from one or more calls to this method if you need
456+
/// the inserted `TxOut` data to be reloaded after closing the wallet.
457+
/// See [`Wallet::reveal_next_address`].
458+
///
459+
/// [`calculate_fee`]: Self::calculate_fee
460+
/// [`calculate_fee_rate`]: Self::calculate_fee_rate
461+
/// [`list_unspent`]: Self::list_unspent
462+
/// [`list_output`]: Self::list_output
463+
pub fn insert_txout(&self, outpoint: OutPoint, txout: TxOut) {
464+
self.get_wallet()
465+
.insert_txout(outpoint.into(), txout.into());
466+
}
467+
446468
/// Calculates the fee of a given transaction. Returns [`Amount::ZERO`] if `tx` is a coinbase transaction.
447469
///
448470
/// To calculate the fee for a [`Transaction`] with inputs not owned by this wallet you must

0 commit comments

Comments
 (0)