Files
lightning/bitcoin/short_channel_id.h
Rusty Russell 042d5d13f5 short_channel_id: don't use bitfields.
I leave all the now-unnecessary accessors in place to avoid churn, but
the use of bitfields has been more pain than help.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-01 23:33:56 +01:00

54 lines
1.5 KiB
C

#ifndef LIGHTNING_BITCOIN_SHORT_CHANNEL_ID_H
#define LIGHTNING_BITCOIN_SHORT_CHANNEL_ID_H
#include "config.h"
#include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>
#include <stdbool.h>
#include <stddef.h>
/* Short Channel ID is composed of 3 bytes for the block height, 3
* bytes of tx index in block and 2 bytes of output index. The
* bitfield is mainly for unit tests where it is nice to be able to
* just memset them and not have to take care about the extra byte for
* u32 */
struct short_channel_id {
u64 u64;
};
static inline u32 short_channel_id_blocknum(const struct short_channel_id *scid)
{
return scid->u64 >> 40;
}
static inline u32 short_channel_id_txnum(const struct short_channel_id *scid)
{
return (scid->u64 >> 16) & 0x00FFFFFF;
}
static inline u16 short_channel_id_outnum(const struct short_channel_id *scid)
{
return scid->u64 & 0xFFFF;
}
void mk_short_channel_id(struct short_channel_id *scid,
u32 blocknum, u32 txnum, u16 outnum);
bool short_channel_id_from_str(const char *str, size_t strlen,
struct short_channel_id *dst);
static inline bool short_channel_id_eq(const struct short_channel_id *a,
const struct short_channel_id *b)
{
return a->u64 == b->u64;
}
/* Fast, platform dependent, way to convert from a short_channel_id to u64 */
static inline u64 short_channel_id_to_uint(const struct short_channel_id *scid)
{
return scid->u64;
}
char *short_channel_id_to_str(const tal_t *ctx, const struct short_channel_id *scid);
#endif /* LIGHTNING_BITCOIN_SHORT_CHANNEL_ID_H */