From 51031b591608c7e60e173ba8e4646caad7e879a4 Mon Sep 17 00:00:00 2001 From: LLFourn Date: Mon, 18 Apr 2022 08:22:18 +1000 Subject: [PATCH] Add segwit_version to DescriptorType --- src/descriptor/mod.rs | 11 ++++++----- src/psbt/mod.rs | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/descriptor/mod.rs b/src/descriptor/mod.rs index 275c0f78e..ea55c2982 100644 --- a/src/descriptor/mod.rs +++ b/src/descriptor/mod.rs @@ -261,14 +261,15 @@ pub enum DescriptorType { } impl DescriptorType { - /// Whether this is a segwit descriptor. + /// Returns the segwit version implied by the descriptor type. /// - /// Returns true whether it is "native" segwit or "wrapped" p2sh segwit - pub fn is_segwit(&self) -> bool { + /// This will return `Some(0)` whether it is "native" segwitv0 or "wrapped" p2sh segwit. + pub fn segwit_version(&self) -> Option { use self::DescriptorType::*; match self { - Wpkh | ShWpkh | Wsh | ShWsh | ShWshSortedMulti | WshSortedMulti | Tr => true, - Bare | Sh | Pkh | ShSortedMulti => false, + Tr => Some(1), + Wpkh | ShWpkh | Wsh | ShWsh | ShWshSortedMulti | WshSortedMulti => Some(0), + Bare | Sh | Pkh | ShSortedMulti => None, } } } diff --git a/src/psbt/mod.rs b/src/psbt/mod.rs index 96fd25559..79e35ad16 100644 --- a/src/psbt/mod.rs +++ b/src/psbt/mod.rs @@ -730,14 +730,14 @@ impl PsbtExt for Psbt { let expected_spk = { match (&input.witness_utxo, &input.non_witness_utxo) { (Some(witness_utxo), None) => { - if desc_type.is_segwit() { + if desc_type.segwit_version().is_some() { witness_utxo.script_pubkey.clone() } else { return Err(UtxoUpdateError::UtxoCheck); } } (None, Some(non_witness_utxo)) => { - if desc_type.is_segwit() { + if desc_type.segwit_version().is_some() { return Err(UtxoUpdateError::UtxoCheck); }