Skip to content

Commit

Permalink
Add cli command for ListPayments
Browse files Browse the repository at this point in the history
Update ldk-server-client/src/client.rs

Co-authored-by: Gursharan Singh <[email protected]>
  • Loading branch information
dzdidi and G8XSU committed Dec 9, 2024
1 parent 38cef90 commit b46e889
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
8 changes: 6 additions & 2 deletions ldk-server-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use ldk_server_client::client::LdkServerClient;
use ldk_server_client::error::LdkServerError;
use ldk_server_client::ldk_server_protos::api::{
Bolt11ReceiveRequest, Bolt11SendRequest, Bolt12ReceiveRequest, Bolt12SendRequest,
GetBalancesRequest, GetNodeInfoRequest, ListChannelsRequest, OnchainReceiveRequest,
OnchainSendRequest, OpenChannelRequest,
GetBalancesRequest, GetNodeInfoRequest, ListChannelsRequest, ListPaymentsRequest,
OnchainReceiveRequest, OnchainSendRequest, OpenChannelRequest,
};

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -77,6 +77,7 @@ enum Commands {
announce_channel: bool,
},
ListChannels,
ListPayments,
}

#[tokio::main]
Expand Down Expand Up @@ -151,6 +152,9 @@ async fn main() {
Commands::ListChannels => {
handle_response(client.list_channels(ListChannelsRequest {}).await);
},
Commands::ListPayments => {
handle_response(client.list_payments(ListPaymentsRequest {}).await);
},
}
}

Expand Down
17 changes: 13 additions & 4 deletions ldk-server-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ use ldk_server_protos::api::{
Bolt11ReceiveRequest, Bolt11ReceiveResponse, Bolt11SendRequest, Bolt11SendResponse,
Bolt12ReceiveRequest, Bolt12ReceiveResponse, Bolt12SendRequest, Bolt12SendResponse,
CloseChannelRequest, CloseChannelResponse, GetBalancesRequest, GetBalancesResponse,
GetNodeInfoRequest, GetNodeInfoRequest, GetNodeInfoResponse, GetNodeInfoResponse,
ListChannelsRequest, ListChannelsResponse, ListPaymentsRequest, ListPaymentsResponse,
OnchainReceiveRequest, OnchainReceiveResponse, OnchainSendRequest, OnchainSendResponse,
OpenChannelRequest, OpenChannelResponse,
GetNodeInfoRequest, GetNodeInfoResponse, ListChannelsRequest, ListChannelsResponse,
ListPaymentsRequest, ListPaymentsResponse, OnchainReceiveRequest, OnchainReceiveResponse,
OnchainSendRequest, OnchainSendResponse, OpenChannelRequest, OpenChannelResponse,
};
use reqwest::header::CONTENT_TYPE;
use reqwest::Client;
Expand All @@ -26,6 +25,7 @@ const BOLT12_SEND_PATH: &str = "Bolt12Send";
const OPEN_CHANNEL_PATH: &str = "OpenChannel";
const CLOSE_CHANNEL_PATH: &str = "CloseChannel";
const LIST_CHANNELS_PATH: &str = "ListChannels";
const LIST_PAYMENTS_PATH: &str = "ListPayments";

/// Client to access a hosted instance of LDK Server.
#[derive(Clone)]
Expand Down Expand Up @@ -139,6 +139,15 @@ impl LdkServerClient {
self.post_request(&request, &url).await
}

/// Retrieves list of all payments sent or received by us.
/// For API contract/usage, refer to docs for [`ListPaymentsRequest`] and [`ListPaymentsResponse`].
pub async fn list_payments(
&self, request: ListPaymentsRequest,
) -> Result<ListPaymentsResponse, LdkServerError> {
let url = format!("http://{}/{LIST_PAYMENTS_PATH}", self.base_url);
self.post_request(&request, &url).await
}

async fn post_request<Rq: Message, Rs: Message + Default>(
&self, request: &Rq, url: &str,
) -> Result<Rs, LdkServerError> {
Expand Down

0 comments on commit b46e889

Please sign in to comment.