-
Notifications
You must be signed in to change notification settings - Fork 21
Implement proper pagination for list-payments cli #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // This file is Copyright its original authors, visible in version control | ||
| // history. | ||
| // | ||
| // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE | ||
| // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
| // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option. | ||
| // You may not use this file except in accordance with one or both of these | ||
| // licenses. | ||
|
|
||
| //! CLI-specific type wrappers for API responses. | ||
| //! | ||
| //! This file contains wrapper types that customize the serialization format | ||
| //! of API responses for CLI output. These wrappers ensure that the CLI's output | ||
| //! format matches what users expect and what the CLI can parse back as input. | ||
| use ldk_server_client::ldk_server_protos::api::ListPaymentsResponse; | ||
| use ldk_server_client::ldk_server_protos::types::{PageToken, Payment}; | ||
| use serde::Serialize; | ||
|
|
||
| /// CLI-specific wrapper for ListPaymentsResponse that formats the page token | ||
| /// as "token:idx" instead of a JSON object. | ||
| #[derive(Debug, Clone, Serialize)] | ||
| pub struct CliListPaymentsResponse { | ||
| /// List of payments. | ||
| pub payments: Vec<Payment>, | ||
| /// Next page token formatted as "token:idx", or None if no more pages. | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub next_page_token: Option<String>, | ||
| } | ||
|
|
||
| impl From<ListPaymentsResponse> for CliListPaymentsResponse { | ||
| fn from(response: ListPaymentsResponse) -> Self { | ||
| let next_page_token = response.next_page_token.map(format_page_token); | ||
|
|
||
| CliListPaymentsResponse { payments: response.payments, next_page_token } | ||
| } | ||
| } | ||
|
|
||
| fn format_page_token(token: PageToken) -> String { | ||
| format!("{}:{}", token.token, token.index) | ||
| } | ||
|
Comment on lines
+31
to
+41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a better fit in the Like this people who interact with the server programmatically also no longer can mishandle these two pieces ? Although I agree they get a single object of type |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point of surfacing the
next_page_tokenback to the user is so that they can continue iterating after we've already satisfied their request to provide at least n payments ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes