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

Function json_listdatastore

lightningd/datastore.c:225–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

223}
224
225static struct command_result *json_listdatastore(struct command *cmd,
226 const char *buffer,
227 const jsmntok_t *obj UNNEEDED,
228 const jsmntok_t *params)
229{
230 struct json_stream *response;
231 const char **key, **k, **prev_k = NULL;
232 const u8 *data;
233 u64 generation;
234 struct db_stmt *stmt;
235
236 if (!param(cmd, buffer, params,
237 p_opt("key", param_list_or_string, &key),
238 NULL))
239 return command_param_failed();
240
241 if (key)
242 log_debug(cmd->ld->log, "Looking for %s",
243 datastore_key_fmt(tmpctx, key));
244
245 response = json_stream_success(cmd);
246 json_array_start(response, "datastore");
247
248 for (stmt = wallet_datastore_first(cmd, cmd->ld->wallet, key,
249 &k, &data, &generation);
250 stmt;
251 stmt = wallet_datastore_next(cmd, cmd->ld->wallet,
252 stmt, &k, &data,
253 &generation)) {
254 log_debug(cmd->ld->log, "Got %s",
255 datastore_key_fmt(tmpctx, k));
256
257 /* Don't list children, except implicitly */
258 if (tal_count(k) > tal_count(key) + 1) {
259 log_debug(cmd->ld->log, "Too long");
260 if (!prev_k || !datastore_key_startswith(k, prev_k)) {
261 prev_k = tal_dup_arr(cmd, const char *, k,
262 tal_count(key) + 1, 0);
263 json_object_start(response, NULL);
264 json_add_datastore(response, prev_k, NULL, 0);
265 json_object_end(response);
266 }
267 } else if (key && !datastore_key_startswith(k, key)) {
268 log_debug(cmd->ld->log, "Not interested");
269 tal_free(stmt);
270 break;
271 } else {
272 log_debug(cmd->ld->log, "Printing");
273 json_object_start(response, NULL);
274 json_add_datastore(response, k, data, generation);
275 json_object_end(response);
276 }
277 }
278 json_array_end(response);
279 return command_success(cmd, response);
280}
281
282static struct command_result *json_deldatastore(struct command *cmd,

Callers

nothing calls this directly

Calls 14

datastore_key_fmtFunction · 0.85
wallet_datastore_firstFunction · 0.85
wallet_datastore_nextFunction · 0.85
datastore_key_startswithFunction · 0.85
json_add_datastoreFunction · 0.85
tal_freeFunction · 0.85
command_param_failedFunction · 0.70
json_stream_successFunction · 0.70
command_successFunction · 0.70
paramFunction · 0.50
json_array_startFunction · 0.50
json_object_startFunction · 0.50

Tested by

no test coverage detected