mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 22:45:27 +01:00
funding: funding_find_htlc and funding_remove_htlc.
Helpers for daemon. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
6d6abd57e7
commit
d5c30ee30b
2 changed files with 40 additions and 0 deletions
22
funding.c
22
funding.c
|
@ -1,5 +1,6 @@
|
||||||
#include "funding.h"
|
#include "funding.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <ccan/structeq/structeq.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static bool subtract_fees(uint64_t *funder, uint64_t *non_funder,
|
static bool subtract_fees(uint64_t *funder, uint64_t *non_funder,
|
||||||
|
@ -154,6 +155,27 @@ void funding_add_htlc(struct channel_oneside *creator,
|
||||||
creator->htlcs[n].rhash = *rhash;
|
creator->htlcs[n].rhash = *rhash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t funding_find_htlc(struct channel_oneside *creator,
|
||||||
|
const struct sha256 *rhash)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < tal_count(creator->htlcs); i++) {
|
||||||
|
if (structeq(&creator->htlcs[i].rhash, rhash))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
void funding_remove_htlc(struct channel_oneside *creator, size_t i)
|
||||||
|
{
|
||||||
|
size_t n = tal_count(creator->htlcs);
|
||||||
|
assert(i < n);
|
||||||
|
memmove(creator->htlcs + i, creator->htlcs + i + 1,
|
||||||
|
(n - i - 1) * sizeof(*creator->htlcs));
|
||||||
|
tal_resize(&creator->htlcs, n-1);
|
||||||
|
}
|
||||||
|
|
||||||
struct channel_state *copy_funding(const tal_t *ctx,
|
struct channel_state *copy_funding(const tal_t *ctx,
|
||||||
const struct channel_state *cstate)
|
const struct channel_state *cstate)
|
||||||
{
|
{
|
||||||
|
|
18
funding.h
18
funding.h
|
@ -85,4 +85,22 @@ void funding_add_htlc(struct channel_oneside *creator,
|
||||||
u32 msatoshis, const struct abs_locktime *expiry,
|
u32 msatoshis, const struct abs_locktime *expiry,
|
||||||
const struct sha256 *rhash);
|
const struct sha256 *rhash);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* funding_find_htlc: find an HTLC on this side of the channel.
|
||||||
|
* @creator: channel_state->a or channel_state->b, whichever originated htlc
|
||||||
|
* @rhash: hash of redeem secret
|
||||||
|
*
|
||||||
|
* Returns a number < tal_count(creator->htlcs), or == tal_count(creator->htlcs)
|
||||||
|
* on fail.
|
||||||
|
*/
|
||||||
|
size_t funding_find_htlc(struct channel_oneside *creator,
|
||||||
|
const struct sha256 *rhash);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* funding_remove_htlc: remove an HTLC from this side of the channel.
|
||||||
|
* @creator: channel_state->a or channel_state->b, whichever originated htlc
|
||||||
|
* @i: index returned from funding_find_htlc.
|
||||||
|
*/
|
||||||
|
void funding_remove_htlc(struct channel_oneside *creator, size_t i);
|
||||||
|
|
||||||
#endif /* LIGHTNING_FUNDING_H */
|
#endif /* LIGHTNING_FUNDING_H */
|
||||||
|
|
Loading…
Add table
Reference in a new issue