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

Function after_latestscb

plugins/chanbackup.c:954–995  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

952}
953
954static struct command_result *after_latestscb(struct command *cmd,
955 const u8 *res,
956 void *cb_arg UNUSED)
957{
958 u64 version;
959 u32 timestamp;
960 bool is_converted;
961 struct modern_scb_chan **scb_tlvs;
962 struct json_stream *response;
963 struct out_req *req;
964
965 if (tal_bytelen(res) == 0) {
966 response = jsonrpc_stream_success(cmd);
967
968 json_add_string(response, "result",
969 "No backup received from peers");
970 return command_finished(cmd, response);
971 }
972
973 if (!read_static_chan_backup(cmd, res, &version, &timestamp, &scb_tlvs, &is_converted))
974 return command_fail(cmd, LIGHTNINGD, "Invalid emergencyrecover");
975
976 if ((version & 0x5555555555555555ULL) != (VERSION & 0x5555555555555555ULL)) {
977 plugin_err(cmd->plugin,
978 "Incompatible emergencyrecover version: loaded version %"PRIu64", expected version %"PRIu64". Contact the admin!", version, VERSION);
979 }
980
981 req = jsonrpc_request_start(cmd, "recoverchannel",
982 after_recover_rpc,
983 &forward_error, NULL);
984
985 json_array_start(req->js, "scb");
986 for (size_t i=0; i<tal_count(scb_tlvs); i++) {
987 u8 *scb_hex = tal_arr(cmd, u8, 0);
988 towire_modern_scb_chan(&scb_hex, scb_tlvs[i]);
989 json_add_hex_talarr(req->js, NULL, scb_hex);
990 }
991 json_array_end(req->js);
992
993 return send_outreq(req);
994
995}
996
997static struct command_result *json_restorefrompeer(struct command *cmd,
998 const char *buf,

Callers

nothing calls this directly

Calls 11

tal_bytelenFunction · 0.85
read_static_chan_backupFunction · 0.85
json_array_startFunction · 0.85
json_add_hex_talarrFunction · 0.85
json_array_endFunction · 0.85
jsonrpc_stream_successFunction · 0.70
command_finishedFunction · 0.70
command_failFunction · 0.70
plugin_errFunction · 0.70
send_outreqFunction · 0.70
json_add_stringFunction · 0.50

Tested by

no test coverage detected