@@ -342,8 +342,9 @@ impl<'a, Cs> TxBuilder<'a, Cs> {
342342 ///
343343 /// This method returns errors in the following circumstances:
344344 ///
345- /// 1. The `psbt_input` does not contain a `witness_utxo` or `non_witness_utxo`.
346- /// 2. The data in `non_witness_utxo` does not match what is in `outpoint`.
345+ /// 1. The provided outpoint is associated to a [`LocalOutput`].
346+ /// 2. The `psbt_input` does not contain a `witness_utxo` or `non_witness_utxo`.
347+ /// 3. The data in `non_witness_utxo` does not match what is in `outpoint`.
347348 ///
348349 /// Note unless you set [`only_witness_utxo`] any non-taproot `psbt_input` you pass to this
349350 /// method must have `non_witness_utxo` set otherwise you will get an error when [`finish`]
@@ -374,6 +375,10 @@ impl<'a, Cs> TxBuilder<'a, Cs> {
374375 satisfaction_weight : Weight ,
375376 sequence : Sequence ,
376377 ) -> Result < & mut Self , AddForeignUtxoError > {
378+ // Avoid the inclusion of local utxos as foreign utxos
379+ if self . wallet . tx_graph ( ) . get_txout ( outpoint) . is_some ( ) {
380+ return Err ( AddForeignUtxoError :: NotForeignUtxo ) ;
381+ } ;
377382 if psbt_input. witness_utxo . is_none ( ) {
378383 match psbt_input. non_witness_utxo . as_ref ( ) {
379384 Some ( tx) => {
@@ -711,6 +716,8 @@ pub enum AddForeignUtxoError {
711716 InvalidOutpoint ( OutPoint ) ,
712717 /// Foreign utxo missing witness_utxo or non_witness_utxo
713718 MissingUtxo ,
719+ /// UTxO is owned by wallet
720+ NotForeignUtxo ,
714721}
715722
716723impl fmt:: Display for AddForeignUtxoError {
@@ -730,6 +737,7 @@ impl fmt::Display for AddForeignUtxoError {
730737 outpoint. txid, outpoint. vout,
731738 ) ,
732739 Self :: MissingUtxo => write ! ( f, "Foreign utxo missing witness_utxo or non_witness_utxo" ) ,
740+ Self :: NotForeignUtxo => write ! ( f, "UTxO is owned by wallet" ) ,
733741 }
734742 }
735743}
0 commit comments