2017-07-20 20:49:45 +02:00
|
|
|
#ifndef LIGHTNING_BITCOIN_SHORT_CHANNEL_ID_H
|
|
|
|
#define LIGHTNING_BITCOIN_SHORT_CHANNEL_ID_H
|
|
|
|
#include "config.h"
|
|
|
|
#include <ccan/short_types/short_types.h>
|
2018-07-04 07:30:02 +02:00
|
|
|
#include <ccan/structeq/structeq.h>
|
2017-07-20 20:49:45 +02:00
|
|
|
#include <ccan/tal/tal.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
/* Short Channel ID is composed of 3 bytes for the block height, 3
|
2018-07-04 07:30:02 +02:00
|
|
|
* bytes of tx index in block and 2 bytes of output index. */
|
2017-07-20 20:49:45 +02:00
|
|
|
struct short_channel_id {
|
2018-03-01 10:22:24 +01:00
|
|
|
u64 u64;
|
2017-07-20 20:49:45 +02:00
|
|
|
};
|
2018-07-04 07:30:02 +02:00
|
|
|
/* Define short_channel_id_eq (no padding) */
|
|
|
|
STRUCTEQ_DEF(short_channel_id, 0, u64);
|
2017-07-20 20:49:45 +02:00
|
|
|
|
2018-03-01 10:22:24 +01:00
|
|
|
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);
|
|
|
|
|
2017-07-20 20:49:45 +02:00
|
|
|
bool short_channel_id_from_str(const char *str, size_t strlen,
|
|
|
|
struct short_channel_id *dst);
|
|
|
|
|
2018-03-01 10:22:24 +01:00
|
|
|
char *short_channel_id_to_str(const tal_t *ctx, const struct short_channel_id *scid);
|
2018-01-30 20:11:27 +01:00
|
|
|
|
2017-07-20 20:49:45 +02:00
|
|
|
#endif /* LIGHTNING_BITCOIN_SHORT_CHANNEL_ID_H */
|