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

Function json_add_invreq_fields

plugins/offers.c:1058–1163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1056}
1057
1058static bool json_add_invreq_fields(struct command *cmd,
1059 struct json_stream *js,
1060 const u8 *invreq_metadata,
1061 const struct bitcoin_blkid *invreq_chain,
1062 const u64 *invreq_amount,
1063 const u8 *invreq_features,
1064 const u64 *invreq_quantity,
1065 const struct pubkey *invreq_payer_id,
1066 const utf8 *invreq_payer_note,
1067 struct blinded_path **invreq_paths,
1068 struct bip_353_name *bip353,
1069 const u32 *invreq_recurrence_counter,
1070 const u32 *invreq_recurrence_start,
1071 const struct tlv_invoice_request_invreq_recurrence_cancel *invreq_recurrence_cancel)
1072{
1073 bool valid = true;
1074
1075 /* BOLT #12:
1076 * - MUST reject the invoice request if `invreq_payer_id` or `invreq_metadata` are not present.
1077 */
1078 if (invreq_metadata)
1079 json_add_hex_talarr(js, "invreq_metadata",
1080 invreq_metadata);
1081 else {
1082 json_add_string(js, "warning_missing_invreq_metadata",
1083 "invreq_metadata required");
1084 valid = false;
1085 }
1086
1087 /* This can be missing for an invoice though! */
1088 if (invreq_payer_id)
1089 json_add_pubkey(js, "invreq_payer_id", invreq_payer_id);
1090
1091 if (invreq_chain)
1092 json_add_sha256(js, "invreq_chain", &invreq_chain->shad.sha);
1093
1094 if (invreq_amount)
1095 json_add_amount_msat(js, "invreq_amount_msat",
1096 amount_msat(*invreq_amount));
1097 if (invreq_features)
1098 json_add_hex_talarr(js, "invreq_features", invreq_features);
1099 if (invreq_quantity)
1100 json_add_u64(js, "invreq_quantity", *invreq_quantity);
1101 if (invreq_payer_note)
1102 valid &= json_add_utf8(js, "invreq_payer_note", invreq_payer_note);
1103 if (invreq_paths)
1104 valid &= json_add_blinded_paths(cmd, js, "invreq_paths",
1105 invreq_paths, NULL);
1106
1107 if (bip353) {
1108 json_object_start(js, "invreq_bip_353_name");
1109 if (bip353->name) {
1110 json_add_str_fmt(js, "name", "%.*s",
1111 (int)tal_bytelen(bip353->name),
1112 (char *)bip353->name);
1113 }
1114 if (bip353->domain) {
1115 json_add_str_fmt(js, "domain", "%.*s",

Callers 2

json_add_invoice_requestFunction · 0.85
json_add_b12_invoiceFunction · 0.85

Calls 15

json_add_hex_talarrFunction · 0.85
json_add_pubkeyFunction · 0.85
json_add_sha256Function · 0.85
json_add_amount_msatFunction · 0.85
json_add_u64Function · 0.85
json_add_utf8Function · 0.85
json_add_blinded_pathsFunction · 0.85
json_object_startFunction · 0.85
json_add_str_fmtFunction · 0.85
tal_bytelenFunction · 0.85
json_object_endFunction · 0.85

Tested by

no test coverage detected