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

Function json_listdatastore

lightningd/datastore.c:207–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205}
206
207static struct command_result *json_listdatastore(struct command *cmd,
208 const char *buffer,
209 const jsmntok_t *obj UNNEEDED,
210 const jsmntok_t *params)
211{
212 struct json_stream *response;
213 const char **key, **k, **prev_k = NULL;
214 const u8 *data;
215 u64 generation;
216 struct db_stmt *stmt;
217
218 if (!param(cmd, buffer, params,
219 p_opt("key", param_list_or_string, &key),
220 NULL))
221 return command_param_failed();
222
223 response = json_stream_success(cmd);
224 json_array_start(response, "datastore");
225
226 for (stmt = wallet_datastore_first(cmd, cmd->ld->wallet, key,
227 &k, &data, &generation);
228 stmt;
229 stmt = wallet_datastore_next(cmd, key,
230 stmt, &k, &data,
231 &generation)) {
232
233 /* Don't list sub-children, except as summary to show it exists. */
234 if (tal_count(k) > tal_count(key) + 1) {
235 if (!prev_k || !datastore_key_startswith(k, prev_k)) {
236 prev_k = tal_dup_arr(cmd, const char *, k,
237 tal_count(key) + 1, 0);
238 json_object_start(response, NULL);
239 json_add_datastore(response, prev_k, NULL, 0);
240 json_object_end(response);
241 }
242 } else {
243 json_object_start(response, NULL);
244 json_add_datastore(response, k, data, generation);
245 json_object_end(response);
246 }
247 }
248 json_array_end(response);
249 return command_success(cmd, response);
250}
251
252static struct command_result *json_deldatastore(struct command *cmd,
253 const char *buffer,

Callers

nothing calls this directly

Calls 12

json_array_startFunction · 0.85
wallet_datastore_firstFunction · 0.85
wallet_datastore_nextFunction · 0.85
datastore_key_startswithFunction · 0.85
json_object_startFunction · 0.85
json_add_datastoreFunction · 0.85
json_object_endFunction · 0.85
json_array_endFunction · 0.85
command_param_failedFunction · 0.70
json_stream_successFunction · 0.70
command_successFunction · 0.70
paramFunction · 0.50

Tested by

no test coverage detected