MCPcopy Create free account
hub / github.com/ElementsProject/lightning / json_add_offer_fields

Function json_add_offer_fields

plugins/offers.c:907–994  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 3

json_add_offerFunction · 0.85
json_add_invoice_requestFunction · 0.85
json_add_b12_invoiceFunction · 0.85

Calls 13

json_add_chainsFunction · 0.85
json_add_hex_talarrFunction · 0.85
json_add_utf8Function · 0.85
json_add_u64Function · 0.85
find_iso4217Function · 0.85
tal_bytelenFunction · 0.85
json_add_numFunction · 0.85
json_add_amount_msatFunction · 0.85
json_add_blinded_pathsFunction · 0.85
json_add_recurrenceFunction · 0.85
json_add_pubkeyFunction · 0.85
amount_msatClass · 0.70

Tested by

no test coverage detected