Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions bdk-ffi/src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,18 @@ impl Descriptor {
.collect()
})
}

/// Computes an upper bound on the difference between a non-satisfied `TxIn`'s
/// `segwit_weight` and a satisfied `TxIn`'s `segwit_weight`.
pub fn max_weight_to_satisfy(&self) -> Result<u64, DescriptorError> {
let weight = self
.extended_descriptor
.max_weight_to_satisfy()
.map_err(|e| DescriptorError::Miniscript {
error_message: e.to_string(),
})?;
Ok(weight.to_wu())
}
}

impl Display for Descriptor {
Expand Down Expand Up @@ -456,4 +468,19 @@ mod test {
assert!(descriptor1.is_ok());
assert_matches!(descriptor2.unwrap_err(), DescriptorError::Key { .. });
}

#[test]
fn test_max_weight_to_satisfy() {
// Test P2WPKH descriptor using standard test descriptor
let descriptor = Descriptor::new(
"wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/1h/0/*)".to_string(),
Network::Testnet
).unwrap();

let weight = descriptor.max_weight_to_satisfy().unwrap();
println!("P2WPKH max weight to satisfy: {} wu", weight);

// Verify the method works and returns a positive weight
assert!(weight > 0, "Weight must be positive");
}
}
Loading