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

Function init_onchain_fees

plugins/bkpr/onchain_fee.c:713–763  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

711}
712
713struct onchain_fees *init_onchain_fees(const tal_t *ctx,
714 struct command *init_cmd)
715{
716 struct onchain_fees *onchain_fees = tal(ctx, struct onchain_fees);
717 struct json_out *params = json_out_new(tmpctx);
718 const jsmntok_t *result;
719 const char *buf;
720 const jsmntok_t *datastore, *t;
721 size_t i;
722
723 onchain_fees->by_account = tal(onchain_fees, struct ofees_hash);
724 ofees_hash_init(onchain_fees->by_account);
725 tal_add_destructor(onchain_fees->by_account, ofees_hash_destroy);
726 memleak_add_helper(onchain_fees->by_account, memleak_scan_ofees_hash);
727
728 json_out_start(params, NULL, '{');
729 json_out_start(params, "key", '[');
730 json_out_addstr(params, NULL, "bookkeeper");
731 json_out_addstr(params, NULL, "onchain_fee");
732 json_out_end(params, ']');
733 json_out_end(params, '}');
734 result = jsonrpc_request_sync(tmpctx, init_cmd,
735 "listdatastore",
736 params, &buf);
737
738 datastore = json_get_member(buf, result, "datastore");
739 json_for_each_arr(i, t, datastore) {
740 size_t datalen;
741 const jsmntok_t *key, *datatok;
742 const u8 *data;
743
744 /* Key is an array, first two elements are bookkeeper, onchain_fee */
745 key = json_get_member(buf, t, "key") + 3;
746 datatok = json_get_member(buf, t, "hex");
747 /* In case someone creates a subdir? */
748 if (!datatok)
749 continue;
750
751 data = json_tok_bin_from_hex(tmpctx, buf, datatok);
752 datalen = tal_bytelen(data);
753
754 while (datalen != 0) {
755 if (!fromwire_onchain_fee(onchain_fees, &data, &datalen))
756 plugin_err(init_cmd->plugin,
757 "Invalid onchain_fee for %.*s in datastore",
758 json_tok_full_len(key),
759 json_tok_full(buf, key));
760 }
761 }
762 return onchain_fees;
763}

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_onchain_feeFunction · 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