Browse Source

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>
travis-debug
Rusty Russell 5 years ago
committed by Christian Decker
parent
commit
c83834ca82
  1. 5
      doc/lightning-getroute.7
  2. 5
      doc/lightning-getroute.7.md
  3. 16
      lightningd/gossip_control.c
  4. 25
      lightningd/pay.c

5
doc/lightning-getroute.7

@ -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 On success, a "route" array is returned\. Each array element contains
\fIid\fR (the node being routed through), \fImsatoshi\fR (the millisatoshis \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 sent), \fIamount_msat\fR (the same, with \fImsat\fR appended), \fIdelay\fR (the
number of blocks to timeout at this node)\. 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 The final \fIid\fR will be the destination \fIid\fR given in the input\. The

5
doc/lightning-getroute.7.md

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

16
lightningd/gossip_control.c

@ -303,6 +303,21 @@ static const struct json_command listnodes_command = {
}; };
AUTODATA(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 */ /* Output a route hop */
static void json_add_route_hop(struct json_stream *r, char const *n, static void json_add_route_hop(struct json_stream *r, char const *n,
const struct route_hop *h) 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_num(r, "direction", h->direction);
json_add_amount_msat_compat(r, h->amount, "msatoshi", "amount_msat"); json_add_amount_msat_compat(r, h->amount, "msatoshi", "amount_msat");
json_add_num(r, "delay", h->delay); json_add_num(r, "delay", h->delay);
json_add_route_hop_style(r, "style", h->style);
json_object_end(r); json_object_end(r);
} }

25
lightningd/pay.c

@ -788,6 +788,27 @@ send_payment(struct lightningd *ld,
JSON-RPC sendpay interface 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, static struct command_result *json_sendpay(struct command *cmd,
const char *buffer, const char *buffer,
const jsmntok_t *obj UNNEEDED, const jsmntok_t *obj UNNEEDED,
@ -846,6 +867,7 @@ static struct command_result *json_sendpay(struct command *cmd,
struct node_id *id; struct node_id *id;
struct short_channel_id *channel; struct short_channel_id *channel;
unsigned *delay, *direction; unsigned *delay, *direction;
enum route_hop_style *style;
if (!param(cmd, buffer, t, if (!param(cmd, buffer, t,
/* Only *one* of these is required */ /* 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("delay", param_number, &delay),
p_opt("channel", param_short_channel_id, &channel), p_opt("channel", param_short_channel_id, &channel),
p_opt("direction", param_number, &direction), p_opt("direction", param_number, &direction),
p_opt_def("style", param_route_hop_style, &style,
ROUTE_HOP_LEGACY),
NULL)) NULL))
return command_param_failed(); return command_param_failed();
@ -884,6 +908,7 @@ static struct command_result *json_sendpay(struct command *cmd,
route[i].nodeid = *id; route[i].nodeid = *id;
route[i].delay = *delay; route[i].delay = *delay;
route[i].channel_id = *channel; route[i].channel_id = *channel;
route[i].style = *style;
/* FIXME: Actually ignored by sending code! */ /* FIXME: Actually ignored by sending code! */
route[i].direction = direction ? *direction : 0; route[i].direction = direction ? *direction : 0;
} }

Loading…
Cancel
Save