From b46e88918fba906022f61cd8d6b9a2e4bd74224f Mon Sep 17 00:00:00 2001 From: dzdidi Date: Mon, 9 Dec 2024 12:04:30 +0100 Subject: [PATCH] Add cli command for ListPayments Update ldk-server-client/src/client.rs Co-authored-by: Gursharan Singh <3442979+G8XSU@users.noreply.github.com> --- ldk-server-cli/src/main.rs | 8 ++++++-- ldk-server-client/src/client.rs | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ldk-server-cli/src/main.rs b/ldk-server-cli/src/main.rs index e0e4c8b..140df23 100644 --- a/ldk-server-cli/src/main.rs +++ b/ldk-server-cli/src/main.rs @@ -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)] @@ -77,6 +77,7 @@ enum Commands { announce_channel: bool, }, ListChannels, + ListPayments, } #[tokio::main] @@ -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); + }, } } diff --git a/ldk-server-client/src/client.rs b/ldk-server-client/src/client.rs index 8d642d0..c8f8872 100644 --- a/ldk-server-client/src/client.rs +++ b/ldk-server-client/src/client.rs @@ -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; @@ -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)] @@ -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 { + let url = format!("http://{}/{LIST_PAYMENTS_PATH}", self.base_url); + self.post_request(&request, &url).await + } + async fn post_request( &self, request: &Rq, url: &str, ) -> Result {