| 903 | } |
| 904 | |
| 905 | static bool json_add_offer_fields(struct command *cmd, |
| 906 | struct json_stream *js, |
| 907 | const struct bitcoin_blkid *offer_chains, |
| 908 | const u8 *offer_metadata, |
| 909 | const char *offer_currency, |
| 910 | const u64 *offer_amount, |
| 911 | const char *offer_description, |
| 912 | const u8 *offer_features, |
| 913 | const u64 *offer_absolute_expiry, |
| 914 | struct blinded_path **offer_paths, |
| 915 | const char *offer_issuer, |
| 916 | const u64 *offer_quantity_max, |
| 917 | const struct pubkey *offer_issuer_id, |
| 918 | const struct recurrence *offer_recurrence_compulsory, |
| 919 | const struct recurrence *offer_recurrence_optional, |
| 920 | const struct recurrence_paywindow *offer_recurrence_paywindow, |
| 921 | const u32 *offer_recurrence_limit, |
| 922 | const struct recurrence_base *offer_recurrence_base) |
| 923 | { |
| 924 | bool valid = true; |
| 925 | |
| 926 | if (offer_chains) |
| 927 | json_add_chains(js, "offer_chains", offer_chains); |
| 928 | if (offer_metadata) |
| 929 | json_add_hex_talarr(js, "offer_metadata", offer_metadata); |
| 930 | if (offer_currency) { |
| 931 | const struct iso4217_name_and_divisor *iso4217; |
| 932 | valid &= json_add_utf8(js, "offer_currency", offer_currency); |
| 933 | if (offer_amount) |
| 934 | json_add_u64(js, "offer_amount", *offer_amount); |
| 935 | iso4217 = find_iso4217(offer_currency, |
| 936 | tal_bytelen(offer_currency)); |
| 937 | if (iso4217) |
| 938 | json_add_num(js, "currency_minor_unit", iso4217->minor_unit); |
| 939 | else |
| 940 | json_add_string(js, "warning_unknown_offer_currency", |
| 941 | "unknown currency code"); |
| 942 | } else if (offer_amount) |
| 943 | json_add_amount_msat(js, "offer_amount_msat", |
| 944 | amount_msat(*offer_amount)); |
| 945 | /* BOLT #12: |
| 946 | * |
| 947 | * - if `offer_amount` is set and `offer_description` is not set: |
| 948 | * - MUST NOT respond to the offer. |
| 949 | */ |
| 950 | if (offer_description) |
| 951 | valid &= json_add_utf8(js, "offer_description", |
| 952 | offer_description); |
| 953 | else if (!offer_description && offer_amount) { |
| 954 | json_add_string(js, "warning_missing_offer_description", |
| 955 | "description is required if offer_amount is set (for the user to know what it was they paid for)"); |
| 956 | valid = false; |
| 957 | } |
| 958 | |
| 959 | if (offer_issuer) |
| 960 | valid &= json_add_utf8(js, "offer_issuer", offer_issuer); |
| 961 | if (offer_features) |
| 962 | json_add_hex_talarr(js, "offer_features", offer_features); |
no test coverage detected