X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fchan_utils.rs;h=263547204c415a963e2223c50da0a9841f2e61e1;hb=0b5b2828f980b615187fae05a950cc41e4fb186b;hp=19a07aaa19c2ea2c30f5498aee3c32278f7cb0c2;hpb=f605eb381943a7d60f995137a7156405078691d2;p=rust-lightning diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs index 19a07aaa..26354720 100644 --- a/lightning/src/ln/chan_utils.rs +++ b/lightning/src/ln/chan_utils.rs @@ -25,6 +25,25 @@ 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.