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

Function shadow_route_listchannels

plugins/libplugin-pay.c:3024–3165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3022}
3023
3024static struct command_result *shadow_route_listchannels(struct command *cmd,
3025 const char *buf,
3026 const jsmntok_t *result,
3027 struct payment *p)
3028{
3029 struct shadow_route_data *d = payment_mod_shadowroute_get_data(p);
3030 struct payment_constraints *cons = &d->constraints;
3031 struct route_info *best = NULL;
3032 double total_weight = 0.0;
3033 size_t i;
3034 struct amount_msat best_fee;
3035 const jsmntok_t *sattok, *delaytok, *basefeetok, *propfeetok, *desttok,
3036 *channelstok, *chan, *scidtok;
3037
3038 /* Check the invariants on the constraints between payment and modifier. */
3039 assert(d->constraints.cltv_budget <= p->constraints.cltv_budget / 4);
3040 assert(amount_msat_greater_eq(p->constraints.fee_budget,
3041 d->constraints.fee_budget));
3042
3043 channelstok = json_get_member(buf, result, "channels");
3044 json_for_each_arr(i, chan, channelstok) {
3045 struct route_info curr;
3046 struct amount_sat capacity;
3047 struct amount_msat fee;
3048
3049 sattok = json_get_member(buf, chan, "satoshis");
3050 delaytok = json_get_member(buf, chan, "delay");
3051 basefeetok = json_get_member(buf, chan, "base_fee_millisatoshi");
3052 propfeetok = json_get_member(buf, chan, "fee_per_millionth");
3053 scidtok = json_get_member(buf, chan, "short_channel_id");
3054 desttok = json_get_member(buf, chan, "destination");
3055
3056 if (sattok == NULL || delaytok == NULL ||
3057 delaytok->type != JSMN_PRIMITIVE || basefeetok == NULL ||
3058 basefeetok->type != JSMN_PRIMITIVE || propfeetok == NULL ||
3059 propfeetok->type != JSMN_PRIMITIVE || desttok == NULL ||
3060 scidtok == NULL)
3061 continue;
3062
3063 json_to_u16(buf, delaytok, &curr.cltv_expiry_delta);
3064 json_to_number(buf, basefeetok, &curr.fee_base_msat);
3065 json_to_number(buf, propfeetok,
3066 &curr.fee_proportional_millionths);
3067 json_to_short_channel_id(buf, scidtok, &curr.short_channel_id);
3068 json_to_sat(buf, sattok, &capacity);
3069 json_to_node_id(buf, desttok, &curr.pubkey);
3070
3071 /* If the capacity is insufficient to pass the amount
3072 * it's not a plausible extension. */
3073 if (amount_msat_greater_sat(p->amount, capacity))
3074 continue;
3075
3076 if (curr.cltv_expiry_delta > cons->cltv_budget)
3077 continue;
3078
3079 if (!amount_msat_fee(
3080 &fee, p->amount, curr.fee_base_msat,
3081 curr.fee_proportional_millionths)) {

Callers

nothing calls this directly

Calls 15

amount_msat_greater_eqFunction · 0.85
amount_msat_greater_satFunction · 0.85
amount_msat_feeFunction · 0.85
amount_msat_greaterFunction · 0.85
paymod_logFunction · 0.85
amount_msat_subFunction · 0.85
paymod_errFunction · 0.85
payment_continueFunction · 0.85
shadow_route_extendFunction · 0.85
command_still_pendingFunction · 0.70
json_get_memberFunction · 0.50
json_to_u16Function · 0.50

Tested by

no test coverage detected