| 793 | } |
| 794 | |
| 795 | static 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 | |
| 848 | static struct channel * |
| 849 | find_channel_for_htlc_add(struct lightningd *ld, |
no test coverage detected