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

Function shadow_route_listchannels

plugins/libplugin-pay.c:3316–3453  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3314}
3315
3316static struct command_result *shadow_route_listchannels(struct command *cmd,
3317 const char *method,
3318 const char *buf,
3319 const jsmntok_t *result,
3320 struct payment *p)
3321{
3322 struct shadow_route_data *d = payment_mod_shadowroute_get_data(p);
3323 struct payment_constraints *cons = &d->constraints;
3324 struct route_info *best = NULL;
3325 double total_weight = 0.0;
3326 size_t i;
3327 struct amount_msat best_fee;
3328 const jsmntok_t *sattok, *delaytok, *basefeetok, *propfeetok, *desttok,
3329 *channelstok, *chan, *scidtok;
3330
3331 /* Check the invariants on the constraints between payment and modifier. */
3332 assert(d->constraints.cltv_budget <= p->constraints.cltv_budget / 4);
3333 assert(amount_msat_greater_eq(p->constraints.fee_budget,
3334 d->constraints.fee_budget));
3335
3336 channelstok = json_get_member(buf, result, "channels");
3337 json_for_each_arr(i, chan, channelstok) {
3338 struct route_info curr;
3339 struct amount_sat capacity;
3340 struct amount_msat fee;
3341
3342 sattok = json_get_member(buf, chan, "satoshis");
3343 delaytok = json_get_member(buf, chan, "delay");
3344 basefeetok = json_get_member(buf, chan, "base_fee_millisatoshi");
3345 propfeetok = json_get_member(buf, chan, "fee_per_millionth");
3346 scidtok = json_get_member(buf, chan, "short_channel_id");
3347 desttok = json_get_member(buf, chan, "destination");
3348
3349 if (sattok == NULL || delaytok == NULL ||
3350 delaytok->type != JSMN_PRIMITIVE || basefeetok == NULL ||
3351 basefeetok->type != JSMN_PRIMITIVE || propfeetok == NULL ||
3352 propfeetok->type != JSMN_PRIMITIVE || desttok == NULL ||
3353 scidtok == NULL)
3354 continue;
3355
3356 json_to_u16(buf, delaytok, &curr.cltv_expiry_delta);
3357 json_to_number(buf, basefeetok, &curr.fee_base_msat);
3358 json_to_number(buf, propfeetok,
3359 &curr.fee_proportional_millionths);
3360 json_to_short_channel_id(buf, scidtok, &curr.short_channel_id);
3361 json_to_sat(buf, sattok, &capacity);
3362 json_to_node_id(buf, desttok, &curr.pubkey);
3363
3364 /* If the capacity is insufficient to pass the amount
3365 * it's not a plausible extension. */
3366 if (amount_msat_greater_sat(p->our_amount, capacity))
3367 continue;
3368
3369 if (curr.cltv_expiry_delta > cons->cltv_budget)
3370 continue;
3371
3372 if (!amount_msat_fee(
3373 &fee, p->our_amount, curr.fee_base_msat,

Callers

nothing calls this directly

Calls 15

amount_msat_greater_eqFunction · 0.85
json_get_memberFunction · 0.85
json_to_satFunction · 0.85
amount_msat_greater_satFunction · 0.85
amount_msat_feeFunction · 0.85
random_selectFunction · 0.85
amount_msat_greaterFunction · 0.85
paymod_logFunction · 0.85
fmt_short_channel_idFunction · 0.85
amount_msat_deductFunction · 0.85
paymod_errFunction · 0.85
shadow_route_extendFunction · 0.85

Tested by

no test coverage detected