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

Function json_preapprovekeysend

lightningd/invoice.c:1920–1970  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1918AUTODATA(json_command, &preapproveinvoice_command);
1919
1920static struct command_result *json_preapprovekeysend(struct command *cmd,
1921 const char *buffer,
1922 const jsmntok_t *obj UNNEEDED,
1923 const jsmntok_t *params)
1924{
1925 struct node_id *destination;
1926 struct sha256 *payment_hash;
1927 struct amount_msat *amount;
1928 struct json_stream *response;
1929 bool approved;
1930 const u8 *msg;
1931 u8 *req;
1932
1933 if (!param_check(cmd, buffer, params,
1934 p_req("destination", param_node_id, &destination),
1935 p_req("payment_hash", param_sha256, &payment_hash),
1936 p_req("amount_msat", param_msat, &amount),
1937 NULL))
1938 return command_param_failed();
1939
1940 if (!hsm_capable(cmd->ld, WIRE_HSMD_PREAPPROVE_KEYSEND_CHECK)) {
1941 /* We can't just check this, so "succeed". Log message for
1942 * tests though */
1943 if (command_check_only(cmd)) {
1944 log_debug(cmd->ld->log, "hsmd too old to check preapprove");
1945 return command_check_done(cmd);
1946 }
1947 req = towire_hsmd_preapprove_keysend(NULL, destination, payment_hash, *amount);
1948 } else {
1949 req = towire_hsmd_preapprove_keysend_check(NULL, destination, payment_hash,
1950 *amount, command_check_only(cmd));
1951 }
1952
1953 msg = hsm_sync_req(tmpctx, cmd->ld, take(req));
1954
1955 /* These are identical, but use separate numbers for clarity */
1956 if (!fromwire_hsmd_preapprove_keysend_reply(msg, &approved)
1957 && !fromwire_hsmd_preapprove_keysend_check_reply(msg, &approved)) {
1958 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1959 "HSM gave bad preapprove_keysend_reply %s", tal_hex(msg, msg));
1960 }
1961
1962 if (!approved)
1963 return command_fail(cmd, PAY_KEYSEND_PREAPPROVAL_DECLINED, "keysend was declined");
1964
1965 if (command_check_only(cmd))
1966 return command_check_done(cmd);
1967
1968 response = json_stream_success(cmd);
1969 return command_success(cmd, response);
1970}
1971
1972static const struct json_command preapprovekeysend_command = {
1973 "preapprovekeysend",

Callers

nothing calls this directly

Calls 14

param_checkFunction · 0.85
tal_hexFunction · 0.85
command_param_failedFunction · 0.70
hsm_capableFunction · 0.70
command_check_onlyFunction · 0.70
command_check_doneFunction · 0.70
hsm_sync_reqFunction · 0.70
command_failFunction · 0.70

Tested by

no test coverage detected