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

Function datastore_list_success

plugins/funder.c:940–1008  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

938}
939
940static struct command_result *
941datastore_list_success(struct command *cmd,
942 const char *method,
943 const char *buf,
944 const jsmntok_t *result,
945 struct open_info *info)
946{
947 struct out_req *req;
948 const char *key, *err;
949 const u8 *utxos_bin;
950 size_t len, i;
951 const jsmntok_t *ds_arr_tok, *ds_result;
952
953 ds_arr_tok = json_get_member(buf, result, "datastore");
954 assert(ds_arr_tok->type == JSMN_ARRAY);
955
956 /* There should only be one result */
957 utxos_bin = NULL;
958 json_for_each_arr(i, ds_result, ds_arr_tok) {
959 err = json_scan(tmpctx, buf, ds_result,
960 "{key:%,hex:%}",
961 JSON_SCAN_TAL(cmd, json_strdup, &key),
962 JSON_SCAN_TAL(cmd, json_tok_bin_from_hex,
963 &utxos_bin));
964
965 if (err)
966 plugin_err(cmd->plugin,
967 "`listdatastore` payload did"
968 " not scan. %s: %.*s",
969 err, json_tok_full_len(result),
970 json_tok_full(buf, result));
971
972 /* We found the prev utxo list */
973 plugin_log(cmd->plugin, LOG_DBG,
974 "Saved utxos for channel (%s)"
975 " pulled from datastore", key);
976
977 /* There should only be one result */
978 break;
979 }
980
981 /* Resurrect outpoints from stashed binary */
982 len = tal_bytelen(utxos_bin);
983 while (len > 0) {
984 struct bitcoin_outpoint *outpoint =
985 tal(info, struct bitcoin_outpoint);
986 fromwire_bitcoin_outpoint(&utxos_bin,
987 &len, outpoint);
988 /* Cursor gets set to null if above fails */
989 if (!utxos_bin)
990 plugin_err(cmd->plugin,
991 "Unable to parse saved utxos: %.*s",
992 json_tok_full_len(result),
993 json_tok_full(buf, result));
994
995 if (!info->prev_outs)
996 info->prev_outs =
997 tal_arr(info, struct bitcoin_outpoint *, 0);

Callers

nothing calls this directly

Calls 9

json_get_memberFunction · 0.85
tal_bytelenFunction · 0.85
plugin_errFunction · 0.70
plugin_logFunction · 0.70
send_outreqFunction · 0.70
json_scanFunction · 0.50
json_tok_full_lenFunction · 0.50
json_tok_fullFunction · 0.50

Tested by

no test coverage detected