| 1862 | AUTODATA(json_command, &createinvoice_command); |
| 1863 | |
| 1864 | static struct command_result *json_preapproveinvoice(struct command *cmd, |
| 1865 | const char *buffer, |
| 1866 | const jsmntok_t *obj UNNEEDED, |
| 1867 | const jsmntok_t *params) |
| 1868 | { |
| 1869 | const char *invstring; |
| 1870 | struct json_stream *response; |
| 1871 | bool approved; |
| 1872 | u8 *req; |
| 1873 | const u8 *msg; |
| 1874 | |
| 1875 | if (!param_check(cmd, buffer, params, |
| 1876 | /* FIXME: parameter should be invstring now */ |
| 1877 | p_req("bolt11", param_invstring, &invstring), |
| 1878 | NULL)) |
| 1879 | return command_param_failed(); |
| 1880 | |
| 1881 | /* Old version didn't have `bool check_only` at end */ |
| 1882 | if (!hsm_capable(cmd->ld, WIRE_HSMD_PREAPPROVE_INVOICE_CHECK)) { |
| 1883 | /* We can't just check this, so "succeed". Log message for |
| 1884 | * tests though */ |
| 1885 | if (command_check_only(cmd)) { |
| 1886 | log_debug(cmd->ld->log, "hsmd too old to check preapprove"); |
| 1887 | return command_check_done(cmd); |
| 1888 | } |
| 1889 | req = towire_hsmd_preapprove_invoice(NULL, invstring); |
| 1890 | } else { |
| 1891 | req = towire_hsmd_preapprove_invoice_check(NULL, invstring, |
| 1892 | command_check_only(cmd)); |
| 1893 | } |
| 1894 | |
| 1895 | msg = hsm_sync_req(tmpctx, cmd->ld, take(req)); |
| 1896 | |
| 1897 | /* These are identical, but use separate numbers for clarity */ |
| 1898 | if (!fromwire_hsmd_preapprove_invoice_reply(msg, &approved) |
| 1899 | && !fromwire_hsmd_preapprove_invoice_check_reply(msg, &approved)) { |
| 1900 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1901 | "HSM gave bad preapprove_invoice_reply %s", tal_hex(msg, msg)); |
| 1902 | } |
| 1903 | |
| 1904 | if (!approved) |
| 1905 | return command_fail(cmd, PAY_INVOICE_PREAPPROVAL_DECLINED, "invoice was declined"); |
| 1906 | |
| 1907 | if (command_check_only(cmd)) |
| 1908 | return command_check_done(cmd); |
| 1909 | |
| 1910 | response = json_stream_success(cmd); |
| 1911 | return command_success(cmd, response); |
| 1912 | } |
| 1913 | |
| 1914 | static const struct json_command preapproveinvoice_command = { |
| 1915 | "preapproveinvoice", |
nothing calls this directly
no test coverage detected