Add ChannelKeys to ChannelMonitor
[rust-lightning] / lightning / src / ln / chan_utils.rs
index aa212b2d2d2d4920b3bc1860449c6aa6f0f8d13d..e7bea90914ebf3fc834f909a84dc7c9bee84217f 100644 (file)
@@ -18,13 +18,32 @@ use ln::channelmanager::{PaymentHash, PaymentPreimage};
 use ln::msgs::DecodeError;
 use util::ser::{Readable, Writeable, Writer, WriterWriteAdaptor};
 
-use secp256k1::key::{SecretKey,PublicKey};
+use secp256k1::key::{SecretKey, PublicKey};
 use secp256k1::{Secp256k1, Signature};
 use secp256k1;
 
 pub(super) const HTLC_SUCCESS_TX_WEIGHT: u64 = 703;
 pub(super) const HTLC_TIMEOUT_TX_WEIGHT: u64 = 663;
 
+#[derive(PartialEq)]
+pub(crate) enum HTLCType {
+       AcceptedHTLC,
+       OfferedHTLC
+}
+
+impl HTLCType {
+       /// Check if a given tx witnessScript len matchs one of a pre-signed HTLC
+       pub(crate) fn scriptlen_to_htlctype(witness_script_len: usize) ->  Option<HTLCType> {
+               if witness_script_len == 133 {
+                       Some(HTLCType::OfferedHTLC)
+               } else if witness_script_len >= 136 && witness_script_len <= 139 {
+                       Some(HTLCType::AcceptedHTLC)
+               } else {
+                       None
+               }
+       }
+}
+
 // Various functions for key derivation and transaction creation for use within channels. Primarily
 // used in Channel and ChannelMonitor.
 
@@ -136,7 +155,7 @@ pub struct TxCreationKeys {
 }
 
 /// One counterparty's public keys which do not change over the life of a channel.
-#[derive(Clone)]
+#[derive(Clone, PartialEq)]
 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.