diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 40bb56812..44bd8624b 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -1757,6 +1758,57 @@ static const struct json_command listpeers_command = { /* Comment added to satisfice AUTODATA */ AUTODATA(json_command, &listpeers_command); +static void json_add_scb(struct command *cmd, + const char *fieldname, + struct json_stream *response, + struct channel *c) +{ + u8 *scb = tal_arr(cmd, u8, 0); + + towire_scb_chan(&scb, c->scb); + json_add_hex_talarr(response, fieldname, + scb); +} + +/* This will return a SCB for all the channels currently loaded + * in the in-memory channel */ +static struct command_result *json_staticbackup(struct command *cmd, + const char *buffer, + const jsmntok_t *obj UNNEEDED, + const jsmntok_t *params) +{ + struct json_stream *response; + struct peer *peer; + struct channel *channel; + + if (!param(cmd, buffer, params, NULL)) + return command_param_failed(); + + response = json_stream_success(cmd); + + json_array_start(response, "scb"); + + list_for_each(&cmd->ld->peers, peer, list) + list_for_each(&peer->channels, channel, list){ + if (!channel->scb) + continue; + json_add_scb(cmd, NULL, response, channel); + } + json_array_end(response); + + return command_success(cmd, response); +} + +static const struct json_command staticbackup_command = { + "staticbackup", + "backup", + json_staticbackup, + "Returns SCB of all the channels currently present in the DB" +}; +/* Comment added to satisfice AUTODATA */ +AUTODATA(json_command, &staticbackup_command); + + struct command_result * command_find_channel(struct command *cmd, const char *buffer, const jsmntok_t *tok,