|
|
@ -292,6 +292,27 @@ static void json_getroute_reply(struct subd *gossip UNUSED, const u8 *reply, con |
|
|
|
was_pending(command_success(cmd, response)); |
|
|
|
} |
|
|
|
|
|
|
|
static bool json_to_short_channel_id_with_dir(const char *buffer, |
|
|
|
const jsmntok_t *tok, |
|
|
|
struct short_channel_id *scid, |
|
|
|
bool *dir) |
|
|
|
{ |
|
|
|
/* Ends in /0 or /1 */ |
|
|
|
if (tok->end - tok->start < 2) |
|
|
|
return false; |
|
|
|
if (buffer[tok->end - 2] != '/') |
|
|
|
return false; |
|
|
|
if (buffer[tok->end - 1] == '0') |
|
|
|
*dir = false; |
|
|
|
else if (buffer[tok->end - 1] == '1') |
|
|
|
*dir = true; |
|
|
|
else |
|
|
|
return false; |
|
|
|
|
|
|
|
return short_channel_id_from_str(buffer + tok->start, |
|
|
|
tok->end - tok->start - 2, scid); |
|
|
|
} |
|
|
|
|
|
|
|
static struct command_result *json_getroute(struct command *cmd, |
|
|
|
const char *buffer, |
|
|
|
const jsmntok_t *obj UNNEEDED, |
|
|
@ -300,9 +321,13 @@ static struct command_result *json_getroute(struct command *cmd, |
|
|
|
struct lightningd *ld = cmd->ld; |
|
|
|
struct pubkey *destination; |
|
|
|
struct pubkey *source; |
|
|
|
const jsmntok_t *excludetok; |
|
|
|
u64 *msatoshi; |
|
|
|
unsigned *cltv; |
|
|
|
double *riskfactor; |
|
|
|
struct short_channel_id *excluded; |
|
|
|
bool *excluded_dir; |
|
|
|
|
|
|
|
/* Higher fuzz means that some high-fee paths can be discounted
|
|
|
|
* for an even larger value, increasing the scope for route |
|
|
|
* randomization (the higher-fee paths become more likely to |
|
|
@ -317,16 +342,43 @@ static struct command_result *json_getroute(struct command *cmd, |
|
|
|
p_opt_def("cltv", param_number, &cltv, 9), |
|
|
|
p_opt_def("fromid", param_pubkey, &source, ld->id), |
|
|
|
p_opt_def("fuzzpercent", param_percent, &fuzz, 5.0), |
|
|
|
p_opt("exclude", param_array, &excludetok), |
|
|
|
NULL)) |
|
|
|
return command_param_failed(); |
|
|
|
|
|
|
|
/* Convert from percentage */ |
|
|
|
*fuzz = *fuzz / 100.0; |
|
|
|
|
|
|
|
if (excludetok) { |
|
|
|
const jsmntok_t *t, *end = json_next(excludetok); |
|
|
|
size_t i; |
|
|
|
|
|
|
|
excluded = tal_arr(cmd, struct short_channel_id, |
|
|
|
excludetok->size); |
|
|
|
excluded_dir = tal_arr(cmd, bool, excludetok->size); |
|
|
|
|
|
|
|
for (i = 0, t = excludetok + 1; |
|
|
|
t < end; |
|
|
|
t = json_next(t), i++) { |
|
|
|
if (!json_to_short_channel_id_with_dir(buffer, t, |
|
|
|
&excluded[i], |
|
|
|
&excluded_dir[i])) { |
|
|
|
return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
|
|
|
"%.*s is not a valid" |
|
|
|
" id+direction", |
|
|
|
t->end - t->start, |
|
|
|
buffer + t->start); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
excluded = NULL; |
|
|
|
excluded_dir = NULL; |
|
|
|
} |
|
|
|
|
|
|
|
u8 *req = towire_gossip_getroute_request(cmd, source, destination, |
|
|
|
*msatoshi, *riskfactor * 1000, |
|
|
|
*cltv, fuzz, |
|
|
|
NULL, NULL); |
|
|
|
excluded, excluded_dir); |
|
|
|
subd_req(ld->gossip, ld->gossip, req, -1, 0, json_getroute_reply, cmd); |
|
|
|
return command_still_pending(cmd); |
|
|
|
} |
|
|
|