| 711 | } |
| 712 | |
| 713 | struct 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 | } |
no test coverage detected