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

Function handle_invoice_request

plugins/offers_invreq_hook.c:1100–1214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1098}
1099
1100struct command_result *handle_invoice_request(struct command *cmd,
1101 const u8 *invreqbin,
1102 struct blinded_path *reply_path,
1103 const struct secret *secret)
1104{
1105 struct out_req *req;
1106 int bad_feature;
1107 size_t len = tal_count(invreqbin);
1108 const u8 *cursor = invreqbin;
1109 struct invreq *ir = tal(cmd, struct invreq);
1110
1111 ir->reply_path = tal_steal(ir, reply_path);
1112 ir->secret = tal_dup_or_null(ir, struct secret, secret);
1113 ir->invreq = fromwire_tlv_invoice_request(cmd, &cursor, &len);
1114
1115 if (!ir->invreq) {
1116 return fail_invreq(cmd, ir, "Invalid invreq");
1117 }
1118
1119 /* BOLT #12:
1120 * The reader:
1121 * ...
1122 * - MUST reject the invoice request if any non-signature TLV fields are outside the inclusive ranges: 0 to 159 and 1000000000 to 2999999999
1123 */
1124 /* BOLT #12:
1125 * Each form is signed using one or more *signature TLV elements*:
1126 * TLV types 240 through 1000 (inclusive)
1127 */
1128 if (any_field_outside_range(ir->invreq->fields, true,
1129 0, 159,
1130 1000000000, 2999999999)) {
1131 return fail_invreq(cmd, ir, "Invalid high fields");
1132 }
1133
1134 /* BOLT #12:
1135 *
1136 * The reader:
1137 * - MUST reject the invoice request if `invreq_payer_id` or `invreq_metadata`
1138 * are not present.
1139 */
1140 if (!ir->invreq->invreq_payer_id)
1141 return fail_invreq(cmd, ir, "Missing invreq_payer_id");
1142 if (!ir->invreq->invreq_metadata)
1143 return fail_invreq(cmd, ir, "Missing invreq_metadata");
1144
1145 /* BOLT #12:
1146 *
1147 * The reader:
1148 *...
1149 * - if `invreq_features` contains unknown _even_ bits that are non-zero:
1150 * - MUST reject the invoice request.
1151 */
1152 bad_feature = features_unsupported(plugin_feature_set(cmd->plugin),
1153 ir->invreq->invreq_features,
1154 BOLT12_INVREQ_FEATURE);
1155 if (bad_feature != -1) {
1156 return fail_invreq(cmd, ir,
1157 "Unsupported invreq feature %i",

Callers 1

onion_message_recvFunction · 0.70

Calls 11

any_field_outside_rangeFunction · 0.85
tal_bytelenFunction · 0.85
bolt12_chain_matchesFunction · 0.85
tal_hexFunction · 0.85
invreq_offer_idFunction · 0.85
json_add_sha256Function · 0.85
plugin_feature_setFunction · 0.70
send_outreqFunction · 0.70
features_unsupportedFunction · 0.50

Tested by

no test coverage detected