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

Function init_accounts

plugins/bkpr/account.c:283–330  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

281}
282
283struct accounts *init_accounts(const tal_t *ctx, struct command *init_cmd)
284{
285 struct json_out *params = json_out_new(tmpctx);
286 const jsmntok_t *result;
287 const char *buf;
288 const jsmntok_t *datastore, *t;
289 size_t i;
290 struct accounts *accounts = tal(ctx, struct accounts);
291
292 accounts->htable = tal(accounts, struct account_htable);
293 account_htable_init(accounts->htable);
294 memleak_add_helper(accounts->htable, memleak_scan_accounts_htable);
295
296 json_out_start(params, NULL, '{');
297 json_out_start(params, "key", '[');
298 json_out_addstr(params, NULL, "bookkeeper");
299 json_out_addstr(params, NULL, "account");
300 json_out_end(params, ']');
301 json_out_end(params, '}');
302 result = jsonrpc_request_sync(tmpctx, init_cmd,
303 "listdatastore",
304 params, &buf);
305
306 datastore = json_get_member(buf, result, "datastore");
307 json_for_each_arr(i, t, datastore) {
308 size_t datalen;
309 const jsmntok_t *key, *datatok;
310 const u8 *data;
311
312 /* Key is an array, first two elements are bookkeeper, account */
313 key = json_get_member(buf, t, "key") + 3;
314 datatok = json_get_member(buf, t, "hex");
315 /* In case someone creates a subdir? */
316 if (!datatok)
317 continue;
318
319 data = json_tok_bin_from_hex(tmpctx, buf, datatok);
320 datalen = tal_bytelen(data);
321
322 if (fromwire_account(accounts, &data, &datalen) == NULL) {
323 plugin_err(init_cmd->plugin,
324 "Invalid account %.*s in datastore",
325 json_tok_full_len(key),
326 json_tok_full(buf, key));
327 }
328 }
329 return accounts;
330}

Callers 1

initFunction · 0.70

Calls 12

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
fromwire_accountFunction · 0.85
jsonrpc_request_syncFunction · 0.50
json_tok_bin_from_hexFunction · 0.50
plugin_errFunction · 0.50
json_tok_full_lenFunction · 0.50
json_tok_fullFunction · 0.50

Tested by

no test coverage detected