Skip to content

Commit

Permalink
Add Descriptor::max_satisfaction_weight function
Browse files Browse the repository at this point in the history
  • Loading branch information
notmandatory committed Jun 7, 2023
1 parent cdf8718 commit 59d874c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,9 @@ interface Descriptor {
[Name=new_bip84_public]
constructor(DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network);

[Throws=BdkError]
u32 max_satisfaction_weight();

string as_string();

string as_string_private();
Expand Down
17 changes: 17 additions & 0 deletions bdk-ffi/src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use bdk::template::{
Bip44, Bip44Public, Bip49, Bip49Public, Bip84, Bip84Public, DescriptorTemplate,
};
use bdk::KeychainKind;
use std::convert::TryFrom;
use std::ops::Deref;
use std::str::FromStr;
use std::sync::Arc;
Expand Down Expand Up @@ -183,6 +184,22 @@ impl Descriptor {
}
}

/// Computes an upper bound on the weight of a satisfying witness to the
/// transaction.
///
/// Assumes all ec-signatures are 73 bytes, including push opcode and
/// sighash suffix. Includes the weight of the VarInts encoding the
/// scriptSig and witness stack length.
///
/// # Errors
/// When the descriptor is impossible to satisfy (ex: sh(OP_FALSE)).
pub(crate) fn max_satisfaction_weight(&self) -> Result<u32, BdkError> {
self.extended_descriptor
.max_satisfaction_weight()
.map(|w| u32::try_from(w).unwrap())
.map_err(BdkError::Miniscript)
}

pub(crate) fn as_string_private(&self) -> String {
let descriptor = &self.extended_descriptor;
let key_map = &self.key_map;
Expand Down

0 comments on commit 59d874c

Please sign in to comment.