| 612 | } |
| 613 | |
| 614 | static struct command_result *json_close(struct command *cmd, |
| 615 | const char *buffer, |
| 616 | const jsmntok_t *obj UNNEEDED, |
| 617 | const jsmntok_t *params) |
| 618 | { |
| 619 | struct channel *channel; |
| 620 | unsigned int *timeout; |
| 621 | const u8 *close_to_script = NULL; |
| 622 | u32 final_key_idx; |
| 623 | struct ext_key final_ext_key; |
| 624 | bool *force_lease_close; |
| 625 | const char *fee_negotiation_step_str; |
| 626 | struct bitcoin_outpoint *wrong_funding; |
| 627 | u32 *feerate_range; |
| 628 | char* end; |
| 629 | bool anysegwit; |
| 630 | struct some_channel *sc = talz(tmpctx, struct some_channel); |
| 631 | |
| 632 | if (!param(cmd, buffer, params, |
| 633 | p_req("id", param_channel_or_peer, &sc), |
| 634 | p_opt_def("unilateraltimeout", param_number, &timeout, |
| 635 | 48 * 3600), |
| 636 | p_opt("destination", param_bitcoin_address, &close_to_script), |
| 637 | p_opt("fee_negotiation_step", param_string, |
| 638 | &fee_negotiation_step_str), |
| 639 | p_opt("wrong_funding", param_outpoint, &wrong_funding), |
| 640 | p_opt_def("force_lease_closed", param_bool, |
| 641 | &force_lease_close, false), |
| 642 | p_opt("feerange", param_feerate_range, &feerate_range), |
| 643 | NULL)) |
| 644 | return command_param_failed(); |
| 645 | |
| 646 | /* Easy cases: peer can simply be forgotten. */ |
| 647 | if (sc->uc) { |
| 648 | kill_uncommitted_channel(sc->uc, "close command called"); |
| 649 | goto discard_unopened; |
| 650 | } |
| 651 | |
| 652 | if (sc->unsaved_channel) { |
| 653 | channel_unsaved_close_conn(sc->unsaved_channel, |
| 654 | "close command called"); |
| 655 | goto discard_unopened; |
| 656 | } |
| 657 | |
| 658 | channel = sc->channel; |
| 659 | assert(channel); |
| 660 | |
| 661 | if (!*force_lease_close && sc->channel->opener != LOCAL |
| 662 | && get_block_height(cmd->ld->topology) < channel->lease_expiry) |
| 663 | return command_fail(cmd, LIGHTNINGD, |
| 664 | "Peer leased this channel from us, we" |
| 665 | " shouldn't close until lease has expired" |
| 666 | " (lease expires block %u," |
| 667 | " current block %u)", |
| 668 | channel->lease_expiry, |
| 669 | get_block_height(cmd->ld->topology)); |
| 670 | |
| 671 | /* Note: we don't change the channel until we're sure we succeed! */ |
nothing calls this directly
no test coverage detected