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

Function json_datastoreusage

lightningd/datastore.c:288–334  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

286}
287
288static struct command_result *json_datastoreusage(struct command *cmd,
289 const char *buffer,
290 const jsmntok_t *obj UNNEEDED,
291 const jsmntok_t *params)
292{
293 struct json_stream *response;
294 const char **k, **key;
295 struct db_stmt *stmt;
296 const u8 *data;
297 u64 gen, total_bytes = 0;
298
299 if (!param(cmd, buffer, params,
300 p_opt("key", param_list_or_string, &key),
301 NULL))
302 return command_param_failed();
303
304 // We ignore an empty key string or key array.
305 if (key && *key[0] == '\0')
306 key = NULL;
307
308 response = json_stream_success(cmd);
309 json_object_start(response, "datastoreusage");
310 json_add_string(response, "key", datastore_key_fmt(tmpctx, key));
311
312 for (stmt = wallet_datastore_first(cmd, cmd->ld->wallet, key,
313 &k, &data, &gen);
314 stmt;
315 stmt = wallet_datastore_next(cmd, key, stmt,
316 &k, &data, &gen)) {
317
318 u64 self_bytes = tal_bytelen(data);
319 /* The key is stored as a binary blob where each string is separated by
320 * a '\0'. Therefore we add an additional `len(k) - 1`. k is the primary
321 * key of the table and can not be NULL */
322 self_bytes += tal_count(k) - 1;
323 for (size_t i = 0; i < tal_count(k); i++) {
324 self_bytes += strlen(k[i]);
325 };
326 total_bytes += self_bytes;
327 };
328 tal_free(stmt);
329
330 json_add_u64(response, "total_bytes", total_bytes);
331 json_object_end(response);
332
333 return command_success(cmd, response);
334}
335
336static const struct json_command datastore_command = {
337 "datastore",

Callers

nothing calls this directly

Calls 13

json_object_startFunction · 0.85
datastore_key_fmtFunction · 0.85
wallet_datastore_firstFunction · 0.85
wallet_datastore_nextFunction · 0.85
tal_bytelenFunction · 0.85
tal_freeFunction · 0.85
json_add_u64Function · 0.85
json_object_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