| 351 | } |
| 352 | |
| 353 | static struct command_result *json_dev(struct command *cmd UNUSED, |
| 354 | const char *buffer, |
| 355 | const jsmntok_t *obj UNNEEDED, |
| 356 | const jsmntok_t *params) |
| 357 | { |
| 358 | const char *subcmd; |
| 359 | |
| 360 | subcmd = param_subcommand(cmd, buffer, params, |
| 361 | "crash", "rhash", "slowcmd", NULL); |
| 362 | if (!subcmd) |
| 363 | return command_param_failed(); |
| 364 | |
| 365 | if (streq(subcmd, "crash")) { |
| 366 | if (!param(cmd, buffer, params, |
| 367 | p_req("subcommand", param_ignore, cmd), |
| 368 | NULL)) |
| 369 | return command_param_failed(); |
| 370 | fatal("Crash at user request"); |
| 371 | } else if (streq(subcmd, "slowcmd")) { |
| 372 | struct slowcmd *sc = tal(cmd, struct slowcmd); |
| 373 | |
| 374 | sc->cmd = cmd; |
| 375 | if (!param(cmd, buffer, params, |
| 376 | p_req("subcommand", param_ignore, cmd), |
| 377 | p_opt_def("msec", param_number, &sc->msec, 1000), |
| 378 | NULL)) |
| 379 | return command_param_failed(); |
| 380 | |
| 381 | new_reltimer(cmd->ld->timers, sc, time_from_msec(0), |
| 382 | slowcmd_start, sc); |
| 383 | return command_still_pending(cmd); |
| 384 | } else { |
| 385 | assert(streq(subcmd, "rhash")); |
| 386 | struct json_stream *response; |
| 387 | struct sha256 *secret; |
| 388 | |
| 389 | if (!param(cmd, buffer, params, |
| 390 | p_req("subcommand", param_ignore, cmd), |
| 391 | p_req("secret", param_sha256, &secret), |
| 392 | NULL)) |
| 393 | return command_param_failed(); |
| 394 | |
| 395 | /* Hash in place. */ |
| 396 | sha256(secret, secret, sizeof(*secret)); |
| 397 | response = json_stream_success(cmd); |
| 398 | json_add_sha256(response, "rhash", secret); |
| 399 | return command_success(cmd, response); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | static const struct json_command dev_command = { |
| 404 | "dev", |
nothing calls this directly
no test coverage detected