| 952 | } |
| 953 | |
| 954 | static 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, ×tamp, &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 | |
| 997 | static struct command_result *json_restorefrompeer(struct command *cmd, |
| 998 | const char *buf, |
nothing calls this directly
no test coverage detected