common: mvt_tag_strs() function to turn tags array into strings.
What changed, and why it matters
This commit is a small code cleanup: it introduces a helper function that converts internal 'tags' into strings, and uses that helper in two places where notifications are formatted as JSON. There is no visible change in behavior and no security issue is apparent.
No security action needed; treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds mvt_tag_strs() in common/coin_mvt.c/h, which builds a tal-allocated const char ** array from an enum mvt_tag array by calling the existing mvt_tag_str() per tag. It then replaces two inline loops in lightningd/notification.c with calls to this helper. The output JSON is identical; the change is purely refactor/reuse.
Changed components
common/coin_mvt.ccommon/coin_mvt.hlightningd/notification.cInspect captured patch +18 / −4
diff --git a/common/coin_mvt.c b/common/coin_mvt.c
index 8f4b240a..34c74dd0 100644
--- a/common/coin_mvt.c
+++ b/common/coin_mvt.c
@@ -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)
diff --git a/common/coin_mvt.h b/common/coin_mvt.h
index d96a34c5..9b34496c 100644
--- a/common/coin_mvt.h
+++ b/common/coin_mvt.h
@@ -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);
diff --git a/lightningd/notification.c b/lightningd/notification.c
index 7bef9feb..d45123f8 100644
--- a/lightningd/notification.c
+++ b/lightningd/notification.c
@@ -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);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.