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