| 2399 | tal_free(to_delete); |
| 2400 | } |
| 2401 | static struct command_result *json_waitblockheight(struct command *cmd, |
| 2402 | const char *buffer, |
| 2403 | const jsmntok_t *obj, |
| 2404 | const jsmntok_t *params) |
| 2405 | { |
| 2406 | unsigned int *target_block_height; |
| 2407 | u32 block_height; |
| 2408 | unsigned int *timeout; |
| 2409 | struct waitblockheight_waiter *w; |
| 2410 | |
| 2411 | if (!param(cmd, buffer, params, |
| 2412 | p_req("blockheight", param_number, &target_block_height), |
| 2413 | p_opt_def("timeout", param_number, &timeout, 60), |
| 2414 | NULL)) |
| 2415 | return command_param_failed(); |
| 2416 | |
| 2417 | /* Check if already reached anyway. */ |
| 2418 | block_height = get_block_height(cmd->ld->topology); |
| 2419 | if (*target_block_height <= block_height) |
| 2420 | return waitblockheight_complete(cmd, block_height); |
| 2421 | |
| 2422 | /* Create a new waitblockheight command. */ |
| 2423 | w = tal(cmd, struct waitblockheight_waiter); |
| 2424 | tal_add_destructor(w, &destroy_waitblockheight_waiter); |
| 2425 | list_add(&cmd->ld->waitblockheight_commands, &w->list); |
| 2426 | w->cmd = cmd; |
| 2427 | w->block_height = *target_block_height; |
| 2428 | w->removed = false; |
| 2429 | /* Install the timeout. */ |
| 2430 | (void) new_reltimer(cmd->ld->timers, w, time_from_sec(*timeout), |
| 2431 | &timeout_waitblockheight_waiter, w); |
| 2432 | |
| 2433 | return command_still_pending(cmd); |
| 2434 | } |
| 2435 | |
| 2436 | static const struct json_command waitblockheight_command = { |
| 2437 | "waitblockheight", |
nothing calls this directly
no test coverage detected