| 1946 | AUTODATA(json_command, &preapprovekeysend_command); |
| 1947 | |
| 1948 | static struct command_result *json_signinvoice(struct command *cmd, |
| 1949 | const char *buffer, |
| 1950 | const jsmntok_t *obj UNNEEDED, |
| 1951 | const jsmntok_t *params) |
| 1952 | { |
| 1953 | const char *invstring; |
| 1954 | struct json_stream *response; |
| 1955 | struct bolt11 *b11; |
| 1956 | struct sha256 hash; |
| 1957 | const u5 *sig; |
| 1958 | bool have_n; |
| 1959 | const char *fail; |
| 1960 | |
| 1961 | if (!param_check(cmd, buffer, params, |
| 1962 | p_req("invstring", param_invstring, &invstring), |
| 1963 | NULL)) |
| 1964 | return command_param_failed(); |
| 1965 | |
| 1966 | b11 = bolt11_decode_nosig(cmd, invstring, cmd->ld->our_features, |
| 1967 | NULL, chainparams, &hash, &sig, &have_n, |
| 1968 | &fail); |
| 1969 | |
| 1970 | if (!b11) |
| 1971 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1972 | "Unparsable invoice '%s': %s", |
| 1973 | invstring, fail); |
| 1974 | |
| 1975 | /* This adds the signature */ |
| 1976 | char *b11enc = bolt11_encode(cmd, b11, have_n, |
| 1977 | hsm_sign_b11, cmd->ld); |
| 1978 | |
| 1979 | /* BOLT #11: |
| 1980 | * A writer: |
| 1981 | *... |
| 1982 | * - MUST include either exactly one `d` or exactly one `h` field. |
| 1983 | */ |
| 1984 | if (!b11->description && !b11->description_hash) |
| 1985 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1986 | "Missing description in invoice"); |
| 1987 | |
| 1988 | if (command_check_only(cmd)) |
| 1989 | return command_check_done(cmd); |
| 1990 | |
| 1991 | response = json_stream_success(cmd); |
| 1992 | json_add_invstring(response, b11enc); |
| 1993 | return command_success(cmd, response); |
| 1994 | } |
| 1995 | |
| 1996 | static const struct json_command signinvoice_command = { |
| 1997 | "signinvoice", |
nothing calls this directly
no test coverage detected