MCPcopy Create free account
hub / github.com/ElementsProject/lightning / json_getroute

Function json_getroute

plugins/topology.c:113–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113static 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");

Callers

nothing calls this directly

Calls 15

command_fail_badparamFunction · 0.85
gossmap_find_nodeFunction · 0.85
route_from_dijkstraFunction · 0.85
plugin_notify_messageFunction · 0.85
json_add_route_hopFunction · 0.85
command_param_failedFunction · 0.70
get_gossmapFunction · 0.70
command_failFunction · 0.70
dijkstraClass · 0.70
jsonrpc_stream_successFunction · 0.70
command_finishedFunction · 0.70
paramFunction · 0.50

Tested by

no test coverage detected