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

Function listoffers_done

plugins/offers_inv_hook.c:158–307  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156}
157
158static struct command_result *listoffers_done(struct command *cmd,
159 const char *buf,
160 const jsmntok_t *result,
161 struct inv *inv)
162{
163 const jsmntok_t *arr = json_get_member(buf, result, "offers");
164 const jsmntok_t *offertok, *activetok, *b12tok;
165 bool active;
166 struct amount_msat amt;
167 char *fail;
168 struct out_req *req;
169 struct command_result *err;
170
171 /* BOLT-offers #12:
172 * - otherwise if `offer_id` is set:
173 * - MUST reject the invoice if the `offer_id` does not refer an
174 * unexpired offer with `send_invoice`
175 */
176 if (arr->size == 0)
177 return fail_inv(cmd, inv, "Unknown offer");
178
179 plugin_log(cmd->plugin, LOG_INFORM,
180 "Attempting payment of offer %.*s",
181 json_tok_full_len(result),
182 json_tok_full(buf, result));
183
184 offertok = arr + 1;
185 activetok = json_get_member(buf, offertok, "active");
186 if (!activetok) {
187 return fail_internalerr(cmd, inv,
188 "Missing active: %.*s",
189 json_tok_full_len(offertok),
190 json_tok_full(buf, offertok));
191 }
192 json_to_bool(buf, activetok, &active);
193 if (!active)
194 return fail_inv(cmd, inv, "Offer no longer available");
195
196 b12tok = json_get_member(buf, offertok, "bolt12");
197 if (!b12tok) {
198 return fail_internalerr(cmd, inv,
199 "Missing bolt12: %.*s",
200 json_tok_full_len(offertok),
201 json_tok_full(buf, offertok));
202 }
203 inv->offer = offer_decode(inv,
204 buf + b12tok->start,
205 b12tok->end - b12tok->start,
206 plugin_feature_set(cmd->plugin),
207 chainparams, &fail);
208 if (!inv->offer) {
209 return fail_internalerr(cmd, inv,
210 "Invalid offer: %s (%.*s)",
211 fail,
212 json_tok_full_len(offertok),
213 json_tok_full(buf, offertok));
214 }
215

Callers

nothing calls this directly

Calls 15

fail_invFunction · 0.85
offer_decodeFunction · 0.85
plugin_feature_setFunction · 0.85
time_nowFunction · 0.85
fmt_amount_msatFunction · 0.85
plugin_logFunction · 0.70
fail_internalerrFunction · 0.70
amount_msatClass · 0.70
send_outreqFunction · 0.70
json_get_memberFunction · 0.50
json_tok_full_lenFunction · 0.50
json_tok_fullFunction · 0.50

Tested by

no test coverage detected