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

Function wait_payment

lightningd/pay.c:664–769  ·  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

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

Callers 1

json_waitsendpayFunction · 0.85

Calls 8

wallet_payment_by_hashFunction · 0.85
fmt_sha256Function · 0.85
sendpay_successFunction · 0.85
sendpay_failFunction · 0.85
sendpay_errmsg_fmtFunction · 0.85
abortFunction · 0.85
command_failFunction · 0.70

Tested by

no test coverage detected