Skip to content

Commit 7a19d08

Browse files
dzdidiG8XSU
andcommitted
Add cli missing commands
Fix typo in readme Add cli command for GetNodeInfo Add cli command for GetBalance Add cli command for ListChannels Add cli command for ListPayments Co-authored-by: Gursharan Singh <3442979+G8XSU@users.noreply.github.com>
1 parent 8a3a55a commit 7a19d08

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ We welcome your feedback and contributions to help shape the future of LDK Serve
3636

3737

3838
### Configuration
39-
Refer `./ldk-server/ldk-server.config to see available configuration options.
39+
Refer `./ldk-server/ldk-server.config` to see available configuration options.
4040

4141
### Building
4242
```

ldk-server-cli/src/main.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use ldk_server_client::client::LdkServerClient;
33
use ldk_server_client::error::LdkServerError;
44
use ldk_server_client::ldk_server_protos::api::{
55
Bolt11ReceiveRequest, Bolt11SendRequest, Bolt12ReceiveRequest, Bolt12SendRequest,
6+
GetBalancesRequest, GetNodeInfoRequest, ListChannelsRequest, ListPaymentsRequest,
67
OnchainReceiveRequest, OnchainSendRequest, OpenChannelRequest,
78
};
89

@@ -18,6 +19,8 @@ struct Cli {
1819

1920
#[derive(Subcommand, Debug)]
2021
enum Commands {
22+
GetNodeInfo,
23+
GetBalances,
2124
OnchainReceive,
2225
OnchainSend {
2326
#[arg(short, long)]
@@ -73,6 +76,8 @@ enum Commands {
7376
#[arg(long)]
7477
announce_channel: bool,
7578
},
79+
ListChannels,
80+
ListPayments,
7681
}
7782

7883
#[tokio::main]
@@ -81,6 +86,12 @@ async fn main() {
8186
let client = LdkServerClient::new(cli.base_url);
8287

8388
match cli.command {
89+
Commands::GetNodeInfo => {
90+
handle_response(client.get_node_info(GetNodeInfoRequest {}).await);
91+
},
92+
Commands::GetBalances => {
93+
handle_response(client.get_balances(GetBalancesRequest {}).await);
94+
},
8495
Commands::OnchainReceive => {
8596
handle_response(client.onchain_receive(OnchainReceiveRequest {}).await);
8697
},
@@ -138,6 +149,12 @@ async fn main() {
138149
.await,
139150
);
140151
},
152+
Commands::ListChannels => {
153+
handle_response(client.list_channels(ListChannelsRequest {}).await);
154+
},
155+
Commands::ListPayments => {
156+
handle_response(client.list_payments(ListPaymentsRequest {}).await);
157+
},
141158
}
142159
}
143160

ldk-server-client/src/client.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ use crate::error::LdkServerError;
44
use ldk_server_protos::api::{
55
Bolt11ReceiveRequest, Bolt11ReceiveResponse, Bolt11SendRequest, Bolt11SendResponse,
66
Bolt12ReceiveRequest, Bolt12ReceiveResponse, Bolt12SendRequest, Bolt12SendResponse,
7-
CloseChannelRequest, CloseChannelResponse, ListChannelsRequest, ListChannelsResponse,
8-
OnchainReceiveRequest, OnchainReceiveResponse, OnchainSendRequest, OnchainSendResponse,
9-
OpenChannelRequest, OpenChannelResponse,
7+
CloseChannelRequest, CloseChannelResponse, GetBalancesRequest, GetBalancesResponse,
8+
GetNodeInfoRequest, GetNodeInfoResponse, ListChannelsRequest, ListChannelsResponse,
9+
ListPaymentsRequest, ListPaymentsResponse, OnchainReceiveRequest, OnchainReceiveResponse,
10+
OnchainSendRequest, OnchainSendResponse, OpenChannelRequest, OpenChannelResponse,
1011
};
1112
use reqwest::header::CONTENT_TYPE;
1213
use reqwest::Client;
1314

1415
const APPLICATION_OCTET_STREAM: &str = "application/octet-stream";
1516

17+
const GET_NODE_INFO_PATH: &str = "GetNodeInfo";
18+
const GET_BALANCES_PATH: &str = "GetBalances";
1619
const ONCHAIN_RECEIVE_PATH: &str = "OnchainReceive";
1720
const ONCHAIN_SEND_PATH: &str = "OnchainSend";
1821
const BOLT11_RECEIVE_PATH: &str = "Bolt11Receive";
@@ -22,6 +25,7 @@ const BOLT12_SEND_PATH: &str = "Bolt12Send";
2225
const OPEN_CHANNEL_PATH: &str = "OpenChannel";
2326
const CLOSE_CHANNEL_PATH: &str = "CloseChannel";
2427
const LIST_CHANNELS_PATH: &str = "ListChannels";
28+
const LIST_PAYMENTS_PATH: &str = "ListPayments";
2529

2630
/// Client to access a hosted instance of LDK Server.
2731
#[derive(Clone)]
@@ -36,6 +40,24 @@ impl LdkServerClient {
3640
Self { base_url, client: Client::new() }
3741
}
3842

43+
/// Retrieve the latest node info like `node_id`, `current_best_block` etc.
44+
/// For API contract/usage, refer to docs for [`GetNodeInfoRequest`] and [`GetNodeInfoResponse`].
45+
pub async fn get_node_info(
46+
&self, request: GetNodeInfoRequest,
47+
) -> Result<GetNodeInfoResponse, LdkServerError> {
48+
let url = format!("http://{}/{GET_NODE_INFO_PATH}", self.base_url);
49+
self.post_request(&request, &url).await
50+
}
51+
52+
/// Retrieves an overview of all known balances.
53+
/// For API contract/usage, refer to docs for [`GetBalancesRequest`] and [`GetBalancesResponse`].
54+
pub async fn get_balances(
55+
&self, request: GetBalancesRequest,
56+
) -> Result<GetBalancesResponse, LdkServerError> {
57+
let url = format!("http://{}/{GET_BALANCES_PATH}", self.base_url);
58+
self.post_request(&request, &url).await
59+
}
60+
3961
/// Retrieve a new on-chain funding address.
4062
/// For API contract/usage, refer to docs for [`OnchainReceiveRequest`] and [`OnchainReceiveResponse`].
4163
pub async fn onchain_receive(
@@ -117,6 +139,15 @@ impl LdkServerClient {
117139
self.post_request(&request, &url).await
118140
}
119141

142+
/// Retrieves list of all payments sent or received by us.
143+
/// For API contract/usage, refer to docs for [`ListPaymentsRequest`] and [`ListPaymentsResponse`].
144+
pub async fn list_payments(
145+
&self, request: ListPaymentsRequest,
146+
) -> Result<ListPaymentsResponse, LdkServerError> {
147+
let url = format!("http://{}/{LIST_PAYMENTS_PATH}", self.base_url);
148+
self.post_request(&request, &url).await
149+
}
150+
120151
async fn post_request<Rq: Message, Rs: Message + Default>(
121152
&self, request: &Rq, url: &str,
122153
) -> Result<Rs, LdkServerError> {

0 commit comments

Comments
 (0)