Skip to content

Commit

Permalink
Add segwit_version to DescriptorType
Browse files Browse the repository at this point in the history
  • Loading branch information
LLFourn committed Apr 21, 2022
1 parent c8c19b1 commit 51031b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> {
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,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/psbt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 51031b5

Please # to comment.