| 111 | } |
| 112 | |
| 113 | static struct command_result *json_getroute(struct command *cmd, |
| 114 | const char *buffer, |
| 115 | const jsmntok_t *params) |
| 116 | { |
| 117 | struct node_id *destination; |
| 118 | struct node_id *source; |
| 119 | struct amount_msat *msat; |
| 120 | u32 *cltv; |
| 121 | /* risk factor 12.345% -> riskfactor_millionths = 12345000 */ |
| 122 | u64 *riskfactor_millionths, *fuzz_millionths; |
| 123 | struct route_exclusion **excluded; |
| 124 | u32 *max_hops; |
| 125 | const struct dijkstra *dij; |
| 126 | struct route_hop *route; |
| 127 | struct gossmap_node *src, *dst; |
| 128 | struct json_stream *js; |
| 129 | struct gossmap *gossmap; |
| 130 | |
| 131 | if (!param(cmd, buffer, params, |
| 132 | p_req("id", param_node_id, &destination), |
| 133 | p_req("amount_msat|msatoshi", param_msat, &msat), |
| 134 | p_req("riskfactor", param_millionths, &riskfactor_millionths), |
| 135 | p_opt_def("cltv", param_number, &cltv, 9), |
| 136 | p_opt_def("fromid", param_node_id, &source, local_id), |
| 137 | p_opt_def("fuzzpercent", param_millionths, &fuzz_millionths, |
| 138 | 5000000), |
| 139 | p_opt("exclude", param_route_exclusion_array, &excluded), |
| 140 | p_opt_def("maxhops", param_number, &max_hops, ROUTING_MAX_HOPS), |
| 141 | NULL)) |
| 142 | return command_param_failed(); |
| 143 | |
| 144 | /* Convert from percentage */ |
| 145 | fuzz = *fuzz_millionths / 100.0 / 1000000.0; |
| 146 | if (fuzz > 1.0) |
| 147 | return command_fail_badparam(cmd, "fuzzpercent", |
| 148 | buffer, params, |
| 149 | "should be <= 100"); |
| 150 | |
| 151 | gossmap = get_gossmap(); |
| 152 | src = gossmap_find_node(gossmap, source); |
| 153 | if (!src) |
| 154 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 155 | "%s: unknown source node_id (no public channels?)", |
| 156 | type_to_string(tmpctx, struct node_id, source)); |
| 157 | |
| 158 | dst = gossmap_find_node(gossmap, destination); |
| 159 | if (!dst) |
| 160 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 161 | "%s: unknown destination node_id (no public channels?)", |
| 162 | type_to_string(tmpctx, struct node_id, destination)); |
| 163 | |
| 164 | fuzz = 0; |
| 165 | dij = dijkstra(tmpctx, gossmap, dst, *msat, |
| 166 | *riskfactor_millionths / 1000000.0, |
| 167 | can_carry, route_score_fuzz, excluded); |
| 168 | route = route_from_dijkstra(dij, gossmap, dij, src, *msat, *cltv); |
| 169 | if (!route) |
| 170 | return command_fail(cmd, PAY_ROUTE_NOT_FOUND, "Could not find a route"); |
nothing calls this directly
no test coverage detected