| 247 | } |
| 248 | |
| 249 | static struct command_result *json_dev(struct command *cmd UNUSED, |
| 250 | const char *buffer, |
| 251 | const jsmntok_t *obj UNNEEDED, |
| 252 | const jsmntok_t *params) |
| 253 | { |
| 254 | const char *subcmd; |
| 255 | |
| 256 | subcmd = param_subcommand(cmd, buffer, params, |
| 257 | "crash", "rhash", "slowcmd", NULL); |
| 258 | if (!subcmd) |
| 259 | return command_param_failed(); |
| 260 | |
| 261 | if (streq(subcmd, "crash")) { |
| 262 | if (!param(cmd, buffer, params, |
| 263 | p_req("subcommand", param_ignore, cmd), |
| 264 | NULL)) |
| 265 | return command_param_failed(); |
| 266 | fatal("Crash at user request"); |
| 267 | } else if (streq(subcmd, "slowcmd")) { |
| 268 | struct slowcmd *sc = tal(cmd, struct slowcmd); |
| 269 | |
| 270 | sc->cmd = cmd; |
| 271 | if (!param(cmd, buffer, params, |
| 272 | p_req("subcommand", param_ignore, cmd), |
| 273 | p_opt_def("msec", param_number, &sc->msec, 1000), |
| 274 | NULL)) |
| 275 | return command_param_failed(); |
| 276 | |
| 277 | new_reltimer(cmd->ld->timers, sc, time_from_msec(0), |
| 278 | slowcmd_start, sc); |
| 279 | return command_still_pending(cmd); |
| 280 | } else { |
| 281 | assert(streq(subcmd, "rhash")); |
| 282 | struct json_stream *response; |
| 283 | struct sha256 *secret; |
| 284 | |
| 285 | if (!param(cmd, buffer, params, |
| 286 | p_req("subcommand", param_ignore, cmd), |
| 287 | p_req("secret", param_sha256, &secret), |
| 288 | NULL)) |
| 289 | return command_param_failed(); |
| 290 | |
| 291 | /* Hash in place. */ |
| 292 | sha256(secret, secret, sizeof(*secret)); |
| 293 | response = json_stream_success(cmd); |
| 294 | json_add_sha256(response, "rhash", secret); |
| 295 | return command_success(cmd, response); |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | static const struct json_command dev_command = { |
| 300 | "dev", |
nothing calls this directly
no test coverage detected