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

Function check_invoice_request_usage

lightningd/pay.c:795–846  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

793 }
794
795static struct command_result *check_invoice_request_usage(struct command *cmd,
796 const struct sha256 *local_invreq_id)
797{
798 enum offer_status status;
799 struct db_stmt *stmt;
800
801 if (!local_invreq_id)
802 return NULL;
803
804 if (!wallet_invoice_request_find(tmpctx, cmd->ld->wallet,
805 local_invreq_id,
806 NULL, &status))
807 return command_fail(cmd, PAY_INVOICE_REQUEST_INVALID,
808 "Unknown invoice_request %s",
809 fmt_sha256(tmpctx, local_invreq_id));
810
811 if (!offer_status_active(status))
812 return command_fail(cmd, PAY_INVOICE_REQUEST_INVALID,
813 "Inactive invoice_request %s",
814 fmt_sha256(tmpctx, local_invreq_id));
815
816 if (!offer_status_single(status))
817 return NULL;
818
819 /* OK, we must not attempt more than one payment at once for
820 * single_use invoice_request we publish! */
821 stmt = payments_by_invoice_request(cmd->ld->wallet, local_invreq_id);
822 if (stmt) {
823 const struct wallet_payment *payment;
824 payment = payment_get_details(tmpctx, stmt);
825
826 tal_free(stmt);
827 switch (payment->status) {
828 case PAYMENT_COMPLETE:
829 return command_fail(cmd, PAY_INVOICE_REQUEST_INVALID,
830 "Single-use invoice_request already paid"
831 " with %s",
832 fmt_sha256(tmpctx,
833 &payment->payment_hash));
834 case PAYMENT_PENDING:
835 return command_fail(cmd, PAY_INVOICE_REQUEST_INVALID,
836 "Single-use invoice_request already"
837 " in progress with %s",
838 fmt_sha256(tmpctx,
839 &payment->payment_hash));
840 case PAYMENT_FAILED:
841 break;
842 }
843 }
844
845 return NULL;
846}
847
848static struct channel *
849find_channel_for_htlc_add(struct lightningd *ld,

Callers 2

send_payment_coreFunction · 0.85
json_injectpaymentonionFunction · 0.85

Calls 8

fmt_sha256Function · 0.85
offer_status_activeFunction · 0.85
offer_status_singleFunction · 0.85
payment_get_detailsFunction · 0.85
tal_freeFunction · 0.85
command_failFunction · 0.70

Tested by

no test coverage detected