Skip to content

Commit

Permalink
Add Impl for ListPayments Api
Browse files Browse the repository at this point in the history
  • Loading branch information
G8XSU committed Oct 21, 2024
1 parent bdf09a8 commit 4a37f1f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions server/src/api/list_payments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use crate::util::proto_adapter::payment_to_proto;
use ldk_node::Node;
use protos::{ListPaymentsRequest, ListPaymentsResponse};
use std::sync::Arc;

pub(crate) const LIST_PAYMENTS_PATH: &str = "ListPayments";

pub(crate) fn handle_list_payments_request(
node: Arc<Node>, _request: ListPaymentsRequest,
) -> Result<ListPaymentsResponse, ldk_node::NodeError> {
let payments = node.list_payments().into_iter().map(|p| payment_to_proto(p)).collect();

let response = ListPaymentsResponse { payments };
Ok(response)
}
1 change: 1 addition & 0 deletions server/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub(crate) mod close_channel;
pub(crate) mod get_node_info;
pub(crate) mod get_payment_details;
pub(crate) mod list_channels;
pub(crate) mod list_payments;
pub(crate) mod onchain_receive;
pub(crate) mod onchain_send;
pub(crate) mod open_channel;
2 changes: 2 additions & 0 deletions server/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::api::get_payment_details::{
handle_get_payment_details_request, GET_PAYMENT_DETAILS_PATH,
};
use crate::api::list_channels::{handle_list_channels_request, LIST_CHANNELS_PATH};
use crate::api::list_payments::{handle_list_payments_request, LIST_PAYMENTS_PATH};
use crate::api::onchain_receive::{handle_onchain_receive_request, ONCHAIN_RECEIVE_PATH};
use crate::api::onchain_send::{handle_onchain_send_request, ONCHAIN_SEND_PATH};
use crate::api::open_channel::{handle_open_channel, OPEN_CHANNEL_PATH};
Expand Down Expand Up @@ -64,6 +65,7 @@ impl Service<Request<Incoming>> for NodeService {
GET_PAYMENT_DETAILS_PATH => {
Box::pin(handle_request(node, req, handle_get_payment_details_request))
},
LIST_PAYMENTS_PATH => Box::pin(handle_request(node, req, handle_list_payments_request)),
path => {
let error = format!("Unknown request: {}", path).into_bytes();
Box::pin(async {
Expand Down

0 comments on commit 4a37f1f

Please sign in to comment.