common: mvt_tag_strs() function to turn tags array into strings.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -489,6 +489,13 @@ struct channel_coin_mvt *new_coin_channel_push(const tal_t *ctx,
|
||||
AMOUNT_MSAT(0));
|
||||
}
|
||||
|
||||
const char **mvt_tag_strs(const tal_t *ctx, const enum mvt_tag *tags)
|
||||
{
|
||||
const char **strs = tal_arr(ctx, const char *, 0);
|
||||
for (size_t i = 0; i < tal_count(tags); i++)
|
||||
tal_arr_expand(&strs, mvt_tag_str(tags[i]));
|
||||
return strs;
|
||||
}
|
||||
/* This is used solely by onchaind. It always uses alt_account, with "" meaning
|
||||
* the channel itself. */
|
||||
void towire_chain_coin_mvt(u8 **pptr, const struct chain_coin_mvt *mvt)
|
||||
|
||||
@@ -256,6 +256,7 @@ struct channel_coin_mvt *new_coin_channel_push(const tal_t *ctx,
|
||||
bool chain_mvt_is_external(const struct chain_coin_mvt *mvt);
|
||||
|
||||
const char *mvt_tag_str(enum mvt_tag tag);
|
||||
const char **mvt_tag_strs(const tal_t *ctx, const enum mvt_tag *tags);
|
||||
|
||||
void towire_chain_coin_mvt(u8 **pptr, const struct chain_coin_mvt *mvt);
|
||||
void fromwire_chain_coin_mvt(const u8 **cursor, size_t *max, struct chain_coin_mvt *mvt);
|
||||
|
||||
@@ -459,6 +459,8 @@ static void chain_movement_notification_serialize(struct json_stream *stream,
|
||||
struct lightningd *ld,
|
||||
const struct chain_coin_mvt *chain_mvt)
|
||||
{
|
||||
const char **tags;
|
||||
|
||||
json_add_num(stream, "version", COIN_MVT_VERSION);
|
||||
json_add_string(stream, "type", "chain_mvt");
|
||||
json_add_node_id(stream, "node_id", &ld->our_nodeid);
|
||||
@@ -496,8 +498,9 @@ static void chain_movement_notification_serialize(struct json_stream *stream,
|
||||
json_add_num(stream, "output_count", chain_mvt->output_count);
|
||||
|
||||
json_array_start(stream, "tags");
|
||||
for (size_t i = 0; i < tal_count(chain_mvt->tags); i++)
|
||||
json_add_string(stream, NULL, mvt_tag_str(chain_mvt->tags[i]));
|
||||
tags = mvt_tag_strs(tmpctx, chain_mvt->tags);
|
||||
for (size_t i = 0; i < tal_count(tags); i++)
|
||||
json_add_string(stream, NULL, tags[i]);
|
||||
json_array_end(stream);
|
||||
|
||||
json_add_u32(stream, "blockheight", chain_mvt->blockheight);
|
||||
@@ -509,6 +512,8 @@ static void channel_movement_notification_serialize(struct json_stream *stream,
|
||||
struct lightningd *ld,
|
||||
const struct channel_coin_mvt *chan_mvt)
|
||||
{
|
||||
const char **tags;
|
||||
|
||||
json_add_num(stream, "version", COIN_MVT_VERSION);
|
||||
json_add_string(stream, "type", "channel_mvt");
|
||||
json_add_node_id(stream, "node_id", &ld->our_nodeid);
|
||||
@@ -525,8 +530,9 @@ static void channel_movement_notification_serialize(struct json_stream *stream,
|
||||
json_add_amount_msat(stream, "fees_msat", chan_mvt->fees);
|
||||
|
||||
json_array_start(stream, "tags");
|
||||
for (size_t i = 0; i < tal_count(chan_mvt->tags); i++)
|
||||
json_add_string(stream, NULL, mvt_tag_str(chan_mvt->tags[i]));
|
||||
tags = mvt_tag_strs(tmpctx, chan_mvt->tags);
|
||||
for (size_t i = 0; i < tal_count(tags); i++)
|
||||
json_add_string(stream, NULL, tags[i]);
|
||||
json_array_end(stream);
|
||||
|
||||
json_add_u32(stream, "timestamp", time_now().ts.tv_sec);
|
||||
|
||||
Reference in New Issue
Block a user