|
1 | | -use crate::bitcoin::{Amount, FeeRate, OutPoint, Psbt, Script, Transaction, Txid}; |
| 1 | +use crate::bitcoin::{Amount, FeeRate, OutPoint, Psbt, Script, Transaction, TxOut, Txid}; |
2 | 2 | use crate::descriptor::Descriptor; |
3 | 3 | use crate::error::{ |
4 | 4 | CalculateFeeError, CannotConnectError, CreateWithPersistError, DescriptorError, |
@@ -443,6 +443,28 @@ impl Wallet { |
443 | 443 | Ok(self.get_wallet().get_tx(txid.0).map(|tx| tx.into())) |
444 | 444 | } |
445 | 445 |
|
| 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 | + |
446 | 468 | /// Calculates the fee of a given transaction. Returns [`Amount::ZERO`] if `tx` is a coinbase transaction. |
447 | 469 | /// |
448 | 470 | /// To calculate the fee for a [`Transaction`] with inputs not owned by this wallet you must |
|
0 commit comments