X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fchan_utils.rs;h=d1489e2716836f928d5bdc04450f3d8722d4fbc9;hb=e0fe325402862978c66603e598cdf7f6fa628606;hp=968de7b43b5e079d2dac2f522350900680e100ee;hpb=6d5c5ba4bbfd0419a284bab8d2d52cef42afbbf1;p=rust-lightning diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs index 968de7b4..d1489e27 100644 --- a/lightning/src/ln/chan_utils.rs +++ b/lightning/src/ln/chan_utils.rs @@ -19,7 +19,7 @@ use bitcoin::util::address::Payload; use bitcoin::hashes::{Hash, HashEngine}; use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::hashes::ripemd160::Hash as Ripemd160; -use bitcoin::hash_types::{Txid, PubkeyHash}; +use bitcoin::hash_types::{Txid, PubkeyHash, WPubkeyHash}; use crate::chain::chaininterface::fee_for_weight; use crate::chain::package::WEIGHT_REVOKED_OUTPUT; @@ -475,7 +475,7 @@ impl_writeable_tlv_based!(TxCreationKeys, { }); /// One counterparty's public keys which do not change over the life of a channel. -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct ChannelPublicKeys { /// The public key which is used to sign all commitment transactions, as it appears in the /// on-chain channel lock-in 2-of-2 multisig output. @@ -556,6 +556,16 @@ pub fn get_revokeable_redeemscript(revocation_key: &PublicKey, contest_delay: u1 res } +/// Returns the script for the counterparty's output on a holder's commitment transaction based on +/// the channel type. +pub fn get_counterparty_payment_script(channel_type_features: &ChannelTypeFeatures, payment_key: &PublicKey) -> Script { + if channel_type_features.supports_anchors_zero_fee_htlc_tx() { + get_to_countersignatory_with_anchors_redeemscript(payment_key).to_v0_p2wsh() + } else { + Script::new_v0_p2wpkh(&WPubkeyHash::hash(&payment_key.serialize())) + } +} + /// Information about an HTLC as it appears in a commitment transaction #[derive(Clone, Debug, PartialEq, Eq)] pub struct HTLCOutputInCommitment { @@ -853,7 +863,7 @@ pub fn build_anchor_input_witness(funding_key: &PublicKey, funding_sig: &Signatu /// /// Normally, this is converted to the broadcaster/countersignatory-organized DirectedChannelTransactionParameters /// before use, via the as_holder_broadcastable and as_counterparty_broadcastable functions. -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct ChannelTransactionParameters { /// Holder public keys pub holder_pubkeys: ChannelPublicKeys, @@ -873,7 +883,7 @@ pub struct ChannelTransactionParameters { } /// Late-bound per-channel counterparty data used to build transactions. -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct CounterpartyChannelTransactionParameters { /// Counter-party public keys pub pubkeys: ChannelPublicKeys, @@ -982,7 +992,7 @@ pub struct DirectedChannelTransactionParameters<'a> { impl<'a> DirectedChannelTransactionParameters<'a> { /// Get the channel pubkeys for the broadcaster - pub fn broadcaster_pubkeys(&self) -> &ChannelPublicKeys { + pub fn broadcaster_pubkeys(&self) -> &'a ChannelPublicKeys { if self.holder_is_broadcaster { &self.inner.holder_pubkeys } else { @@ -991,7 +1001,7 @@ impl<'a> DirectedChannelTransactionParameters<'a> { } /// Get the channel pubkeys for the countersignatory - pub fn countersignatory_pubkeys(&self) -> &ChannelPublicKeys { + pub fn countersignatory_pubkeys(&self) -> &'a ChannelPublicKeys { if self.holder_is_broadcaster { &self.inner.counterparty_parameters.as_ref().unwrap().pubkeys } else { @@ -1020,7 +1030,7 @@ impl<'a> DirectedChannelTransactionParameters<'a> { } /// Whether to use anchors for this channel - pub fn channel_type_features(&self) -> &ChannelTypeFeatures { + pub fn channel_type_features(&self) -> &'a ChannelTypeFeatures { &self.inner.channel_type_features } } @@ -1279,7 +1289,7 @@ impl<'a> Deref for TrustedClosingTransaction<'a> { impl<'a> TrustedClosingTransaction<'a> { /// The pre-built Bitcoin commitment transaction - pub fn built_transaction(&self) -> &Transaction { + pub fn built_transaction(&self) -> &'a Transaction { &self.inner.built } @@ -1668,17 +1678,17 @@ impl<'a> TrustedCommitmentTransaction<'a> { } /// The pre-built Bitcoin commitment transaction - pub fn built_transaction(&self) -> &BuiltCommitmentTransaction { + pub fn built_transaction(&self) -> &'a BuiltCommitmentTransaction { &self.inner.built } /// The pre-calculated transaction creation public keys. - pub fn keys(&self) -> &TxCreationKeys { + pub fn keys(&self) -> &'a TxCreationKeys { &self.inner.keys } /// Should anchors be used. - pub fn channel_type_features(&self) -> &ChannelTypeFeatures { + pub fn channel_type_features(&self) -> &'a ChannelTypeFeatures { &self.inner.channel_type_features }