Skip to content

Commit 6a53cf2

Browse files
cdeckerrustyrussell
authored andcommitted
libplugin: Add primitive to serialize channel_hint to JSON
1 parent eae378c commit 6a53cf2

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

plugins/libplugin-pay.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,16 @@ void payment_start(struct payment *p)
387387
payment_start_at_blockheight(p, INVALID_BLOCKHEIGHT);
388388
}
389389

390+
static void channel_hint_to_json(const char *name, const struct channel_hint *hint, struct json_stream *dest)
391+
{
392+
json_object_start(dest, name);
393+
json_add_u32(dest, "timestamp", hint->timestamp);
394+
json_add_short_channel_id_dir(dest, "scid", hint->scid);
395+
json_add_amount_msat(dest, "capacity_msat", hint->estimated_capacity);
396+
json_add_bool(dest, "enabled", hint->enabled);
397+
json_object_end(dest);
398+
}
399+
390400
/**
391401
* Notify subscribers of the `channel_hint` topic about a changed hint
392402
*
@@ -406,7 +416,7 @@ static void channel_hint_notify(struct plugin *plugin,
406416
plugin_notification_start(plugin, "channel_hint_update");
407417

408418
/* The timestamp used to decay the observation over time. */
409-
json_add_u32(js, "timestamp", hint->timestamp);
419+
channel_hint_to_json("channel_hint", hint, js);
410420
plugin_notification_end(plugin, js);
411421
}
412422

plugins/test/run-route-calc.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ void json_add_amount_msat(struct json_stream *result UNNEEDED,
8181
struct amount_msat msat)
8282

8383
{ fprintf(stderr, "json_add_amount_msat called!\n"); abort(); }
84+
/* Generated stub for json_add_bool */
85+
void json_add_bool(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
86+
bool value UNNEEDED)
87+
{ fprintf(stderr, "json_add_bool called!\n"); abort(); }
8488
/* Generated stub for json_add_hex_talarr */
8589
void json_add_hex_talarr(struct json_stream *result UNNEEDED,
8690
const char *fieldname UNNEEDED,
@@ -116,6 +120,11 @@ void json_add_short_channel_id(struct json_stream *response UNNEEDED,
116120
const char *fieldname UNNEEDED,
117121
struct short_channel_id id UNNEEDED)
118122
{ fprintf(stderr, "json_add_short_channel_id called!\n"); abort(); }
123+
/* Generated stub for json_add_short_channel_id_dir */
124+
void json_add_short_channel_id_dir(struct json_stream *response UNNEEDED,
125+
const char *fieldname UNNEEDED,
126+
struct short_channel_id_dir idd UNNEEDED)
127+
{ fprintf(stderr, "json_add_short_channel_id_dir called!\n"); abort(); }
119128
/* Generated stub for json_add_string */
120129
void json_add_string(struct json_stream *js UNNEEDED,
121130
const char *fieldname UNNEEDED,

plugins/test/run-route-overlong.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ void json_add_amount_msat(struct json_stream *result UNNEEDED,
7878
struct amount_msat msat)
7979

8080
{ fprintf(stderr, "json_add_amount_msat called!\n"); abort(); }
81+
/* Generated stub for json_add_bool */
82+
void json_add_bool(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
83+
bool value UNNEEDED)
84+
{ fprintf(stderr, "json_add_bool called!\n"); abort(); }
8185
/* Generated stub for json_add_hex_talarr */
8286
void json_add_hex_talarr(struct json_stream *result UNNEEDED,
8387
const char *fieldname UNNEEDED,
@@ -113,6 +117,11 @@ void json_add_short_channel_id(struct json_stream *response UNNEEDED,
113117
const char *fieldname UNNEEDED,
114118
struct short_channel_id id UNNEEDED)
115119
{ fprintf(stderr, "json_add_short_channel_id called!\n"); abort(); }
120+
/* Generated stub for json_add_short_channel_id_dir */
121+
void json_add_short_channel_id_dir(struct json_stream *response UNNEEDED,
122+
const char *fieldname UNNEEDED,
123+
struct short_channel_id_dir idd UNNEEDED)
124+
{ fprintf(stderr, "json_add_short_channel_id_dir called!\n"); abort(); }
116125
/* Generated stub for json_add_string */
117126
void json_add_string(struct json_stream *js UNNEEDED,
118127
const char *fieldname UNNEEDED,

0 commit comments

Comments
 (0)