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

Function wait_payment

lightningd/pay.c:658–756  ·  view source on GitHub ↗

Wait for a payment. If cmd is deleted, then wait_payment() * no longer be called. * Return callback if we called already, otherwise NULL. */

Source from the content-addressed store, hash-verified

656 * no longer be called.
657 * Return callback if we called already, otherwise NULL. */
658static struct command_result *wait_payment(struct lightningd *ld,
659 struct command *cmd,
660 const struct sha256 *payment_hash,
661 u64 partid, u64 groupid)
662{
663 struct wallet_payment *payment;
664 struct onionreply *failonionreply;
665 bool faildestperm;
666 int failindex;
667 enum onion_wire failcode;
668 struct node_id *failnode;
669 struct short_channel_id *failchannel;
670 u8 *failupdate;
671 char *faildetail;
672 struct routing_failure *fail;
673 int faildirection;
674 enum jsonrpc_errcode rpcerrorcode;
675
676 payment = wallet_payment_by_hash(tmpctx, ld->wallet,
677 payment_hash, partid, groupid);
678 if (!payment) {
679 return command_fail(cmd, PAY_NO_SUCH_PAYMENT,
680 "Never attempted payment part %"PRIu64
681 " for '%s'",
682 partid,
683 type_to_string(tmpctx, struct sha256,
684 payment_hash));
685 }
686
687 log_debug(cmd->ld->log, "Payment part %"PRIu64"/%"PRIu64"/%"PRIu64" status %u",
688 partid, payment->partid, payment->groupid, payment->status);
689
690 switch (payment->status) {
691 case PAYMENT_PENDING:
692 add_waitsendpay_waiter(ld, cmd, payment_hash, partid, groupid);
693 return NULL;
694
695 case PAYMENT_COMPLETE:
696 return sendpay_success(cmd, payment);
697
698 case PAYMENT_FAILED:
699 /* Get error from DB */
700 wallet_payment_get_failinfo(tmpctx, ld->wallet,
701 payment_hash,
702 partid,
703 groupid,
704 &failonionreply,
705 &faildestperm,
706 &failindex,
707 &failcode,
708 &failnode,
709 &failchannel,
710 &failupdate,
711 &faildetail,
712 &faildirection);
713 /* Old DB might not save failure information */
714 if (!failonionreply && !failnode) {
715 return command_fail(cmd, PAY_UNSPECIFIED_ERROR,

Callers 1

json_waitsendpayFunction · 0.85

Calls 9

wallet_payment_by_hashFunction · 0.85
add_waitsendpay_waiterFunction · 0.85
sendpay_successFunction · 0.85
sendpay_failFunction · 0.85
sendpay_errmsg_fmtFunction · 0.85
abortFunction · 0.85
command_failFunction · 0.70
type_to_stringClass · 0.50

Tested by

no test coverage detected