| 3754 | tal_free(to_delete); |
| 3755 | } |
| 3756 | static struct command_result *json_waitblockheight(struct command *cmd, |
| 3757 | const char *buffer, |
| 3758 | const jsmntok_t *obj, |
| 3759 | const jsmntok_t *params) |
| 3760 | { |
| 3761 | unsigned int *target_block_height; |
| 3762 | u32 block_height; |
| 3763 | unsigned int *timeout; |
| 3764 | struct waitblockheight_waiter *w; |
| 3765 | |
| 3766 | if (!param(cmd, buffer, params, |
| 3767 | p_req("blockheight", param_number, &target_block_height), |
| 3768 | p_opt_def("timeout", param_number, &timeout, 60), |
| 3769 | NULL)) |
| 3770 | return command_param_failed(); |
| 3771 | |
| 3772 | /* Check if already reached anyway. */ |
| 3773 | block_height = get_block_height(cmd->ld->topology); |
| 3774 | if (*target_block_height <= block_height) |
| 3775 | return waitblockheight_complete(cmd, block_height); |
| 3776 | |
| 3777 | /* Create a new waitblockheight command. */ |
| 3778 | w = tal(cmd, struct waitblockheight_waiter); |
| 3779 | tal_add_destructor(w, &destroy_waitblockheight_waiter); |
| 3780 | list_add(&cmd->ld->waitblockheight_commands, &w->list); |
| 3781 | w->cmd = cmd; |
| 3782 | w->block_height = *target_block_height; |
| 3783 | w->removed = false; |
| 3784 | /* Install the timeout. */ |
| 3785 | (void) new_reltimer(cmd->ld->timers, w, time_from_sec(*timeout), |
| 3786 | &timeout_waitblockheight_waiter, w); |
| 3787 | |
| 3788 | return command_still_pending(cmd); |
| 3789 | } |
| 3790 | |
| 3791 | static const struct json_command waitblockheight_command = { |
| 3792 | "waitblockheight", |
nothing calls this directly
no test coverage detected