From d7224e217895decb071bcd098cb231dbb93c6a7b Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 30 Jan 2018 20:11:27 +0100 Subject: [PATCH] gossip: Added short_channel_id_to_uint for uintmap index Signed-off-by: Christian Decker --- bitcoin/short_channel_id.c | 6 ++++++ bitcoin/short_channel_id.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/bitcoin/short_channel_id.c b/bitcoin/short_channel_id.c index d02e0a368..4085981ae 100644 --- a/bitcoin/short_channel_id.c +++ b/bitcoin/short_channel_id.c @@ -32,3 +32,9 @@ bool short_channel_id_eq(const struct short_channel_id *a, return a->blocknum == b->blocknum && a->txnum == b->txnum && a->outnum == b->outnum; } + +u64 short_channel_id_to_uint(const struct short_channel_id *scid) +{ + return ((u64)scid->blocknum & 0xFFFFFF) << 40 | + ((u64)scid->txnum & 0xFFFFFF) << 16 | (scid->outnum & 0xFFFF); +} diff --git a/bitcoin/short_channel_id.h b/bitcoin/short_channel_id.h index ecc2dc250..d0e9a346f 100644 --- a/bitcoin/short_channel_id.h +++ b/bitcoin/short_channel_id.h @@ -25,4 +25,7 @@ bool short_channel_id_eq(const struct short_channel_id *a, char *short_channel_id_to_str(const tal_t *ctx, const struct short_channel_id *scid); +/* Fast, platform dependent, way to convert from a short_channel_id to u64 */ +u64 short_channel_id_to_uint(const struct short_channel_id *scid); + #endif /* LIGHTNING_BITCOIN_SHORT_CHANNEL_ID_H */