X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fchan_utils.rs;h=51a2c4b042224464eacbfe5781c9ed36325b992e;hb=9ed4f521f3950980a1a4680b708576890e8c0bcf;hp=5338c06c5b839fb099e0ac608cca8dfc7178f790;hpb=42d773823447bd219943cc795ab71f2915c24df7;p=rust-lightning diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs index 5338c06c..51a2c4b0 100644 --- a/lightning/src/ln/chan_utils.rs +++ b/lightning/src/ln/chan_utils.rs @@ -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 { + 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. @@ -124,15 +143,15 @@ pub struct TxCreationKeys { pub per_commitment_point: PublicKey, /// The revocation key which is used to allow the owner of the commitment transaction to /// provide their counterparty the ability to punish them if they broadcast an old state. - pub revocation_key: PublicKey, + pub(crate) revocation_key: PublicKey, /// A's HTLC Key - pub a_htlc_key: PublicKey, + pub(crate) a_htlc_key: PublicKey, /// B's HTLC Key - pub b_htlc_key: PublicKey, + pub(crate) b_htlc_key: PublicKey, /// A's Payment Key (which isn't allowed to be spent from for some delay) - pub a_delayed_payment_key: PublicKey, + pub(crate) a_delayed_payment_key: PublicKey, /// B's Payment Key - pub b_payment_key: PublicKey, + pub(crate) b_payment_key: PublicKey, } /// One counterparty's public keys which do not change over the life of a channel.