| 1563 | } |
| 1564 | |
| 1565 | static struct command_result *json_listsendpays(struct command *cmd, |
| 1566 | const char *buffer, |
| 1567 | const jsmntok_t *obj UNNEEDED, |
| 1568 | const jsmntok_t *params) |
| 1569 | { |
| 1570 | const struct wallet_payment **payments; |
| 1571 | struct json_stream *response; |
| 1572 | struct sha256 *rhash; |
| 1573 | const char *invstring; |
| 1574 | enum wallet_payment_status *status; |
| 1575 | |
| 1576 | if (!param(cmd, buffer, params, |
| 1577 | /* FIXME: parameter should be invstring now */ |
| 1578 | p_opt("bolt11", param_string, &invstring), |
| 1579 | p_opt("payment_hash", param_sha256, &rhash), |
| 1580 | p_opt("status", param_payment_status, &status), |
| 1581 | NULL)) |
| 1582 | return command_param_failed(); |
| 1583 | |
| 1584 | if (rhash && invstring) { |
| 1585 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1586 | "Can only specify one of" |
| 1587 | " {bolt11} or {payment_hash}"); |
| 1588 | } |
| 1589 | |
| 1590 | if (invstring) { |
| 1591 | struct bolt11 *b11; |
| 1592 | char *fail; |
| 1593 | |
| 1594 | b11 = bolt11_decode(cmd, invstring, cmd->ld->our_features, NULL, |
| 1595 | chainparams, &fail); |
| 1596 | if (b11) { |
| 1597 | rhash = &b11->payment_hash; |
| 1598 | } else { |
| 1599 | struct tlv_invoice *b12; |
| 1600 | |
| 1601 | b12 = invoice_decode(cmd, invstring, strlen(invstring), |
| 1602 | cmd->ld->our_features, |
| 1603 | chainparams, &fail); |
| 1604 | if (b12 && b12->payment_hash) |
| 1605 | rhash = b12->payment_hash; |
| 1606 | else |
| 1607 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1608 | "Invalid invstring: %s", fail); |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash); |
| 1613 | response = json_stream_success(cmd); |
| 1614 | |
| 1615 | json_array_start(response, "payments"); |
| 1616 | for (size_t i = 0; i < tal_count(payments); i++) { |
| 1617 | if (status && payments[i]->status != *status) |
| 1618 | continue; |
| 1619 | json_object_start(response, NULL); |
| 1620 | json_add_payment_fields(response, payments[i]); |
| 1621 | json_object_end(response); |
| 1622 | } |
nothing calls this directly
no test coverage detected