Skip to content

Commit a1a8c5b

Browse files
committed
feat(psbt): Add PsbtParams::only_witness_utxo
1 parent c73001c commit a1a8c5b

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/psbt/params.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub struct PsbtParams {
4343
pub(crate) locktime: Option<absolute::LockTime>,
4444
pub(crate) fallback_sequence: Option<Sequence>,
4545
pub(crate) ordering: TxOrdering<Input, Output>,
46+
pub(crate) only_witness_utxo: bool,
4647
}
4748

4849
impl Default for PsbtParams {
@@ -66,6 +67,7 @@ impl Default for PsbtParams {
6667
locktime: Default::default(),
6768
fallback_sequence: Default::default(),
6869
ordering: Default::default(),
70+
only_witness_utxo: Default::default(),
6971
}
7072
}
7173
}
@@ -239,6 +241,19 @@ impl PsbtParams {
239241
}
240242
self
241243
}
244+
245+
/// Only fill in the [`witness_utxo`] field of PSBT inputs which spends funds under segwit (v0).
246+
///
247+
/// This allows opting out of including the [`non_witness_utxo`] for segwit spends. This reduces
248+
/// the size of the PSBT, however be aware that some signers might require the presence of the
249+
/// `non_witness_utxo`.
250+
///
251+
/// [`witness_utxo`]: bitcoin::psbt::Input::witness_utxo
252+
/// [`non_witness_utxo`]: bitcoin::psbt::Input::non_witness_utxo
253+
pub fn only_witness_utxo(&mut self) -> &mut Self {
254+
self.only_witness_utxo = true;
255+
self
256+
}
242257
}
243258

244259
/// Coin select strategy.

src/wallet/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,9 +2993,7 @@ impl Wallet {
29932993
version,
29942994
fallback_locktime,
29952995
fallback_sequence,
2996-
mandate_full_tx_for_segwit_v0: true,
2997-
// TODO: Only witness utxo
2998-
// mandate_full_tx_for_segwit_v0: params.only_witness_utxo,
2996+
mandate_full_tx_for_segwit_v0: !params.only_witness_utxo,
29992997
})
30002998
.map_err(CreatePsbtError::Psbt)?;
30012999

0 commit comments

Comments
 (0)