| 1444 | } |
| 1445 | |
| 1446 | static struct command_result *json_recoverchannel(struct command *cmd, |
| 1447 | const char *buffer, |
| 1448 | const jsmntok_t *obj UNNEEDED, |
| 1449 | const jsmntok_t *params) |
| 1450 | { |
| 1451 | const jsmntok_t *scb, *t; |
| 1452 | size_t i; |
| 1453 | struct json_stream *response; |
| 1454 | struct scb_chan *scb_chan = tal(cmd, struct scb_chan); |
| 1455 | |
| 1456 | if (!param(cmd, buffer, params, |
| 1457 | p_req("scb", param_array, &scb), |
| 1458 | NULL)) |
| 1459 | return command_param_failed(); |
| 1460 | |
| 1461 | response = json_stream_success(cmd); |
| 1462 | |
| 1463 | json_array_start(response, "stubs"); |
| 1464 | json_for_each_arr(i,t,scb){ |
| 1465 | |
| 1466 | char *token = json_strdup(tmpctx, buffer, t); |
| 1467 | const u8 *scb_arr = tal_hexdata(cmd, token, strlen(token)); |
| 1468 | size_t scblen = tal_count(scb_arr); |
| 1469 | |
| 1470 | scb_chan = fromwire_scb_chan(cmd ,&scb_arr, &scblen); |
| 1471 | |
| 1472 | if (scb_chan == NULL) { |
| 1473 | log_broken(cmd->ld->log, "SCB is invalid!"); |
| 1474 | continue; |
| 1475 | } |
| 1476 | |
| 1477 | struct lightningd *ld = cmd->ld; |
| 1478 | struct channel *channel= stub_chan(cmd, |
| 1479 | scb_chan->id, |
| 1480 | scb_chan->node_id, |
| 1481 | scb_chan->cid, |
| 1482 | scb_chan->funding, |
| 1483 | scb_chan->addr, |
| 1484 | scb_chan->funding_sats, |
| 1485 | scb_chan->type); |
| 1486 | |
| 1487 | /* Returns NULL only when channel already exists, so we skip over it. */ |
| 1488 | if (channel == NULL) |
| 1489 | continue; |
| 1490 | |
| 1491 | /* Now we put this in the database. */ |
| 1492 | wallet_channel_insert(ld->wallet, channel); |
| 1493 | |
| 1494 | /* Watch the Funding */ |
| 1495 | channel_watch_funding(ld, channel); |
| 1496 | |
| 1497 | json_add_channel_id(response, NULL, &scb_chan->cid); |
| 1498 | } |
| 1499 | |
| 1500 | /* This will try to reconnect to the peers and start |
| 1501 | * initiating the process */ |
| 1502 | setup_peers(cmd->ld); |
| 1503 |
nothing calls this directly
no test coverage detected