| 776 | } |
| 777 | |
| 778 | static struct command_result *json_close(struct command *cmd, |
| 779 | const char *buffer, |
| 780 | const jsmntok_t *obj UNNEEDED, |
| 781 | const jsmntok_t *params) |
| 782 | { |
| 783 | struct channel *channel; |
| 784 | unsigned int *timeout; |
| 785 | const u8 *close_to_script = NULL; |
| 786 | u32 final_key_idx; |
| 787 | struct ext_key final_ext_key; |
| 788 | bool *force_lease_close; |
| 789 | const char *fee_negotiation_step_str; |
| 790 | struct bitcoin_outpoint *wrong_funding; |
| 791 | u32 *feerate_range; |
| 792 | char* end; |
| 793 | bool anysegwit; |
| 794 | struct some_channel *sc = talz(tmpctx, struct some_channel); |
| 795 | |
| 796 | if (!param(cmd, buffer, params, |
| 797 | p_req("id", param_channel_or_peer, &sc), |
| 798 | p_opt_def("unilateraltimeout", param_number, &timeout, |
| 799 | 48 * 3600), |
| 800 | p_opt("destination", param_bitcoin_address, &close_to_script), |
| 801 | p_opt("fee_negotiation_step", param_string, |
| 802 | &fee_negotiation_step_str), |
| 803 | p_opt("wrong_funding", param_outpoint, &wrong_funding), |
| 804 | p_opt_def("force_lease_closed", param_bool, |
| 805 | &force_lease_close, false), |
| 806 | p_opt("feerange", param_feerate_range, &feerate_range), |
| 807 | NULL)) |
| 808 | return command_param_failed(); |
| 809 | |
| 810 | /* Easy cases: peer can simply be forgotten. */ |
| 811 | if (sc->uc) { |
| 812 | kill_uncommitted_channel(sc->uc, "close command called"); |
| 813 | goto discard_unopened; |
| 814 | } |
| 815 | |
| 816 | if (sc->unsaved_channel) { |
| 817 | channel_unsaved_close_conn(sc->unsaved_channel, |
| 818 | "close command called"); |
| 819 | goto discard_unopened; |
| 820 | } |
| 821 | |
| 822 | channel = sc->channel; |
| 823 | assert(channel); |
| 824 | |
| 825 | if (!*force_lease_close && sc->channel->opener != LOCAL |
| 826 | && get_block_height(cmd->ld->topology) < channel->lease_expiry) |
| 827 | return command_fail(cmd, LIGHTNINGD, |
| 828 | "Peer leased this channel from us, we" |
| 829 | " shouldn't close until lease has expired" |
| 830 | " (lease expires block %u," |
| 831 | " current block %u)", |
| 832 | channel->lease_expiry, |
| 833 | get_block_height(cmd->ld->topology)); |
| 834 | |
| 835 | /* Note: we don't change the channel until we're sure we succeed! */ |
nothing calls this directly
no test coverage detected