lightningd: expose/accept "style" parameter in routes.

Default is legacy.  If we have future styles, new strings can be defined,
but for now it's "tlv" or "legacy".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2019-11-14 10:48:53 +10:30
committed by Christian Decker
parent 997e3f7fe6
commit c83834ca82
4 changed files with 47 additions and 4 deletions

View File

@@ -113,8 +113,9 @@ factor for larger amounts, and is basically ignored for tiny ones\.
On success, a "route" array is returned\. Each array element contains
\fIid\fR (the node being routed through), \fImsatoshi\fR (the millisatoshis
sent), \fIamount_msat\fR (the same, with \fImsat\fR appended), and \fIdelay\fR (the
number of blocks to timeout at this node)\.
sent), \fIamount_msat\fR (the same, with \fImsat\fR appended), \fIdelay\fR (the
number of blocks to timeout at this node), and \fIstyle\fR (indicating
the features which can be used for this hop)\.
The final \fIid\fR will be the destination \fIid\fR given in the input\. The

View File

@@ -279,8 +279,9 @@ RETURN VALUE
On success, a "route" array is returned. Each array element contains
*id* (the node being routed through), *msatoshi* (the millisatoshis
sent), *amount\_msat* (the same, with *msat* appended), and *delay* (the
number of blocks to timeout at this node).
sent), *amount\_msat* (the same, with *msat* appended), *delay* (the
number of blocks to timeout at this node), and *style* (indicating
the features which can be used for this hop).
The final *id* will be the destination *id* given in the input. The
difference between the first *msatoshi* minus the *msatoshi* given in

View File

@@ -303,6 +303,21 @@ static const struct json_command listnodes_command = {
};
AUTODATA(json_command, &listnodes_command);
static void json_add_route_hop_style(struct json_stream *response,
const char *fieldname,
enum route_hop_style style)
{
switch (style) {
case ROUTE_HOP_LEGACY:
json_add_string(response, fieldname, "legacy");
return;
case ROUTE_HOP_TLV:
json_add_string(response, fieldname, "tlv");
return;
}
fatal("Unknown route_hop_style %u", style);
}
/* Output a route hop */
static void json_add_route_hop(struct json_stream *r, char const *n,
const struct route_hop *h)
@@ -315,6 +330,7 @@ static void json_add_route_hop(struct json_stream *r, char const *n,
json_add_num(r, "direction", h->direction);
json_add_amount_msat_compat(r, h->amount, "msatoshi", "amount_msat");
json_add_num(r, "delay", h->delay);
json_add_route_hop_style(r, "style", h->style);
json_object_end(r);
}

View File

@@ -788,6 +788,27 @@ send_payment(struct lightningd *ld,
JSON-RPC sendpay interface
-----------------------------------------------------------------------------*/
static struct command_result *param_route_hop_style(struct command *cmd,
const char *name,
const char *buffer,
const jsmntok_t *tok,
enum route_hop_style **style)
{
*style = tal(cmd, enum route_hop_style);
if (json_tok_streq(buffer, tok, "legacy")) {
**style = ROUTE_HOP_LEGACY;
return NULL;
} else if (json_tok_streq(buffer, tok, "tlv")) {
**style = ROUTE_HOP_TLV;
return NULL;
}
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be a legacy or tlv, not '%.*s'",
name, json_tok_full_len(tok),
json_tok_full(buffer, tok));
}
static struct command_result *json_sendpay(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
@@ -846,6 +867,7 @@ static struct command_result *json_sendpay(struct command *cmd,
struct node_id *id;
struct short_channel_id *channel;
unsigned *delay, *direction;
enum route_hop_style *style;
if (!param(cmd, buffer, t,
/* Only *one* of these is required */
@@ -856,6 +878,8 @@ static struct command_result *json_sendpay(struct command *cmd,
p_opt("delay", param_number, &delay),
p_opt("channel", param_short_channel_id, &channel),
p_opt("direction", param_number, &direction),
p_opt_def("style", param_route_hop_style, &style,
ROUTE_HOP_LEGACY),
NULL))
return command_param_failed();
@@ -884,6 +908,7 @@ static struct command_result *json_sendpay(struct command *cmd,
route[i].nodeid = *id;
route[i].delay = *delay;
route[i].channel_id = *channel;
route[i].style = *style;
/* FIXME: Actually ignored by sending code! */
route[i].direction = direction ? *direction : 0;
}