diff --git a/daemon/Makefile b/daemon/Makefile index 01a25a507..9dacfd579 100644 --- a/daemon/Makefile +++ b/daemon/Makefile @@ -52,6 +52,7 @@ DAEMON_HEADERS := \ daemon/controlled_time.h \ daemon/cryptopkt.h \ daemon/dns.h \ + daemon/htlc.h \ daemon/json.h \ daemon/jsonrpc.h \ daemon/lightningd.h \ diff --git a/daemon/htlc.h b/daemon/htlc.h new file mode 100644 index 000000000..da879f1f6 --- /dev/null +++ b/daemon/htlc.h @@ -0,0 +1,49 @@ +#ifndef LIGHTNING_DAEMON_HTLC_H +#define LIGHTNING_DAEMON_HTLC_H +#include "config.h" +#include "bitcoin/locktime.h" +#include "pseudorand.h" +#include +#include +#include +#include + +struct htlc { + /* Useful for debugging, and decoding via ->src. */ + struct peer *peer; + /* The unique ID for this peer and this direction (ours or theirs) */ + u64 id; + /* The amount in millisatoshi. */ + u64 msatoshis; + /* When the HTLC can no longer be redeemed. */ + struct abs_locktime expiry; + /* The hash of the preimage which can redeem this HTLC */ + struct sha256 rhash; + + /* FIXME: We could union these together: */ + /* Routing information sent with this HTLC. */ + const u8 *routing; + /* Previous HTLC (if any) which made us offer this (OURS only) */ + struct htlc *src; +}; + +/* htlc_map: ID -> htlc mapping. */ +static inline u64 htlc_key(const struct htlc *h) +{ + return h->id; +} +static inline bool htlc_cmp(const struct htlc *h, u64 id) +{ + return h->id == id; +} +static inline size_t htlc_hash(u64 id) +{ + return siphash24(siphash_seed(), &id, sizeof(id)); +} +HTABLE_DEFINE_TYPE(struct htlc, htlc_key, htlc_hash, htlc_cmp, htlc_map); + +static inline size_t htlc_map_count(const struct htlc_map *htlcs) +{ + return htlcs->raw.elems; +} +#endif /* LIGHTNING_DAEMON_HTLC_H */