Skip to content

Commit

Permalink
pay: move preapproveinvoice command out so it can be called bu check.
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <[email protected]>
Changelog-Added: JSON-RPC: `check` `keysend` now checks with HSM that it will approve it (use instead of `preapprovekeysend`).
  • Loading branch information
rustyrussell committed Feb 27, 2024
1 parent 85edde4 commit 1fb80a3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
1 change: 0 additions & 1 deletion plugins/libplugin-pay.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,6 @@ REGISTER_PAYMENT_MODIFIER_HEADER(local_channel_hints, void);
* each of those channels can bear. */
REGISTER_PAYMENT_MODIFIER_HEADER(payee_incoming_limit, void);
REGISTER_PAYMENT_MODIFIER_HEADER(route_exclusions, struct route_exclusions_data);
REGISTER_PAYMENT_MODIFIER_HEADER(check_preapproveinvoice, void);


struct payment *payment_new(tal_t *ctx, struct command *cmd,
Expand Down
43 changes: 32 additions & 11 deletions plugins/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,6 @@ payment_listsendpays_previous(struct command *cmd, const char *buf,
}

struct payment_modifier *paymod_mods[] = {
&check_preapproveinvoice_pay_mod,
/* NOTE: The order in which these four paymods are executed is
* significant!
* local_channel_hints *must* execute first before route_exclusions
Expand Down Expand Up @@ -1009,6 +1008,32 @@ static void destroy_payment(struct payment *p)
list_del(&p->list);
}

static struct command_result *
preapproveinvoice_succeed(struct command *cmd,
const char *buf,
const jsmntok_t *result,
struct payment *p)
{
struct out_req *req;

/* Now we can conclude `check` command */
if (command_check_only(cmd)) {
return command_check_done(cmd);
}

list_add_tail(&payments, &p->list);
tal_add_destructor(p, destroy_payment);
/* We're keeping this around now */
tal_steal(cmd->plugin, p);

req = jsonrpc_request_start(cmd->plugin, cmd, "listsendpays",
payment_listsendpays_previous,
payment_listsendpays_previous, p);

json_add_sha256(req->js, "payment_hash", p->payment_hash);
return send_outreq(cmd->plugin, req);
}

static struct command_result *json_pay(struct command *cmd,
const char *buf,
const jsmntok_t *params)
Expand All @@ -1035,7 +1060,7 @@ static struct command_result *json_pay(struct command *cmd,
/* If any of the modifiers need to add params to the JSON-RPC call we
* would add them to the `param()` call below, and have them be
* initialized directly that way. */
if (!param(cmd, buf, params,
if (!param_check(cmd, buf, params,
/* FIXME: parameter should be invstring now */
p_req("bolt11", param_invstring, &b11str),
p_opt("amount_msat", param_msat, &msat),
Expand Down Expand Up @@ -1256,16 +1281,12 @@ static struct command_result *json_pay(struct command *cmd,
tal_free(dev_use_shadow);

p->label = tal_steal(p, label);
list_add_tail(&payments, &p->list);
tal_add_destructor(p, destroy_payment);
/* We're keeping this around now */
tal_steal(cmd->plugin, p);

req = jsonrpc_request_start(cmd->plugin, cmd, "listsendpays",
payment_listsendpays_previous,
payment_listsendpays_previous, p);

json_add_sha256(req->js, "payment_hash", p->payment_hash);
/* Now preapprove, then start payment. */
req = jsonrpc_request_start(p->plugin, cmd, "preapproveinvoice",
&preapproveinvoice_succeed,
&forward_error, p);
json_add_string(req->js, "bolt11", p->invstring);
return send_outreq(cmd->plugin, req);
}

Expand Down

0 comments on commit 1fb80a3

Please sign in to comment.