Check if payment already in progress. Returns NULL if all good. * Sets *succeeded_payment if we had a previous successful payment for this hash. */
| 898 | /* Check if payment already in progress. Returns NULL if all good. |
| 899 | * Sets *succeeded_payment if we had a previous successful payment for this hash. */ |
| 900 | static struct command_result *check_progress(struct lightningd *ld, |
| 901 | struct command *cmd, |
| 902 | const struct sha256 *rhash, |
| 903 | struct amount_msat msat, |
| 904 | struct amount_msat total_msat, |
| 905 | u64 partid, |
| 906 | u64 group, |
| 907 | const struct node_id *destination, |
| 908 | const struct wallet_payment **succeeded_payment) |
| 909 | { |
| 910 | bool have_complete = false; |
| 911 | struct amount_msat msat_already_pending = AMOUNT_MSAT(0); |
| 912 | |
| 913 | *succeeded_payment = NULL; |
| 914 | |
| 915 | /* Now, do we already have one or more payments? */ |
| 916 | for (struct db_stmt *stmt = payments_by_hash(cmd->ld->wallet, rhash); |
| 917 | stmt; |
| 918 | stmt = payments_next(cmd->ld->wallet, stmt)) { |
| 919 | const struct wallet_payment *payment; |
| 920 | |
| 921 | payment = payment_get_details(tmpctx, stmt); |
| 922 | log_debug(ld->log, "Payment: %s %s", |
| 923 | fmt_amount_msat(tmpctx, payment->msatoshi), |
| 924 | payment->status == PAYMENT_COMPLETE ? "COMPLETE" |
| 925 | : payment->status == PAYMENT_PENDING ? "PENDING" |
| 926 | : "FAILED"); |
| 927 | |
| 928 | switch (payment->status) { |
| 929 | case PAYMENT_COMPLETE: |
| 930 | have_complete = true; |
| 931 | if (payment->partid != partid) |
| 932 | continue; |
| 933 | |
| 934 | tal_free(stmt); |
| 935 | |
| 936 | /* Must match successful payment parameters. */ |
| 937 | if (!amount_msat_eq(payment->msatoshi, msat)) { |
| 938 | return command_fail(cmd, PAY_RHASH_ALREADY_USED, |
| 939 | "Already succeeded " |
| 940 | "with amount %s (not %s)", |
| 941 | fmt_amount_msat(tmpctx, |
| 942 | payment->msatoshi), |
| 943 | fmt_amount_msat(tmpctx, |
| 944 | msat)); |
| 945 | } |
| 946 | if (payment->destination && destination |
| 947 | && !node_id_eq(payment->destination, |
| 948 | destination)) { |
| 949 | return command_fail(cmd, PAY_RHASH_ALREADY_USED, |
| 950 | "Already succeeded to %s", |
| 951 | fmt_node_id(tmpctx, |
| 952 | payment->destination)); |
| 953 | } |
| 954 | *succeeded_payment = payment; |
| 955 | return NULL; |
| 956 | |
| 957 | case PAYMENT_PENDING: |
no test coverage detected