| 3022 | } |
| 3023 | |
| 3024 | static 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)) { |
nothing calls this directly
no test coverage detected