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

Function json_preapprovekeysend

lightningd/invoice.c:1890–1940  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1888AUTODATA(json_command, &preapproveinvoice_command);
1889
1890static struct command_result *json_preapprovekeysend(struct command *cmd,
1891 const char *buffer,
1892 const jsmntok_t *obj UNNEEDED,
1893 const jsmntok_t *params)
1894{
1895 struct node_id *destination;
1896 struct sha256 *payment_hash;
1897 struct amount_msat *amount;
1898 struct json_stream *response;
1899 bool approved;
1900 const u8 *msg;
1901 u8 *req;
1902
1903 if (!param_check(cmd, buffer, params,
1904 p_req("destination", param_node_id, &destination),
1905 p_req("payment_hash", param_sha256, &payment_hash),
1906 p_req("amount_msat", param_msat, &amount),
1907 NULL))
1908 return command_param_failed();
1909
1910 if (!hsm_capable(cmd->ld, WIRE_HSMD_PREAPPROVE_KEYSEND_CHECK)) {
1911 /* We can't just check this, so "succeed". Log message for
1912 * tests though */
1913 if (command_check_only(cmd)) {
1914 log_debug(cmd->ld->log, "hsmd too old to check preapprove");
1915 return command_check_done(cmd);
1916 }
1917 req = towire_hsmd_preapprove_keysend(NULL, destination, payment_hash, *amount);
1918 } else {
1919 req = towire_hsmd_preapprove_keysend_check(NULL, destination, payment_hash,
1920 *amount, command_check_only(cmd));
1921 }
1922
1923 msg = hsm_sync_req(tmpctx, cmd->ld, take(req));
1924
1925 /* These are identical, but use separate numbers for clarity */
1926 if (!fromwire_hsmd_preapprove_keysend_reply(msg, &approved)
1927 && !fromwire_hsmd_preapprove_keysend_check_reply(msg, &approved)) {
1928 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1929 "HSM gave bad preapprove_keysend_reply %s", tal_hex(msg, msg));
1930 }
1931
1932 if (!approved)
1933 return command_fail(cmd, PAY_KEYSEND_PREAPPROVAL_DECLINED, "keysend was declined");
1934
1935 if (command_check_only(cmd))
1936 return command_check_done(cmd);
1937
1938 response = json_stream_success(cmd);
1939 return command_success(cmd, response);
1940}
1941
1942static const struct json_command preapprovekeysend_command = {
1943 "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