Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Expose lsps0_message_handler.handle_request #15

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ mod transport;
mod utils;

pub use transport::message_handler::{LiquidityManager, LiquidityProviderConfig};
pub use transport::msgs;
3 changes: 2 additions & 1 deletion src/transport/message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ pub struct LiquidityManager<
pending_messages: Arc<Mutex<Vec<(PublicKey, LSPSMessage)>>>,
pending_events: Arc<EventQueue>,
request_id_to_method_map: Mutex<HashMap<String, String>>,
lsps0_message_handler: LSPS0MessageHandler<ES>,
/// lsps0 message handler
pub lsps0_message_handler: LSPS0MessageHandler<ES>,
provider_config: Option<LiquidityProviderConfig>,
channel_manager: Arc<ChannelManager<M, T, ES, NS, SP, F, R, L>>,
}
Expand Down
1 change: 1 addition & 0 deletions src/transport/msgs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(missing_docs)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We set #![deny(missing_docs)] crate-wide for good reason and def. should allow them here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there demo client to request on the public interface of lsp handler? It will be nice for people to check after integrate the handler. Many thanks.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @johncantrell97 has a branch of ldk-sample with the LSP client and LSPS2 integrated.

@johncantrell97, mind sharing a link here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget the state it's in but I think it was working: https://github.com/johncantrell97/ldk-sample/pull/1/files

use lightning::impl_writeable_msg;
use lightning::ln::wire;
use serde::de;
Expand Down
23 changes: 13 additions & 10 deletions src/transport/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,21 @@ where
self.pending_messages.lock().unwrap().push((counterparty_node_id, message.into()));
}

fn handle_request(
/// Return LSPS0Response
///
/// Typically the return will not send out to any where just for verification or inspectation
/// in service for advanced features or logging
pub fn handle_request(
&self, request_id: RequestId, request: LSPS0Request, counterparty_node_id: &PublicKey,
) -> Result<(), lightning::ln::msgs::LightningError> {
) -> Result<LSPS0Response, lightning::ln::msgs::LightningError> {
match request {
LSPS0Request::ListProtocols(_) => {
let msg = LSPS0Message::Response(
request_id,
LSPS0Response::ListProtocols(ListProtocolsResponse {
protocols: self.protocols.clone(),
}),
);
let resp = LSPS0Response::ListProtocols(ListProtocolsResponse {
protocols: self.protocols.clone(),
});
let msg = LSPS0Message::Response(request_id, resp.clone());
self.enqueue_message(*counterparty_node_id, msg);
Ok(())
Ok(resp)
}
}
}
Expand Down Expand Up @@ -92,7 +94,8 @@ where
) -> Result<(), LightningError> {
match message {
LSPS0Message::Request(request_id, request) => {
self.handle_request(request_id, request, counterparty_node_id)
self.handle_request(request_id, request, counterparty_node_id)?;
Ok(())
}
LSPS0Message::Response(_, response) => {
self.handle_response(response, counterparty_node_id)
Expand Down