Skip to content

Commit 51031b5

Browse files
committed
Add segwit_version to DescriptorType
1 parent c8c19b1 commit 51031b5

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/descriptor/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,15 @@ pub enum DescriptorType {
261261
}
262262

263263
impl DescriptorType {
264-
/// Whether this is a segwit descriptor.
264+
/// Returns the segwit version implied by the descriptor type.
265265
///
266-
/// Returns true whether it is "native" segwit or "wrapped" p2sh segwit
267-
pub fn is_segwit(&self) -> bool {
266+
/// This will return `Some(0)` whether it is "native" segwitv0 or "wrapped" p2sh segwit.
267+
pub fn segwit_version(&self) -> Option<u8> {
268268
use self::DescriptorType::*;
269269
match self {
270-
Wpkh | ShWpkh | Wsh | ShWsh | ShWshSortedMulti | WshSortedMulti | Tr => true,
271-
Bare | Sh | Pkh | ShSortedMulti => false,
270+
Tr => Some(1),
271+
Wpkh | ShWpkh | Wsh | ShWsh | ShWshSortedMulti | WshSortedMulti => Some(0),
272+
Bare | Sh | Pkh | ShSortedMulti => None,
272273
}
273274
}
274275
}

src/psbt/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -730,14 +730,14 @@ impl PsbtExt for Psbt {
730730
let expected_spk = {
731731
match (&input.witness_utxo, &input.non_witness_utxo) {
732732
(Some(witness_utxo), None) => {
733-
if desc_type.is_segwit() {
733+
if desc_type.segwit_version().is_some() {
734734
witness_utxo.script_pubkey.clone()
735735
} else {
736736
return Err(UtxoUpdateError::UtxoCheck);
737737
}
738738
}
739739
(None, Some(non_witness_utxo)) => {
740-
if desc_type.is_segwit() {
740+
if desc_type.segwit_version().is_some() {
741741
return Err(UtxoUpdateError::UtxoCheck);
742742
}
743743

0 commit comments

Comments
 (0)