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

Function prev_invoice_done

plugins/offers_invreq_hook.c:543–595  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

541}
542
543static struct command_result *prev_invoice_done(struct command *cmd,
544 const char *method,
545 const char *buf,
546 const jsmntok_t *result,
547 struct invreq *ir)
548{
549 const jsmntok_t *status, *arr, *b12;
550 struct tlv_invoice *previnv;
551 const char *fail;
552
553 /* Was it created? */
554 arr = json_get_member(buf, result, "invoices");
555 if (arr->size == 0) {
556 return fail_invreq(cmd, ir,
557 "No previous invoice #%u",
558 *ir->inv->invreq_recurrence_counter - 1);
559 }
560
561 /* Was it paid? */
562 status = json_get_member(buf, arr + 1, "status");
563 if (!json_tok_streq(buf, status, "paid")) {
564 return fail_invreq(cmd, ir,
565 "Previous invoice #%u status %.*s",
566 *ir->inv->invreq_recurrence_counter - 1,
567 json_tok_full_len(status),
568 json_tok_full(buf, status));
569 }
570
571 /* Decode it */
572 b12 = json_get_member(buf, arr + 1, "bolt12");
573 if (!b12) {
574 return fail_internalerr(cmd, ir,
575 "Previous invoice #%u no bolt12 (%.*s)",
576 *ir->inv->invreq_recurrence_counter - 1,
577 json_tok_full_len(arr + 1),
578 json_tok_full(buf, arr + 1));
579 }
580 previnv = invoice_decode(tmpctx, buf + b12->start, b12->end - b12->start,
581 plugin_feature_set(cmd->plugin),
582 chainparams, &fail);
583 if (!previnv) {
584 return fail_internalerr(cmd, ir,
585 "Previous invoice %.*s can't decode?",
586 json_tok_full_len(b12),
587 json_tok_full(buf, b12));
588 }
589 if (!previnv->invoice_recurrence_basetime) {
590 return fail_internalerr(cmd, ir,
591 "Previous invoice %.*s no recurrence_basetime?",
592 json_tok_full_len(b12), json_tok_full(buf, b12));
593 }
594 return check_period(cmd, ir, *previnv->invoice_recurrence_basetime);
595}
596
597/* Now, we need to check the previous invoice was paid, and maybe get timebase */
598static struct command_result *check_previous_invoice(struct command *cmd,

Callers

nothing calls this directly

Calls 8

json_get_memberFunction · 0.85
json_tok_streqFunction · 0.85
invoice_decodeFunction · 0.85
check_periodFunction · 0.85
fail_internalerrFunction · 0.70
plugin_feature_setFunction · 0.70
json_tok_full_lenFunction · 0.50
json_tok_fullFunction · 0.50

Tested by

no test coverage detected