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

Function check_offer_usage

lightningd/pay.c:781–831  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

779}
780
781static struct command_result *check_offer_usage(struct command *cmd,
782 const struct sha256 *local_offer_id)
783{
784 enum offer_status status;
785 const struct wallet_payment **payments;
786
787 if (!local_offer_id)
788 return NULL;
789
790 if (!wallet_offer_find(tmpctx, cmd->ld->wallet, local_offer_id,
791 NULL, &status))
792 return command_fail(cmd, PAY_OFFER_INVALID,
793 "Unknown offer %s",
794 type_to_string(tmpctx, struct sha256,
795 local_offer_id));
796
797 if (!offer_status_active(status))
798 return command_fail(cmd, PAY_OFFER_INVALID,
799 "Inactive offer %s",
800 type_to_string(tmpctx, struct sha256,
801 local_offer_id));
802
803 if (!offer_status_single(status))
804 return NULL;
805
806 /* OK, we must not attempt more than one payment at once for
807 * single_use offer */
808 payments = wallet_payments_by_offer(tmpctx, cmd->ld->wallet, local_offer_id);
809 for (size_t i = 0; i < tal_count(payments); i++) {
810 switch (payments[i]->status) {
811 case PAYMENT_COMPLETE:
812 return command_fail(cmd, PAY_OFFER_INVALID,
813 "Single-use offer already paid"
814 " with %s",
815 type_to_string(tmpctx, struct sha256,
816 &payments[i]
817 ->payment_hash));
818 case PAYMENT_PENDING:
819 return command_fail(cmd, PAY_OFFER_INVALID,
820 "Single-use offer already"
821 " in progress with %s",
822 type_to_string(tmpctx, struct sha256,
823 &payments[i]
824 ->payment_hash));
825 case PAYMENT_FAILED:
826 break;
827 }
828 }
829
830 return NULL;
831}
832
833static struct channel *find_channel_for_htlc_add(struct lightningd *ld,
834 const struct node_id *node,

Callers 1

send_payment_coreFunction · 0.85

Calls 6

offer_status_activeFunction · 0.85
offer_status_singleFunction · 0.85
wallet_payments_by_offerFunction · 0.85
command_failFunction · 0.70
wallet_offer_findFunction · 0.50
type_to_stringClass · 0.50

Tested by

no test coverage detected