| 737 | } |
| 738 | |
| 739 | struct command_result *json_invoicerequest(struct command *cmd, |
| 740 | const char *buffer, |
| 741 | const jsmntok_t *params) |
| 742 | { |
| 743 | const struct offers_data *od = get_offers_data(cmd->plugin); |
| 744 | const char *desc, *issuer, *label; |
| 745 | struct tlv_invoice_request *invreq; |
| 746 | struct amount_msat *msat; |
| 747 | bool *single_use; |
| 748 | |
| 749 | invreq = tlv_invoice_request_new(cmd); |
| 750 | |
| 751 | if (!param(cmd, buffer, params, |
| 752 | p_req("amount", param_msat, &msat), |
| 753 | p_opt("description", param_escaped_string, &desc), |
| 754 | p_opt("issuer", param_escaped_string, &issuer), |
| 755 | p_opt("label", param_escaped_string, &label), |
| 756 | p_opt("absolute_expiry", param_u64, |
| 757 | &invreq->offer_absolute_expiry), |
| 758 | p_opt_def("single_use", param_bool, &single_use, true), |
| 759 | NULL)) |
| 760 | return command_param_failed(); |
| 761 | |
| 762 | /* BOLT #12: |
| 763 | * - otherwise (not responding to an offer): |
| 764 | * - MUST set `offer_description` to a complete description of the purpose of the payment. |
| 765 | * - MUST set (or not set) `offer_absolute_expiry` and `offer_issuer` as it would for an offer. |
| 766 | * - MUST set `invreq_payer_id` (as it would set `offer_issuer_id` for an offer). |
| 767 | * - MUST set `invreq_paths` as it would set (or not set) `offer_paths` for an offer. |
| 768 | * - MUST NOT include `signature`, `offer_metadata`, `offer_chains`, `offer_amount`, `offer_currency`, `offer_features`, `offer_quantity_max`, `offer_paths` or `offer_issuer_id` |
| 769 | * - if the chain for the invoice is not solely bitcoin: |
| 770 | * - MUST specify `invreq_chain` the offer is valid for. |
| 771 | * - MUST set `invreq_amount`. |
| 772 | */ |
| 773 | if (desc) |
| 774 | invreq->offer_description = tal_dup_arr(invreq, char, desc, strlen(desc), 0); |
| 775 | else |
| 776 | invreq->offer_description = NULL; |
| 777 | |
| 778 | if (issuer) { |
| 779 | invreq->offer_issuer |
| 780 | = tal_dup_arr(invreq, char, issuer, strlen(issuer), 0); |
| 781 | } |
| 782 | |
| 783 | if (!streq(chainparams->network_name, "bitcoin")) { |
| 784 | invreq->invreq_chain |
| 785 | = tal_dup(invreq, struct bitcoin_blkid, |
| 786 | &chainparams->genesis_blockhash); |
| 787 | } |
| 788 | /* BOLT #12: |
| 789 | * - if it sets `invreq_amount`: |
| 790 | * - MUST set `msat` in multiples of the minimum lightning-payable unit |
| 791 | * (e.g. milli-satoshis for bitcoin) for `invreq_chain` (or for bitcoin, if there is no `invreq_chain`). |
| 792 | */ |
| 793 | invreq->invreq_amount |
| 794 | = tal_dup(invreq, u64, &msat->millisatoshis); /* Raw: wire */ |
| 795 | |
| 796 | /* BOLT #12: |
nothing calls this directly
no test coverage detected