+ /// Get the channel pubkeys for the countersignatory
+ pub fn countersignatory_pubkeys(&self) -> &ChannelPublicKeys {
+ if self.holder_is_broadcaster {
+ &self.inner.counterparty_parameters.as_ref().unwrap().pubkeys
+ } else {
+ &self.inner.holder_pubkeys
+ }
+ }
+
+ /// Get the contest delay applicable to the transactions.
+ /// Note that the contest delay was selected by the countersignatory.
+ pub fn contest_delay(&self) -> u16 {
+ let counterparty_parameters = self.inner.counterparty_parameters.as_ref().unwrap();
+ if self.holder_is_broadcaster { counterparty_parameters.selected_contest_delay } else { self.inner.holder_selected_contest_delay }
+ }
+
+ /// Whether the channel is outbound from the broadcaster.
+ ///
+ /// The boolean representing the side that initiated the channel is
+ /// an input to the commitment number obscure factor computation.
+ pub fn is_outbound(&self) -> bool {
+ if self.holder_is_broadcaster { self.inner.is_outbound_from_holder } else { !self.inner.is_outbound_from_holder }
+ }
+
+ /// The funding outpoint
+ pub fn funding_outpoint(&self) -> OutPoint {
+ self.inner.funding_outpoint.unwrap().into_bitcoin_outpoint()
+ }
+}
+
+/// Information needed to build and sign a holder's commitment transaction.
+///
+/// The transaction is only signed once we are ready to broadcast.
+#[derive(Clone)]
+pub struct HolderCommitmentTransaction {
+ inner: CommitmentTransaction,
+ /// Our counterparty's signature for the transaction
+ pub counterparty_sig: Signature,
+ /// All non-dust counterparty HTLC signatures, in the order they appear in the transaction
+ pub counterparty_htlc_sigs: Vec<Signature>,
+ // Which order the signatures should go in when constructing the final commitment tx witness.
+ // The user should be able to reconstruct this themselves, so we don't bother to expose it.
+ holder_sig_first: bool,
+}
+
+impl Deref for HolderCommitmentTransaction {
+ type Target = CommitmentTransaction;
+
+ fn deref(&self) -> &Self::Target { &self.inner }
+}
+
+impl PartialEq for HolderCommitmentTransaction {
+ // We dont care whether we are signed in equality comparison
+ fn eq(&self, o: &Self) -> bool {
+ self.inner == o.inner
+ }
+}
+
+impl_writeable!(HolderCommitmentTransaction, 0, {
+ inner, counterparty_sig, counterparty_htlc_sigs, holder_sig_first
+});
+
+impl HolderCommitmentTransaction {
+ #[cfg(test)]
+ pub fn dummy() -> Self {
+ let secp_ctx = Secp256k1::new();
+ let dummy_key = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
+ let dummy_sig = secp_ctx.sign(&secp256k1::Message::from_slice(&[42; 32]).unwrap(), &SecretKey::from_slice(&[42; 32]).unwrap());
+
+ let keys = TxCreationKeys {
+ per_commitment_point: dummy_key.clone(),
+ revocation_key: dummy_key.clone(),
+ broadcaster_htlc_key: dummy_key.clone(),
+ countersignatory_htlc_key: dummy_key.clone(),
+ broadcaster_delayed_payment_key: dummy_key.clone(),
+ };
+ let channel_pubkeys = ChannelPublicKeys {
+ funding_pubkey: dummy_key.clone(),
+ revocation_basepoint: dummy_key.clone(),
+ payment_point: dummy_key.clone(),
+ delayed_payment_basepoint: dummy_key.clone(),
+ htlc_basepoint: dummy_key.clone()
+ };
+ let channel_parameters = ChannelTransactionParameters {
+ holder_pubkeys: channel_pubkeys.clone(),
+ holder_selected_contest_delay: 0,
+ is_outbound_from_holder: false,
+ counterparty_parameters: Some(CounterpartyChannelTransactionParameters { pubkeys: channel_pubkeys.clone(), selected_contest_delay: 0 }),
+ funding_outpoint: Some(chain::transaction::OutPoint { txid: Default::default(), index: 0 })
+ };
+ let mut htlcs_with_aux: Vec<(_, ())> = Vec::new();
+ let inner = CommitmentTransaction::new_with_auxiliary_htlc_data(0, 0, 0, keys, 0, &mut htlcs_with_aux, &channel_parameters.as_counterparty_broadcastable());
+ HolderCommitmentTransaction {
+ inner,
+ counterparty_sig: dummy_sig,
+ counterparty_htlc_sigs: Vec::new(),
+ holder_sig_first: false