| 605 | AUTODATA(json_command, &payersign_command); |
| 606 | |
| 607 | static struct command_result *json_listinvoicerequests(struct command *cmd, |
| 608 | const char *buffer, |
| 609 | const jsmntok_t *obj UNNEEDED, |
| 610 | const jsmntok_t *params) |
| 611 | { |
| 612 | struct sha256 *invreq_id; |
| 613 | struct json_stream *response; |
| 614 | struct wallet *wallet = cmd->ld->wallet; |
| 615 | const char *b12; |
| 616 | const struct json_escape *label; |
| 617 | bool *active_only; |
| 618 | enum offer_status status; |
| 619 | |
| 620 | if (!param(cmd, buffer, params, |
| 621 | p_opt("invreq_id", param_sha256, &invreq_id), |
| 622 | p_opt_def("active_only", param_bool, &active_only, false), |
| 623 | NULL)) |
| 624 | return command_param_failed(); |
| 625 | |
| 626 | response = json_stream_success(cmd); |
| 627 | json_array_start(response, "invoicerequests"); |
| 628 | if (invreq_id) { |
| 629 | b12 = wallet_invoice_request_find(tmpctx, wallet, |
| 630 | invreq_id, &label, |
| 631 | &status); |
| 632 | if (b12 && offer_status_active(status) >= *active_only) { |
| 633 | json_object_start(response, NULL); |
| 634 | json_populate_invreq(response, |
| 635 | invreq_id, b12, |
| 636 | label, status); |
| 637 | json_object_end(response); |
| 638 | } |
| 639 | } else { |
| 640 | struct db_stmt *stmt; |
| 641 | struct sha256 id; |
| 642 | |
| 643 | for (stmt = wallet_invreq_id_first(cmd->ld->wallet, &id); |
| 644 | stmt; |
| 645 | stmt = wallet_invreq_id_next(cmd->ld->wallet, stmt, &id)) { |
| 646 | b12 = wallet_invoice_request_find(tmpctx, wallet, &id, |
| 647 | &label, &status); |
| 648 | if (offer_status_active(status) >= *active_only) { |
| 649 | json_object_start(response, NULL); |
| 650 | json_populate_invreq(response, |
| 651 | &id, b12, |
| 652 | label, status); |
| 653 | json_object_end(response); |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | json_array_end(response); |
| 658 | return command_success(cmd, response); |
| 659 | } |
| 660 | |
| 661 | static const struct json_command listinvoicerequests_command = { |
| 662 | "listinvoicerequests", |
nothing calls this directly
no test coverage detected