From a4125313ceb26383f2b880f21dd6eee5af834554 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 4 May 2016 16:11:47 +0930 Subject: [PATCH] peer: helpers to extract a given HTLC from commit_info. Signed-off-by: Rusty Russell --- daemon/peer.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/daemon/peer.c b/daemon/peer.c index ade0df1b6..d9dc5facc 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -743,6 +744,31 @@ static void close_depth_cb(struct peer *peer, unsigned int depth, } } +static UNNEEDED struct channel_htlc *htlc_by_index(const struct commit_info *ci, size_t index) +{ + if (ci->map[index] == -1) + return NULL; + + /* First two are non-HTLC outputs to us, them. */ + assert(index >= 2); + index -= 2; + + if (index < tal_count(ci->cstate->a.htlcs)) + return cast_const(struct channel_htlc *, ci->cstate->a.htlcs) + + index; + index -= tal_count(ci->cstate->a.htlcs); + assert(index < tal_count(ci->cstate->b.htlcs)); + return cast_const(struct channel_htlc *, ci->cstate->b.htlcs) + index; +} + +static UNNEEDED bool htlc_a_offered(struct commit_info *ci, size_t index) +{ + assert(index >= 2); + index -= 2; + + return index < tal_count(ci->cstate->a.htlcs); +} + /* We assume the tx is valid! Don't do a blockchain.info and feed this * invalid transactions! */ static void anchor_spent(struct peer *peer,