| 1606 | } |
| 1607 | |
| 1608 | static struct command_result *json_check(struct command *cmd, |
| 1609 | const char *buffer, |
| 1610 | const jsmntok_t *obj, |
| 1611 | const jsmntok_t *params) |
| 1612 | { |
| 1613 | jsmntok_t *mod_params; |
| 1614 | const jsmntok_t *name_tok; |
| 1615 | struct command_result *res; |
| 1616 | struct lightningd *ld = cmd->ld; |
| 1617 | |
| 1618 | if (cmd->mode == CMD_USAGE) { |
| 1619 | mod_params = NULL; |
| 1620 | } else { |
| 1621 | mod_params = json_tok_copy(cmd, params); |
| 1622 | } |
| 1623 | |
| 1624 | /* Replaces cmd->json_cmd: */ |
| 1625 | if (!param(cmd, buffer, mod_params, |
| 1626 | p_req("command_to_check", param_command, &name_tok), |
| 1627 | p_opt_any(), |
| 1628 | NULL)) |
| 1629 | return command_param_failed(); |
| 1630 | |
| 1631 | cmd->mode = CMD_CHECK; |
| 1632 | /* Make *sure* it doesn't try to manip db! */ |
| 1633 | db_set_readonly(ld->wallet->db, true); |
| 1634 | |
| 1635 | /* Raw check hook is needed for plugins */ |
| 1636 | if (cmd->json_cmd->check) { |
| 1637 | res = cmd->json_cmd->check(cmd, buffer, obj, params); |
| 1638 | } else { |
| 1639 | /* Point name_tok to the name, not the value */ |
| 1640 | if (params->type == JSMN_OBJECT) |
| 1641 | name_tok--; |
| 1642 | |
| 1643 | json_tok_remove(&mod_params, mod_params, name_tok, 1); |
| 1644 | |
| 1645 | res = cmd->json_cmd->dispatch(cmd, buffer, mod_params, mod_params); |
| 1646 | } |
| 1647 | db_set_readonly(ld->wallet->db, false); |
| 1648 | |
| 1649 | return res; |
| 1650 | } |
| 1651 | |
| 1652 | static const struct json_command check_command = { |
| 1653 | "check", |
nothing calls this directly
no test coverage detected