MCPcopy Create free account
hub / github.com/ElementsProject/lightning / setup_backup_map

Function setup_backup_map

plugins/chanbackup.c:1064–1113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1062}
1063
1064static void setup_backup_map(struct command *init_cmd,
1065 struct chanbackup *cb)
1066{
1067 struct json_out *params = json_out_new(init_cmd);
1068 const jsmntok_t *result;
1069 const char *buf;
1070 const jsmntok_t *datastore, *t;
1071 size_t i, total = 0;
1072
1073 cb->backups = new_htable(cb, backup_map);
1074 cb->peers = new_htable(cb, peer_map);
1075
1076 json_out_start(params, NULL, '{');
1077 json_out_start(params, "key", '[');
1078 json_out_addstr(params, NULL, "chanbackup");
1079 json_out_addstr(params, NULL, "peers");
1080 json_out_end(params, ']');
1081 json_out_end(params, '}');
1082
1083 result = jsonrpc_request_sync(tmpctx, init_cmd,
1084 "listdatastore",
1085 take(params), &buf);
1086
1087 datastore = json_get_member(buf, result, "datastore");
1088 json_for_each_arr(i, t, datastore) {
1089 const jsmntok_t *keytok, *hextok;
1090 struct node_id peer;
1091 u8 *data;
1092
1093 /* Key is an array, first two elements are chanbackup, peers */
1094 keytok = json_get_member(buf, t, "key") + 3;
1095 hextok = json_get_member(buf, t, "hex");
1096 /* In case someone creates a subdir? */
1097 if (!hextok)
1098 continue;
1099 if (!json_to_node_id(buf, keytok, &peer))
1100 plugin_err(init_cmd->plugin,
1101 "Could not parse datastore id '%.*s'",
1102 json_tok_full_len(keytok),
1103 json_tok_full(buf, keytok));
1104 data = json_tok_bin_from_hex(NULL, buf, hextok);
1105 /* Only count non-empty ones. */
1106 if (tal_bytelen(data) != 0)
1107 total++;
1108 add_to_backup_map(cb, &peer, take(data));
1109 }
1110 if (total)
1111 plugin_log(init_cmd->plugin, LOG_INFORM,
1112 "Loaded %zu stored backups for peers", total);
1113}
1114
1115static const char *init(struct command *init_cmd,
1116 const char *buf UNUSED,

Callers 1

initFunction · 0.85

Calls 14

json_out_newFunction · 0.85
json_out_startFunction · 0.85
json_out_addstrFunction · 0.85
json_out_endFunction · 0.85
json_get_memberFunction · 0.85
tal_bytelenFunction · 0.85
add_to_backup_mapFunction · 0.85
jsonrpc_request_syncFunction · 0.70
plugin_errFunction · 0.70
plugin_logFunction · 0.70
json_to_node_idFunction · 0.50
json_tok_full_lenFunction · 0.50

Tested by

no test coverage detected