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