| 474 | } |
| 475 | |
| 476 | static void json_add_b12_invoice(struct json_stream *js, |
| 477 | const struct tlv_invoice *invoice) |
| 478 | { |
| 479 | bool valid = true; |
| 480 | |
| 481 | if (invoice->chain) |
| 482 | json_add_sha256(js, "chain", &invoice->chain->shad.sha); |
| 483 | if (invoice->offer_id) |
| 484 | json_add_sha256(js, "offer_id", invoice->offer_id); |
| 485 | |
| 486 | /* BOLT-offers #12: |
| 487 | * - MUST reject the invoice if `msat` is not present. |
| 488 | */ |
| 489 | if (invoice->amount) |
| 490 | json_add_amount_msat_only(js, "amount_msat", |
| 491 | amount_msat(*invoice->amount)); |
| 492 | else { |
| 493 | json_add_string(js, "warning_invoice_missing_amount", |
| 494 | "invoices without an amount are invalid"); |
| 495 | valid = false; |
| 496 | } |
| 497 | |
| 498 | /* BOLT-offers #12: |
| 499 | * - MUST reject the invoice if `description` is not present. |
| 500 | */ |
| 501 | if (invoice->description) |
| 502 | json_add_stringn(js, "description", invoice->description, |
| 503 | tal_bytelen(invoice->description)); |
| 504 | else { |
| 505 | json_add_string(js, "warning_invoice_missing_description", |
| 506 | "invoices without a description are invalid"); |
| 507 | valid = false; |
| 508 | } |
| 509 | |
| 510 | if (invoice->issuer) |
| 511 | json_add_stringn(js, "issuer", invoice->issuer, |
| 512 | tal_bytelen(invoice->issuer)); |
| 513 | if (invoice->features) |
| 514 | json_add_hex_talarr(js, "features", invoice->features); |
| 515 | if (invoice->paths) { |
| 516 | /* BOLT-offers #12: |
| 517 | * - if `blinded_path` is present: |
| 518 | * - MUST reject the invoice if `blinded_payinfo` is not |
| 519 | * present. |
| 520 | * - MUST reject the invoice if `blinded_payinfo` does not |
| 521 | * contain exactly as many `payinfo` as total `onionmsg_path` |
| 522 | * in `blinded_path`. |
| 523 | */ |
| 524 | if (!invoice->blindedpay) { |
| 525 | json_add_string(js, "warning_invoice_missing_blinded_payinfo", |
| 526 | "invoices with blinded_path without blinded_payinfo are invalid"); |
| 527 | valid = false; |
| 528 | } |
| 529 | valid &= json_add_blinded_paths(js, invoice->paths, invoice->blindedpay); |
| 530 | } |
| 531 | if (invoice->quantity) |
| 532 | json_add_u64(js, "quantity", *invoice->quantity); |
| 533 | if (invoice->send_invoice) |
no test coverage detected