| 1658 | } |
| 1659 | |
| 1660 | static struct command_result *json_delpay(struct command *cmd, |
| 1661 | const char *buffer, |
| 1662 | const jsmntok_t *obj UNNEEDED, |
| 1663 | const jsmntok_t *params) |
| 1664 | { |
| 1665 | struct json_stream *response; |
| 1666 | const struct wallet_payment **payments; |
| 1667 | enum wallet_payment_status *status; |
| 1668 | struct sha256 *payment_hash; |
| 1669 | u64 *groupid, *partid; |
| 1670 | bool found; |
| 1671 | |
| 1672 | if (!param(cmd, buffer, params, |
| 1673 | p_req("payment_hash", param_sha256, &payment_hash), |
| 1674 | p_req("status", param_payment_status_nopending, &status), |
| 1675 | p_opt("partid", param_u64, &partid), |
| 1676 | p_opt("groupid", param_u64, &groupid), |
| 1677 | NULL)) |
| 1678 | return command_param_failed(); |
| 1679 | |
| 1680 | if ((partid != NULL) != (groupid != NULL)) |
| 1681 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1682 | "Must set both partid and groupid, or neither"); |
| 1683 | |
| 1684 | payments = wallet_payment_list(cmd, cmd->ld->wallet, payment_hash); |
| 1685 | |
| 1686 | if (tal_count(payments) == 0) |
| 1687 | return command_fail(cmd, PAY_NO_SUCH_PAYMENT, "Unknown payment with payment_hash: %s", |
| 1688 | type_to_string(tmpctx, struct sha256, payment_hash)); |
| 1689 | |
| 1690 | found = false; |
| 1691 | for (int i = 0; i < tal_count(payments); i++) { |
| 1692 | if (groupid && payments[i]->groupid != *groupid) |
| 1693 | continue; |
| 1694 | if (partid && payments[i]->partid != *partid) |
| 1695 | continue; |
| 1696 | |
| 1697 | found = true; |
| 1698 | if (payments[i]->status != *status) { |
| 1699 | return command_fail(cmd, PAY_STATUS_UNEXPECTED, "Payment with hash %s has %s status but it should be %s", |
| 1700 | type_to_string(tmpctx, struct sha256, payment_hash), |
| 1701 | payment_status_to_string(payments[i]->status), |
| 1702 | payment_status_to_string(*status)); |
| 1703 | } |
| 1704 | } |
| 1705 | |
| 1706 | if (!found) { |
| 1707 | return command_fail(cmd, PAY_NO_SUCH_PAYMENT, |
| 1708 | "No payment for that payment_hash with that partid and groupid"); |
| 1709 | } |
| 1710 | |
| 1711 | wallet_payment_delete(cmd->ld->wallet, payment_hash, partid, groupid); |
| 1712 | |
| 1713 | response = json_stream_success(cmd); |
| 1714 | json_array_start(response, "payments"); |
| 1715 | for (int i = 0; i < tal_count(payments); i++) { |
| 1716 | if (groupid && payments[i]->groupid != *groupid) |
| 1717 | continue; |
nothing calls this directly
no test coverage detected