mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-12 01:24:23 +01:00
common: infrastructure to construct warning messages.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -42,6 +42,43 @@ u8 *towire_errorfmt(const tal_t *ctx,
|
||||
return msg;
|
||||
}
|
||||
|
||||
u8 *towire_warningfmtv(const tal_t *ctx,
|
||||
const struct channel_id *channel,
|
||||
const char *fmt,
|
||||
va_list ap)
|
||||
{
|
||||
/* BOLT #1:
|
||||
*
|
||||
* The channel is referred to by `channel_id`, unless `channel_id` is
|
||||
* 0 (i.e. all bytes are 0), in which case it refers to all
|
||||
* channels. */
|
||||
static const struct channel_id all_channels;
|
||||
char *estr;
|
||||
u8 *msg;
|
||||
|
||||
estr = tal_vfmt(ctx, fmt, ap);
|
||||
/* We need tal_len to work, so we use copy. */
|
||||
msg = towire_warning(ctx, channel ? channel : &all_channels,
|
||||
(u8 *)tal_dup_arr(estr, char, estr, strlen(estr), 0));
|
||||
tal_free(estr);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
u8 *towire_warningfmt(const tal_t *ctx,
|
||||
const struct channel_id *channel,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
u8 *msg;
|
||||
|
||||
va_start(ap, fmt);
|
||||
msg = towire_warningfmtv(ctx, channel, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
bool channel_id_is_all(const struct channel_id *channel_id)
|
||||
{
|
||||
return memeqzero(channel_id, sizeof(*channel_id));
|
||||
|
||||
@@ -32,6 +32,30 @@ u8 *towire_errorfmtv(const tal_t *ctx,
|
||||
const char *fmt,
|
||||
va_list ap);
|
||||
|
||||
/**
|
||||
* towire_warningfmt - helper to turn string into WIRE_WARNING.
|
||||
*
|
||||
* @ctx: context to allocate from
|
||||
* @channel: specific channel to complain about, or NULL for all.
|
||||
* @fmt: format for warning.
|
||||
*/
|
||||
u8 *towire_warningfmt(const tal_t *ctx,
|
||||
const struct channel_id *channel,
|
||||
const char *fmt, ...) PRINTF_FMT(3,4);
|
||||
|
||||
/**
|
||||
* towire_warningfmtv - helper to turn string into WIRE_WARNING.
|
||||
*
|
||||
* @ctx: context to allocate from
|
||||
* @channel: specific channel to complain about, or NULL for all.
|
||||
* @fmt: format for warning.
|
||||
* @ap: accumulated varargs.
|
||||
*/
|
||||
u8 *towire_warningfmtv(const tal_t *ctx,
|
||||
const struct channel_id *channel,
|
||||
const char *fmt,
|
||||
va_list ap);
|
||||
|
||||
/* BOLT #1:
|
||||
*
|
||||
* The channel is referred to by `channel_id`, unless `channel_id` is 0
|
||||
|
||||
Reference in New Issue
Block a user