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

Function shadow_route_listchannels

plugins/libplugin-pay.c:3300–3437  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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