Pull anchor check into helper function

This commit is contained in:
Elias Rohrer 2024-03-27 11:43:55 +01:00
parent 113b0f1a0e
commit 5cc321594d
No known key found for this signature in database
GPG key ID: 36153082BDF676FD
2 changed files with 8 additions and 6 deletions

View file

@ -852,6 +852,11 @@ impl ChannelTransactionParameters {
self.counterparty_parameters.is_some() && self.funding_outpoint.is_some() self.counterparty_parameters.is_some() && self.funding_outpoint.is_some()
} }
/// Whether the channel supports zero-fee HTLC transaction anchors.
pub(crate) fn supports_anchors(&self) -> bool {
self.channel_type_features.supports_anchors_zero_fee_htlc_tx()
}
/// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters, /// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters,
/// given that the holder is the broadcaster. /// given that the holder is the broadcaster.
/// ///

View file

@ -156,7 +156,7 @@ impl StaticPaymentOutputDescriptor {
pub fn witness_script(&self) -> Option<ScriptBuf> { pub fn witness_script(&self) -> Option<ScriptBuf> {
self.channel_transaction_parameters.as_ref() self.channel_transaction_parameters.as_ref()
.and_then(|channel_params| .and_then(|channel_params|
if channel_params.channel_type_features.supports_anchors_zero_fee_htlc_tx() { if channel_params.supports_anchors() {
let payment_point = channel_params.holder_pubkeys.payment_point; let payment_point = channel_params.holder_pubkeys.payment_point;
Some(chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_point)) Some(chan_utils::get_to_countersignatory_with_anchors_redeemscript(&payment_point))
} else { } else {
@ -169,9 +169,7 @@ impl StaticPaymentOutputDescriptor {
/// Note: If you have the grind_signatures feature enabled, this will be at least 1 byte /// Note: If you have the grind_signatures feature enabled, this will be at least 1 byte
/// shorter. /// shorter.
pub fn max_witness_length(&self) -> u64 { pub fn max_witness_length(&self) -> u64 {
if self.channel_transaction_parameters.as_ref() if self.channel_transaction_parameters.as_ref().map_or(false, |p| p.supports_anchors())
.map(|channel_params| channel_params.channel_type_features.supports_anchors_zero_fee_htlc_tx())
.unwrap_or(false)
{ {
let witness_script_weight = 1 /* pubkey push */ + 33 /* pubkey */ + let witness_script_weight = 1 /* pubkey push */ + 33 /* pubkey */ +
1 /* OP_CHECKSIGVERIFY */ + 1 /* OP_1 */ + 1 /* OP_CHECKSEQUENCEVERIFY */; 1 /* OP_CHECKSIGVERIFY */ + 1 /* OP_1 */ + 1 /* OP_CHECKSEQUENCEVERIFY */;
@ -356,8 +354,7 @@ impl SpendableOutputDescriptor {
if !output_set.insert(descriptor.outpoint) { return Err(()); } if !output_set.insert(descriptor.outpoint) { return Err(()); }
let sequence = let sequence =
if descriptor.channel_transaction_parameters.as_ref() if descriptor.channel_transaction_parameters.as_ref()
.map(|channel_params| channel_params.channel_type_features.supports_anchors_zero_fee_htlc_tx()) .map_or(false, |p| p.supports_anchors())
.unwrap_or(false)
{ {
Sequence::from_consensus(1) Sequence::from_consensus(1)
} else { } else {