| 440 | } |
| 441 | |
| 442 | static struct command_result *invreq_amount_by_quantity(struct command *cmd, |
| 443 | const struct invreq *ir, |
| 444 | u64 *raw_amt) |
| 445 | { |
| 446 | assert(ir->offer->amount); |
| 447 | |
| 448 | /* BOLT-offers #12: |
| 449 | * - MUST calculate the *base invoice amount* using the offer `amount`: |
| 450 | */ |
| 451 | *raw_amt = *ir->offer->amount; |
| 452 | |
| 453 | /* BOLT-offers #12: |
| 454 | * - if request contains `quantity`, multiply by `quantity`. |
| 455 | */ |
| 456 | if (ir->invreq->quantity) { |
| 457 | if (mul_overflows_u64(*ir->invreq->quantity, *raw_amt)) { |
| 458 | return fail_invreq(cmd, ir, |
| 459 | "quantity %"PRIu64 |
| 460 | " causes overflow", |
| 461 | *ir->invreq->quantity); |
| 462 | } |
| 463 | *raw_amt *= *ir->invreq->quantity; |
| 464 | } |
| 465 | |
| 466 | return NULL; |
| 467 | } |
| 468 | |
| 469 | /* The non-currency-converting case. */ |
| 470 | static struct command_result *invreq_base_amount_simple(struct command *cmd, |
no test coverage detected