Skip to content

Commit e85b99c

Browse files
committed
Add segwit_version to DescriptorType
1 parent cb0dd48 commit e85b99c

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/descriptor/mod.rs

Lines changed: 6 additions & 5 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,14 +731,14 @@ impl PsbtExt for Psbt {
731731
let expected_spk = {
732732
match (&input.witness_utxo, &input.non_witness_utxo) {
733733
(Some(witness_utxo), None) => {
734-
if desc_type.is_segwit() {
734+
if desc_type.segwit_version().is_some() {
735735
witness_utxo.script_pubkey.clone()
736736
} else {
737737
return Err(UtxoUpdateError::UtxoCheck);
738738
}
739739
}
740740
(None, Some(non_witness_utxo)) => {
741-
if desc_type.is_segwit() {
741+
if desc_type.segwit_version().is_some() {
742742
return Err(UtxoUpdateError::UtxoCheck);
743743
}
744744

0 commit comments

Comments
 (0)