bitcoin/short_channel_id: pass by copy everywhere.
It's a u64, we should pass by copy. This is a big sweeping change, but mainly mechanical (change one, compile, fix breakage, repeat). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -55,9 +55,9 @@ bool short_channel_id_from_str(const char *str, size_t strlen,
|
||||
char *fmt_short_channel_id(const tal_t *ctx, struct short_channel_id scid)
|
||||
{
|
||||
return tal_fmt(ctx, "%dx%dx%d",
|
||||
short_channel_id_blocknum(&scid),
|
||||
short_channel_id_txnum(&scid),
|
||||
short_channel_id_outnum(&scid));
|
||||
short_channel_id_blocknum(scid),
|
||||
short_channel_id_txnum(scid),
|
||||
short_channel_id_outnum(scid));
|
||||
}
|
||||
|
||||
bool short_channel_id_dir_from_str(const char *str, size_t strlen,
|
||||
@@ -87,13 +87,15 @@ char *fmt_short_channel_id_dir(const tal_t *ctx,
|
||||
}
|
||||
|
||||
void towire_short_channel_id(u8 **pptr,
|
||||
const struct short_channel_id *short_channel_id)
|
||||
struct short_channel_id short_channel_id)
|
||||
{
|
||||
towire_u64(pptr, short_channel_id->u64);
|
||||
towire_u64(pptr, short_channel_id.u64);
|
||||
}
|
||||
|
||||
void fromwire_short_channel_id(const u8 **cursor, size_t *max,
|
||||
struct short_channel_id *short_channel_id)
|
||||
struct short_channel_id fromwire_short_channel_id(const u8 **cursor, size_t *max)
|
||||
{
|
||||
short_channel_id->u64 = fromwire_u64(cursor, max);
|
||||
struct short_channel_id scid;
|
||||
|
||||
scid.u64 = fromwire_u64(cursor, max);
|
||||
return scid;
|
||||
}
|
||||
|
||||
@@ -12,8 +12,12 @@
|
||||
struct short_channel_id {
|
||||
u64 u64;
|
||||
};
|
||||
/* Define short_channel_id_eq (no padding) */
|
||||
STRUCTEQ_DEF(short_channel_id, 0, u64);
|
||||
|
||||
static inline bool short_channel_id_eq(struct short_channel_id a,
|
||||
struct short_channel_id b)
|
||||
{
|
||||
return a.u64 == b.u64;
|
||||
}
|
||||
|
||||
/* BOLT #7:
|
||||
*
|
||||
@@ -32,32 +36,32 @@ struct short_channel_id_dir {
|
||||
int dir;
|
||||
};
|
||||
|
||||
static inline u32 short_channel_id_blocknum(const struct short_channel_id *scid)
|
||||
static inline u32 short_channel_id_blocknum(struct short_channel_id scid)
|
||||
{
|
||||
return scid->u64 >> 40;
|
||||
return scid.u64 >> 40;
|
||||
}
|
||||
|
||||
static inline bool is_stub_scid(const struct short_channel_id *scid)
|
||||
static inline bool is_stub_scid(struct short_channel_id scid)
|
||||
{
|
||||
return scid ? scid->u64 >> 40 == 1 &&
|
||||
((scid->u64 >> 16) & 0x00FFFFFF) == 1 &&
|
||||
(scid->u64 & 0xFFFF) == 1 : false;
|
||||
return scid.u64 >> 40 == 1 &&
|
||||
((scid.u64 >> 16) & 0x00FFFFFF) == 1 &&
|
||||
(scid.u64 & 0xFFFF) == 1;
|
||||
}
|
||||
|
||||
static inline u32 short_channel_id_txnum(const struct short_channel_id *scid)
|
||||
static inline u32 short_channel_id_txnum(struct short_channel_id scid)
|
||||
{
|
||||
return (scid->u64 >> 16) & 0x00FFFFFF;
|
||||
return (scid.u64 >> 16) & 0x00FFFFFF;
|
||||
}
|
||||
|
||||
static inline u16 short_channel_id_outnum(const struct short_channel_id *scid)
|
||||
static inline u16 short_channel_id_outnum(struct short_channel_id scid)
|
||||
{
|
||||
return scid->u64 & 0xFFFF;
|
||||
return scid.u64 & 0xFFFF;
|
||||
}
|
||||
|
||||
/* Subtly, at block N, depth is 1, hence the -1 here. eg. 103x1x0 is announceable
|
||||
* when height is 108. */
|
||||
static inline bool
|
||||
is_scid_depth_announceable(const struct short_channel_id *scid,
|
||||
is_scid_depth_announceable(struct short_channel_id scid,
|
||||
unsigned int height)
|
||||
{
|
||||
return short_channel_id_blocknum(scid) + ANNOUNCE_MIN_DEPTH - 1
|
||||
@@ -80,8 +84,7 @@ char *fmt_short_channel_id_dir(const tal_t *ctx,
|
||||
|
||||
/* Marshal/unmarshal */
|
||||
void towire_short_channel_id(u8 **pptr,
|
||||
const struct short_channel_id *short_channel_id);
|
||||
void fromwire_short_channel_id(const u8 **cursor, size_t *max,
|
||||
struct short_channel_id *short_channel_id);
|
||||
struct short_channel_id short_channel_id);
|
||||
struct short_channel_id fromwire_short_channel_id(const u8 **cursor, size_t *max);
|
||||
|
||||
#endif /* LIGHTNING_BITCOIN_SHORT_CHANNEL_ID_H */
|
||||
|
||||
Reference in New Issue
Block a user