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

Function json_emergencyrecover

plugins/chanbackup.c:361–403  ·  view source on GitHub ↗

Recovers the channels by making RPC to `recoverchannel` */

Source from the content-addressed store, hash-verified

359
360/* Recovers the channels by making RPC to `recoverchannel` */
361static struct command_result *json_emergencyrecover(struct command *cmd,
362 const char *buf,
363 const jsmntok_t *params)
364{
365 struct out_req *req;
366 u64 version;
367 u32 timestamp;
368 bool is_converted;
369 struct modern_scb_chan **scb_tlvs;
370
371 if (!param(cmd, buf, params, NULL))
372 return command_param_failed();
373
374 u8 *res = decrypt_scb(cmd->plugin);
375 if (!read_static_chan_backup(cmd, res, &version, &timestamp, &scb_tlvs, &is_converted))
376 return command_fail(cmd, LIGHTNINGD,
377 "Invalid recovery format");
378
379 if ((version & 0x5555555555555555ULL) != (VERSION & 0x5555555555555555ULL)) {
380 plugin_err(cmd->plugin,
381 "Incompatible emergencyrecover version: loaded version %"PRIu64", expected version %"PRIu64". Contact the admin!", version, VERSION);
382 }
383
384 req = jsonrpc_request_start(cmd, "recoverchannel",
385 after_recover_rpc,
386 forward_error, NULL);
387
388 if (is_converted) {
389 plugin_notify_message(cmd, LOG_DBG, "Processing legacy emergency.recover file format. "
390 "Please migrate to the latest file format for improved "
391 "compatibility and fund recovery.");
392 }
393
394 json_array_start(req->js, "scb");
395 for (size_t i=0; i<tal_count(scb_tlvs); i++) {
396 u8 *scb_hex = tal_arr(cmd, u8, 0);
397 towire_modern_scb_chan(&scb_hex, scb_tlvs[i]);
398 json_add_hex_talarr(req->js, NULL, scb_hex);
399 }
400 json_array_end(req->js);
401
402 return send_outreq(req);
403}
404
405static void update_scb(struct plugin *p, struct modern_scb_chan **channels)
406{

Callers

nothing calls this directly

Calls 11

decrypt_scbFunction · 0.85
read_static_chan_backupFunction · 0.85
json_array_startFunction · 0.85
json_add_hex_talarrFunction · 0.85
json_array_endFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
plugin_errFunction · 0.70
plugin_notify_messageFunction · 0.70
send_outreqFunction · 0.70
paramFunction · 0.50

Tested by

no test coverage detected