Browse Source

channel_state: add htlcs array.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 10 years ago
parent
commit
f0df2b7930
  1. 18
      funding.c
  2. 2
      funding.h

18
funding.c

@ -36,7 +36,17 @@ static bool subtract_fees(uint64_t *funder, uint64_t *non_funder,
*funder -= *funder_fee; *funder -= *funder_fee;
return true; return true;
} }
static uint64_t htlcs_total(UpdateAddHtlc *const *htlcs)
{
size_t i, n = tal_count(htlcs);
uint64_t total = 0;
for (i = 0; i < n; i++)
total += htlcs[i]->amount;
return total;
}
bool funding_delta(const OpenChannel *oa, bool funding_delta(const OpenChannel *oa,
const OpenChannel *ob, const OpenChannel *ob,
const OpenAnchor *anchor, const OpenAnchor *anchor,
@ -53,7 +63,8 @@ bool funding_delta(const OpenChannel *oa,
a = a_side->pay + a_side->fee; a = a_side->pay + a_side->fee;
b = b_side->pay + b_side->fee; b = b_side->pay + b_side->fee;
fee = a_side->fee + b_side->fee; fee = a_side->fee + b_side->fee;
assert(a + b == anchor->amount); assert(a + b + htlcs_total(a_side->htlcs) + htlcs_total(b_side->htlcs)
== anchor->amount);
/* Only one can be funder. */ /* Only one can be funder. */
if (is_funder(oa) == is_funder(ob)) if (is_funder(oa) == is_funder(ob))
@ -101,6 +112,9 @@ struct channel_state *initial_funding(const tal_t *ctx,
{ {
struct channel_state *state = talz(ctx, struct channel_state); struct channel_state *state = talz(ctx, struct channel_state);
state->a.htlcs = tal_arr(state, UpdateAddHtlc *, 0);
state->b.htlcs = tal_arr(state, UpdateAddHtlc *, 0);
if (fee > anchor->amount) if (fee > anchor->amount)
return tal_free(state); return tal_free(state);

2
funding.h

@ -7,6 +7,8 @@
struct channel_oneside { struct channel_oneside {
uint64_t pay, fee; uint64_t pay, fee;
/* Use tal_count to get the number */
UpdateAddHtlc **htlcs;
}; };
struct channel_state { struct channel_state {

Loading…
Cancel
Save