Wait for a payment. If cmd is deleted, then wait_payment() * no longer be called. * Return callback if we called already, otherwise NULL. */
| 662 | * no longer be called. |
| 663 | * Return callback if we called already, otherwise NULL. */ |
| 664 | static 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, |
no test coverage detected