mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-15 11:04:20 +01:00
hsmd: add hsmd_preapprove_keysend and check_preapprovekeysend pay modifier
Changelog-added: hsmd: A new message `hsmd_preapprove_keysend` is added. Changelog-added: JSON-RPC: A new command `preapprovekeysend` is added.
This commit is contained in:
@@ -1853,3 +1853,47 @@ static const struct json_command preapproveinvoice_command = {
|
||||
"Ask the HSM to preapprove an invoice."
|
||||
};
|
||||
AUTODATA(json_command, &preapproveinvoice_command);
|
||||
|
||||
static struct command_result *json_preapprovekeysend(struct command *cmd,
|
||||
const char *buffer,
|
||||
const jsmntok_t *obj UNNEEDED,
|
||||
const jsmntok_t *params)
|
||||
{
|
||||
struct node_id *destination;
|
||||
struct sha256 *payment_hash;
|
||||
struct amount_msat *amount;
|
||||
|
||||
struct json_stream *response;
|
||||
bool approved;
|
||||
|
||||
if (!param(cmd, buffer, params,
|
||||
p_req("destination", param_node_id, &destination),
|
||||
p_req("payment_hash", param_sha256, &payment_hash),
|
||||
p_req("amount_msat|msatoshi", param_msat, &amount),
|
||||
NULL))
|
||||
return command_param_failed();
|
||||
|
||||
u8 *msg = towire_hsmd_preapprove_keysend(NULL, destination, payment_hash, *amount);
|
||||
|
||||
if (!wire_sync_write(cmd->ld->hsm_fd, take(msg)))
|
||||
fatal("Could not write to HSM: %s", strerror(errno));
|
||||
|
||||
msg = wire_sync_read(tmpctx, cmd->ld->hsm_fd);
|
||||
if (!fromwire_hsmd_preapprove_keysend_reply(msg, &approved))
|
||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"HSM gave bad preapprove_keysend_reply %s", tal_hex(msg, msg));
|
||||
|
||||
if (!approved)
|
||||
return command_fail(cmd, PAY_KEYSEND_PREAPPROVAL_DECLINED, "keysend was declined");
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
|
||||
static const struct json_command preapprovekeysend_command = {
|
||||
"preapprovekeysend",
|
||||
"payment",
|
||||
json_preapprovekeysend,
|
||||
"Ask the HSM to preapprove a keysend payment."
|
||||
};
|
||||
AUTODATA(json_command, &preapprovekeysend_command);
|
||||
|
||||
@@ -258,6 +258,9 @@ bool fromwire_hsmd_sign_bolt12_reply(const void *p UNNEEDED, struct bip340sig *s
|
||||
/* Generated stub for fromwire_hsmd_preapprove_invoice_reply */
|
||||
bool fromwire_hsmd_preapprove_invoice_reply(const void *p UNNEEDED, bool *approved UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_hsmd_preapprove_invoice_reply called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_hsmd_preapprove_keysend_reply */
|
||||
bool fromwire_hsmd_preapprove_keysend_reply(const void *p UNNEEDED, bool *approved UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_hsmd_preapprove_keysend_reply called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_hsmd_sign_commitment_tx_reply */
|
||||
bool fromwire_hsmd_sign_commitment_tx_reply(const void *p UNNEEDED, struct bitcoin_signature *sig UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_hsmd_sign_commitment_tx_reply called!\n"); abort(); }
|
||||
@@ -783,6 +786,9 @@ u8 *towire_hsmd_sign_bolt12(const tal_t *ctx UNNEEDED, const wirestring *message
|
||||
/* Generated stub for towire_hsmd_preapprove_invoice */
|
||||
u8 *towire_hsmd_preapprove_invoice(const tal_t *ctx UNNEEDED, const wirestring *invstring UNNEEDED)
|
||||
{ fprintf(stderr, "towire_hsmd_preapprove_invoice called!\n"); abort(); }
|
||||
/* Generated stub for towire_hsmd_preapprove_keysend */
|
||||
u8 *towire_hsmd_preapprove_keysend(const tal_t *ctx UNNEEDED, const struct node_id *destination UNNEEDED, const struct sha256 *payment_hash UNNEEDED, struct amount_msat amount UNNEEDED)
|
||||
{ fprintf(stderr, "towire_hsmd_preapprove_keysend called!\n"); abort(); }
|
||||
/* Generated stub for towire_hsmd_sign_commitment_tx */
|
||||
u8 *towire_hsmd_sign_commitment_tx(const tal_t *ctx UNNEEDED, const struct node_id *peer_id UNNEEDED, u64 channel_dbid UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const struct pubkey *remote_funding_key UNNEEDED, u64 commit_num UNNEEDED)
|
||||
{ fprintf(stderr, "towire_hsmd_sign_commitment_tx called!\n"); abort(); }
|
||||
|
||||
Reference in New Issue
Block a user