| 276 | } |
| 277 | |
| 278 | static struct command_result *json_recover(struct command *cmd, |
| 279 | const char *buffer, |
| 280 | const jsmntok_t *obj UNNEEDED, |
| 281 | const jsmntok_t *params) |
| 282 | { |
| 283 | const char *dir, *hsm_secret; |
| 284 | |
| 285 | if (!param_check(cmd, buffer, params, |
| 286 | p_req("hsmsecret", param_hsm_secret, &hsm_secret), |
| 287 | NULL)) |
| 288 | return command_param_failed(); |
| 289 | |
| 290 | /* FIXME: How do we "move" the Postgres DB? */ |
| 291 | if (!streq(cmd->ld->wallet->db->config->name, "sqlite3")) |
| 292 | return command_fail(cmd, LIGHTNINGD, |
| 293 | "Only sqlite3 supported for recover command"); |
| 294 | |
| 295 | /* Check this is an empty node! */ |
| 296 | if (db_get_intvar(cmd->ld->wallet->db, "bip32_max_index", 0) != 0 |
| 297 | || db_get_intvar(cmd->ld->wallet->db, "bip86_max_index", 0) != 0) { |
| 298 | return command_fail(cmd, RECOVER_NODE_IN_USE, |
| 299 | "Node has already issued bitcoin addresses!"); |
| 300 | } |
| 301 | |
| 302 | if (have_channels(cmd->ld)) { |
| 303 | return command_fail(cmd, RECOVER_NODE_IN_USE, |
| 304 | "Node has channels!"); |
| 305 | } |
| 306 | |
| 307 | /* Don't try to add --recover to cmdline twice! */ |
| 308 | if (cmd->ld->recover != NULL) { |
| 309 | return command_fail(cmd, RECOVER_NODE_IN_USE, |
| 310 | "Already doing recover"); |
| 311 | } |
| 312 | |
| 313 | if (command_check_only(cmd)) |
| 314 | return command_check_done(cmd); |
| 315 | |
| 316 | dir = tal_fmt(tmpctx, "lightning.pre-recover.%u", getpid()); |
| 317 | log_unusual(cmd->ld->log, |
| 318 | "JSON-RPC recovery command: moving existing files to %s", dir); |
| 319 | |
| 320 | move_prerecover_files(dir); |
| 321 | |
| 322 | /* Top level hands this to our re-exec'd self */ |
| 323 | cmd->ld->recover_secret = tal_steal(cmd->ld, hsm_secret); |
| 324 | cmd->ld->try_reexec = true; |
| 325 | return prepare_stop_conn(cmd, "Recovery restart in progress"); |
| 326 | } |
| 327 | |
| 328 | static const struct json_command recover_command = { |
| 329 | "recover", |
nothing calls this directly
no test coverage detected