JSON: add payment_secret parameter to sendpay.

This is not documented yet, since it's ignored unless EXPERIMENTAL_FEATURES
is set.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2019-11-23 10:49:23 +10:30
parent 854c64ffee
commit dfb1f6a096

View File

@ -637,7 +637,8 @@ send_payment(struct lightningd *ld,
const struct route_hop *route,
struct amount_msat msat,
const char *label TAKES,
const char *b11str TAKES)
const char *b11str TAKES,
const struct secret *payment_secret)
{
const u8 *onion;
u8 sessionkey[32];
@ -681,13 +682,11 @@ send_payment(struct lightningd *ld,
ret = pubkey_from_node_id(&pubkey, &ids[i]);
assert(ret);
/* FIXME: This can't fail if payment_secret total_msat == amount, and
* payment_secret is NULL, but it will later when we modify code. */
if (!sphinx_add_final_hop(path, &pubkey,
should_use_tlv(route[i].style),
route[i].amount,
base_expiry + route[i].delay,
route[i].amount, NULL)) {
route[i].amount, payment_secret)) {
return command_fail(cmd, PAY_DESTINATION_PERM_FAIL,
"Destination does not support"
" payment_secret");
@ -831,6 +830,23 @@ static struct command_result *param_route_hop_style(struct command *cmd,
json_tok_full(buffer, tok));
}
static struct command_result *param_secret(struct command *cmd,
const char *name,
const char *buffer,
const jsmntok_t *tok,
struct secret **secret)
{
*secret = tal(cmd, struct secret);
if (hex_decode(buffer + tok->start,
tok->end - tok->start,
*secret, sizeof(**secret)))
return NULL;
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be a 32 byte hex value, not '%.*s'",
name, tok->end - tok->start, buffer + tok->start);
}
static struct command_result *json_sendpay(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
@ -844,6 +860,7 @@ static struct command_result *json_sendpay(struct command *cmd,
struct amount_msat *msat;
const char *b11str, *label = NULL;
struct command_result *res;
struct secret *payment_secret;
/* For generating help, give new-style. */
if (!params || !deprecated_apis) {
@ -853,6 +870,8 @@ static struct command_result *json_sendpay(struct command *cmd,
p_opt("label", param_escaped_string, &label),
p_opt("msatoshi", param_msat, &msat),
p_opt("bolt11", param_string, &b11str),
p_opt("payment_secret", param_secret,
&payment_secret),
NULL))
return command_param_failed();
} else if (params->type == JSMN_ARRAY) {
@ -862,6 +881,8 @@ static struct command_result *json_sendpay(struct command *cmd,
p_opt("label_or_description", param_escaped_string, &label),
p_opt("msatoshi", param_msat, &msat),
p_opt("bolt11", param_string, &b11str),
p_opt("payment_secret", param_secret,
&payment_secret),
NULL))
return command_param_failed();
} else {
@ -873,6 +894,8 @@ static struct command_result *json_sendpay(struct command *cmd,
p_opt("description", param_escaped_string, &desc),
p_opt("msatoshi", param_msat, &msat),
p_opt("bolt11", param_string, &b11str),
p_opt("payment_secret", param_secret,
&payment_secret),
NULL))
return command_param_failed();
@ -964,9 +987,18 @@ static struct command_result *json_sendpay(struct command *cmd,
&route[routetok->size-1].amount));
}
/* It's easier to leave this in the API, then ignore it here. */
#if !EXPERIMENTAL_FEATURES
if (payment_secret) {
log_unusual(cmd->ld->log,
"sendpay: we don't support payment_secret yet, ignoring");
payment_secret = NULL;
}
#endif
res = send_payment(cmd->ld, cmd, rhash, route,
msat ? *msat : route[routetok->size-1].amount,
label, b11str);
label, b11str, payment_secret);
if (res)
return res;
return command_still_pending(cmd);