| 1832 | AUTODATA(json_command, &createinvoice_command); |
| 1833 | |
| 1834 | static struct command_result *json_preapproveinvoice(struct command *cmd, |
| 1835 | const char *buffer, |
| 1836 | const jsmntok_t *obj UNNEEDED, |
| 1837 | const jsmntok_t *params) |
| 1838 | { |
| 1839 | const char *invstring; |
| 1840 | struct json_stream *response; |
| 1841 | bool approved; |
| 1842 | u8 *req; |
| 1843 | const u8 *msg; |
| 1844 | |
| 1845 | if (!param_check(cmd, buffer, params, |
| 1846 | /* FIXME: parameter should be invstring now */ |
| 1847 | p_req("bolt11", param_invstring, &invstring), |
| 1848 | NULL)) |
| 1849 | return command_param_failed(); |
| 1850 | |
| 1851 | /* Old version didn't have `bool check_only` at end */ |
| 1852 | if (!hsm_capable(cmd->ld, WIRE_HSMD_PREAPPROVE_INVOICE_CHECK)) { |
| 1853 | /* We can't just check this, so "succeed". Log message for |
| 1854 | * tests though */ |
| 1855 | if (command_check_only(cmd)) { |
| 1856 | log_debug(cmd->ld->log, "hsmd too old to check preapprove"); |
| 1857 | return command_check_done(cmd); |
| 1858 | } |
| 1859 | req = towire_hsmd_preapprove_invoice(NULL, invstring); |
| 1860 | } else { |
| 1861 | req = towire_hsmd_preapprove_invoice_check(NULL, invstring, |
| 1862 | command_check_only(cmd)); |
| 1863 | } |
| 1864 | |
| 1865 | msg = hsm_sync_req(tmpctx, cmd->ld, take(req)); |
| 1866 | |
| 1867 | /* These are identical, but use separate numbers for clarity */ |
| 1868 | if (!fromwire_hsmd_preapprove_invoice_reply(msg, &approved) |
| 1869 | && !fromwire_hsmd_preapprove_invoice_check_reply(msg, &approved)) { |
| 1870 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1871 | "HSM gave bad preapprove_invoice_reply %s", tal_hex(msg, msg)); |
| 1872 | } |
| 1873 | |
| 1874 | if (!approved) |
| 1875 | return command_fail(cmd, PAY_INVOICE_PREAPPROVAL_DECLINED, "invoice was declined"); |
| 1876 | |
| 1877 | if (command_check_only(cmd)) |
| 1878 | return command_check_done(cmd); |
| 1879 | |
| 1880 | response = json_stream_success(cmd); |
| 1881 | return command_success(cmd, response); |
| 1882 | } |
| 1883 | |
| 1884 | static const struct json_command preapproveinvoice_command = { |
| 1885 | "preapproveinvoice", |
nothing calls this directly
no test coverage detected