]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Expose witness_script for StaticPaymentOutputDescriptor
authorWilmer Paulino <wilmer@wilmerpaulino.com>
Thu, 28 Sep 2023 19:31:43 +0000 (12:31 -0700)
committerWilmer Paulino <wilmer@wilmerpaulino.com>
Fri, 29 Sep 2023 21:22:04 +0000 (14:22 -0700)
lightning/src/sign/mod.rs

index 9a30253049d1bf0816626377ce0c258e568db7e9..39f1001c480fd45926aed14355d78068028bfdc5 100644 (file)
@@ -134,6 +134,22 @@ pub struct StaticPaymentOutputDescriptor {
        pub channel_transaction_parameters: Option<ChannelTransactionParameters>,
 }
 impl StaticPaymentOutputDescriptor {
+       /// Returns the `witness_script` of the spendable output.
+       ///
+       /// Note that this will only return `Some` for [`StaticPaymentOutputDescriptor`]s that
+       /// originated from an anchor outputs channel, as they take the form of a P2WSH script.
+       pub fn witness_script(&self) -> Option<Script> {
+               self.channel_transaction_parameters.as_ref()
+                       .and_then(|channel_params|
+                                if channel_params.channel_type_features.supports_anchors_zero_fee_htlc_tx() {
+                                       let payment_point = channel_params.holder_pubkeys.payment_point;
+                                       Some(chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_point))
+                                } else {
+                                        None
+                                }
+                       )
+       }
+
        /// The maximum length a well-formed witness spending one of these should have.
        /// Note: If you have the grind_signatures feature enabled, this will be at least 1 byte
        /// shorter.