Skip to content

Commit 4a37f1f

Browse files
committed
Add Impl for ListPayments Api
1 parent bdf09a8 commit 4a37f1f

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

server/src/api/list_payments.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use crate::util::proto_adapter::payment_to_proto;
2+
use ldk_node::Node;
3+
use protos::{ListPaymentsRequest, ListPaymentsResponse};
4+
use std::sync::Arc;
5+
6+
pub(crate) const LIST_PAYMENTS_PATH: &str = "ListPayments";
7+
8+
pub(crate) fn handle_list_payments_request(
9+
node: Arc<Node>, _request: ListPaymentsRequest,
10+
) -> Result<ListPaymentsResponse, ldk_node::NodeError> {
11+
let payments = node.list_payments().into_iter().map(|p| payment_to_proto(p)).collect();
12+
13+
let response = ListPaymentsResponse { payments };
14+
Ok(response)
15+
}

server/src/api/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub(crate) mod close_channel;
66
pub(crate) mod get_node_info;
77
pub(crate) mod get_payment_details;
88
pub(crate) mod list_channels;
9+
pub(crate) mod list_payments;
910
pub(crate) mod onchain_receive;
1011
pub(crate) mod onchain_send;
1112
pub(crate) mod open_channel;

server/src/service.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::api::get_payment_details::{
2121
handle_get_payment_details_request, GET_PAYMENT_DETAILS_PATH,
2222
};
2323
use crate::api::list_channels::{handle_list_channels_request, LIST_CHANNELS_PATH};
24+
use crate::api::list_payments::{handle_list_payments_request, LIST_PAYMENTS_PATH};
2425
use crate::api::onchain_receive::{handle_onchain_receive_request, ONCHAIN_RECEIVE_PATH};
2526
use crate::api::onchain_send::{handle_onchain_send_request, ONCHAIN_SEND_PATH};
2627
use crate::api::open_channel::{handle_open_channel, OPEN_CHANNEL_PATH};
@@ -64,6 +65,7 @@ impl Service<Request<Incoming>> for NodeService {
6465
GET_PAYMENT_DETAILS_PATH => {
6566
Box::pin(handle_request(node, req, handle_get_payment_details_request))
6667
},
68+
LIST_PAYMENTS_PATH => Box::pin(handle_request(node, req, handle_list_payments_request)),
6769
path => {
6870
let error = format!("Unknown request: {}", path).into_bytes();
6971
Box::pin(async {

0 commit comments

Comments
 (0)