MCPcopy Create free account
hub / github.com/ElementsProject/lightning / json_signinvoice

Function json_signinvoice

lightningd/invoice.c:1948–1994  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1946AUTODATA(json_command, &preapprovekeysend_command);
1947
1948static 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
1996static const struct json_command signinvoice_command = {
1997 "signinvoice",

Callers

nothing calls this directly

Calls 9

param_checkFunction · 0.85
bolt11_decode_nosigFunction · 0.85
json_add_invstringFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
command_check_onlyFunction · 0.70
command_check_doneFunction · 0.70
json_stream_successFunction · 0.70
command_successFunction · 0.70

Tested by

no test coverage detected