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

Function json_signinvoice

lightningd/invoice.c:1969–2015  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1967AUTODATA(json_command, &preapprovekeysend_command);
1968
1969static struct command_result *json_signinvoice(struct command *cmd,
1970 const char *buffer,
1971 const jsmntok_t *obj UNNEEDED,
1972 const jsmntok_t *params)
1973{
1974 const char *invstring;
1975 struct json_stream *response;
1976 struct bolt11 *b11;
1977 struct sha256 hash;
1978 const u5 *sig;
1979 bool have_n;
1980 const char *fail;
1981
1982 if (!param_check(cmd, buffer, params,
1983 p_req("invstring", param_invstring, &invstring),
1984 NULL))
1985 return command_param_failed();
1986
1987 b11 = bolt11_decode_nosig(cmd, invstring, cmd->ld->our_features,
1988 NULL, chainparams, &hash, &sig, &have_n,
1989 &fail);
1990
1991 if (!b11)
1992 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1993 "Unparsable invoice '%s': %s",
1994 invstring, fail);
1995
1996 /* This adds the signature */
1997 char *b11enc = bolt11_encode(cmd, b11, have_n,
1998 hsm_sign_b11, cmd->ld);
1999
2000 /* BOLT #11:
2001 * A writer:
2002 *...
2003 * - MUST include either exactly one `d` or exactly one `h` field.
2004 */
2005 if (!b11->description && !b11->description_hash)
2006 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
2007 "Missing description in invoice");
2008
2009 if (command_check_only(cmd))
2010 return command_check_done(cmd);
2011
2012 response = json_stream_success(cmd);
2013 json_add_invstring(response, b11enc);
2014 return command_success(cmd, response);
2015}
2016
2017static const struct json_command signinvoice_command = {
2018 "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