funding: return pointer to added HTLC.

For convenience.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2016-05-26 15:25:24 +09:30
parent b6dbaa409c
commit b66d3e263a
2 changed files with 26 additions and 21 deletions

View File

@ -222,11 +222,12 @@ void invert_cstate(struct channel_state *cstate)
}
/* Add a HTLC to @creator if it can afford it. */
static bool add_htlc(struct channel_state *cstate,
struct channel_oneside *creator,
struct channel_oneside *recipient,
u32 msatoshis, const struct abs_locktime *expiry,
const struct sha256 *rhash, uint64_t id)
static struct channel_htlc *add_htlc(struct channel_state *cstate,
struct channel_oneside *creator,
struct channel_oneside *recipient,
u32 msatoshis,
const struct abs_locktime *expiry,
const struct sha256 *rhash, uint64_t id)
{
size_t n, nondust;
@ -240,7 +241,7 @@ static bool add_htlc(struct channel_state *cstate,
if (!change_funding(cstate->anchor, cstate->fee_rate,
msatoshis, creator, recipient, nondust))
return false;
return NULL;
n = tal_count(creator->htlcs);
tal_resize(&creator->htlcs, n+1);
@ -253,7 +254,7 @@ static bool add_htlc(struct channel_state *cstate,
sizeof(creator->htlcs[n].msatoshis));
memcheck(&creator->htlcs[n].rhash, sizeof(creator->htlcs[n].rhash));
cstate->changes++;
return true;
return &creator->htlcs[n];
}
/* Remove htlc from creator, credit it to beneficiary. */
@ -291,17 +292,19 @@ static void remove_htlc(struct channel_state *cstate,
cstate->changes++;
}
bool funding_a_add_htlc(struct channel_state *cstate,
u32 msatoshis, const struct abs_locktime *expiry,
const struct sha256 *rhash, uint64_t id)
struct channel_htlc *funding_a_add_htlc(struct channel_state *cstate,
u32 msatoshis,
const struct abs_locktime *expiry,
const struct sha256 *rhash, uint64_t id)
{
return add_htlc(cstate, &cstate->a, &cstate->b,
msatoshis, expiry, rhash, id);
}
bool funding_b_add_htlc(struct channel_state *cstate,
u32 msatoshis, const struct abs_locktime *expiry,
const struct sha256 *rhash, uint64_t id)
struct channel_htlc *funding_b_add_htlc(struct channel_state *cstate,
u32 msatoshis,
const struct abs_locktime *expiry,
const struct sha256 *rhash, uint64_t id)
{
return add_htlc(cstate, &cstate->b, &cstate->a,
msatoshis, expiry, rhash, id);

View File

@ -61,17 +61,19 @@ struct channel_state *copy_funding(const tal_t *ctx,
* @id: 64-bit ID for htlc
*
* If A can't afford the HTLC (or still owes its half of the fees),
* this will return false and leave @cstate unchanged. Otherwise
* this will return NULL and leave @cstate unchanged. Otherwise
* cstate->a.htlcs will have the HTLC appended, and pay_msat and
* fee_msat are adjusted accordingly.
* fee_msat are adjusted accordingly; &cstate->htlcs[<last] is returned.
*/
bool funding_a_add_htlc(struct channel_state *cstate,
u32 msatoshis, const struct abs_locktime *expiry,
const struct sha256 *rhash, uint64_t id);
struct channel_htlc *funding_a_add_htlc(struct channel_state *cstate,
u32 msatoshis,
const struct abs_locktime *expiry,
const struct sha256 *rhash, uint64_t id);
bool funding_b_add_htlc(struct channel_state *cstate,
u32 msatoshis, const struct abs_locktime *expiry,
const struct sha256 *rhash, uint64_t id);
struct channel_htlc *funding_b_add_htlc(struct channel_state *cstate,
u32 msatoshis,
const struct abs_locktime *expiry,
const struct sha256 *rhash, uint64_t id);
/**
* funding_a_fail_htlc: remove an HTLC from A's side of cstate, funds to A