xpay doesn't have maxfeepercent or exemptfee, so we convert them to * an absolute restriction here. If we can't, fail and let pay handle * it. */
| 3292 | * an absolute restriction here. If we can't, fail and let pay handle |
| 3293 | * it. */ |
| 3294 | static bool calc_maxfee(struct command *cmd, |
| 3295 | const char **maxfeestr, |
| 3296 | const char *buf, |
| 3297 | const jsmntok_t *invstringtok, |
| 3298 | const jsmntok_t *amount_msattok, |
| 3299 | const jsmntok_t *exemptfeetok, |
| 3300 | const jsmntok_t *maxfeepercenttok) |
| 3301 | { |
| 3302 | u64 maxfeepercent_ppm; |
| 3303 | struct amount_msat amount, maxfee, exemptfee; |
| 3304 | |
| 3305 | if (!exemptfeetok && !maxfeepercenttok) |
| 3306 | return true; |
| 3307 | |
| 3308 | /* Can't have both */ |
| 3309 | if (*maxfeestr) |
| 3310 | return false; |
| 3311 | |
| 3312 | /* If they specify amount easy, otherwise take from invoice */ |
| 3313 | if (amount_msattok) { |
| 3314 | if (!parse_amount_msat(&amount, buf + amount_msattok->start, |
| 3315 | amount_msattok->end - amount_msattok->start)) |
| 3316 | return false; |
| 3317 | } else { |
| 3318 | const struct bolt11 *b11; |
| 3319 | const char *invstr, *fail; |
| 3320 | |
| 3321 | /* We need to know total amount to calc fee */ |
| 3322 | if (!invstringtok) |
| 3323 | return false; |
| 3324 | |
| 3325 | invstr = json_strdup(tmpctx, buf, invstringtok); |
| 3326 | b11 = bolt11_decode(tmpctx, invstr, NULL, NULL, NULL, &fail); |
| 3327 | if (b11 != NULL) { |
| 3328 | if (b11->msat == NULL) |
| 3329 | return false; |
| 3330 | amount = *b11->msat; |
| 3331 | } else { |
| 3332 | const struct tlv_invoice *b12; |
| 3333 | b12 = invoice_decode(tmpctx, invstr, strlen(invstr), |
| 3334 | NULL, NULL, &fail); |
| 3335 | if (b12 == NULL || b12->invoice_amount == NULL) |
| 3336 | return false; |
| 3337 | amount = amount_msat(*b12->invoice_amount); |
| 3338 | } |
| 3339 | } |
| 3340 | |
| 3341 | if (maxfeepercenttok) { |
| 3342 | if (!json_to_millionths(buf, |
| 3343 | maxfeepercenttok, |
| 3344 | &maxfeepercent_ppm)) |
| 3345 | return false; |
| 3346 | } else |
| 3347 | maxfeepercent_ppm = 500000; |
| 3348 | |
| 3349 | if (!amount_msat_fee(&maxfee, amount, 0, maxfeepercent_ppm / 100)) |
| 3350 | return false; |
| 3351 |
no test coverage detected