| 981 | } |
| 982 | |
| 983 | static struct command_result * |
| 984 | datastore_list_success(struct command *cmd, |
| 985 | const char *method, |
| 986 | const char *buf, |
| 987 | const jsmntok_t *result, |
| 988 | struct open_info *info) |
| 989 | { |
| 990 | const char *key, *err; |
| 991 | const u8 *utxos_bin; |
| 992 | size_t len, i; |
| 993 | const jsmntok_t *ds_arr_tok, *ds_result; |
| 994 | |
| 995 | ds_arr_tok = json_get_member(buf, result, "datastore"); |
| 996 | assert(ds_arr_tok->type == JSMN_ARRAY); |
| 997 | |
| 998 | /* There should only be one result */ |
| 999 | utxos_bin = NULL; |
| 1000 | json_for_each_arr(i, ds_result, ds_arr_tok) { |
| 1001 | err = json_scan(tmpctx, buf, ds_result, |
| 1002 | "{key:%,hex:%}", |
| 1003 | JSON_SCAN_TAL(cmd, json_strdup, &key), |
| 1004 | JSON_SCAN_TAL(cmd, json_tok_bin_from_hex, |
| 1005 | &utxos_bin)); |
| 1006 | |
| 1007 | if (err) |
| 1008 | plugin_err(cmd->plugin, |
| 1009 | "`listdatastore` payload did" |
| 1010 | " not scan. %s: %.*s", |
| 1011 | err, json_tok_full_len(result), |
| 1012 | json_tok_full(buf, result)); |
| 1013 | |
| 1014 | /* We found the prev utxo list */ |
| 1015 | plugin_log(cmd->plugin, LOG_DBG, |
| 1016 | "Saved utxos for channel (%s)" |
| 1017 | " pulled from datastore", key); |
| 1018 | |
| 1019 | /* There should only be one result */ |
| 1020 | break; |
| 1021 | } |
| 1022 | |
| 1023 | /* Resurrect outpoints from stashed binary */ |
| 1024 | len = tal_bytelen(utxos_bin); |
| 1025 | while (len > 0) { |
| 1026 | struct bitcoin_outpoint *outpoint = |
| 1027 | tal(info, struct bitcoin_outpoint); |
| 1028 | fromwire_bitcoin_outpoint(&utxos_bin, |
| 1029 | &len, outpoint); |
| 1030 | /* Cursor gets set to null if above fails */ |
| 1031 | if (!utxos_bin) |
| 1032 | plugin_err(cmd->plugin, |
| 1033 | "Unable to parse saved utxos: %.*s", |
| 1034 | json_tok_full_len(result), |
| 1035 | json_tok_full(buf, result)); |
| 1036 | |
| 1037 | if (!info->prev_outs) |
| 1038 | info->prev_outs = |
| 1039 | tal_arr(info, struct bitcoin_outpoint *, 0); |
| 1040 |
nothing calls this directly
no test coverage detected