lsps: Add client implementation of LSPS0

We want a working client to run some integration tests.

Changelog-Added: lsps-plugin: lsps0 client support
This commit is contained in:
Peter Neuroth
2025-04-04 12:27:38 +02:00
committed by ShahanaFarooqui
parent 4d9ed8e2fb
commit f3f222f39f
6 changed files with 77 additions and 8 deletions

2
plugins/.gitignore vendored
View File

@@ -20,4 +20,4 @@ cln-askrene
recklessrpc
exposesecret
cln-xpay
cln-lsps
cln-lsps-client

View File

@@ -147,8 +147,10 @@ plugins/cln-grpc: target/${RUST_PROFILE}/cln-grpc
@cp $< $@
plugins/clnrest: target/${RUST_PROFILE}/clnrest
@cp $< $@
plugins/cln-lsps-client: target/${RUST_PROFILE}/cln-lsps-client
@cp $< $@
PLUGINS += plugins/cln-grpc plugins/clnrest plugins/cln-lsps
PLUGINS += plugins/cln-grpc plugins/clnrest plugins/cln-lsps-client
endif
PLUGIN_COMMON_OBJS := \
@@ -306,10 +308,12 @@ target/${RUST_PROFILE}/cln-grpc: ${CLN_PLUGIN_SRC} ${CLN_GRPC_PLUGIN_SRC} $(MSGG
cargo build ${CARGO_OPTS} --bin cln-grpc
target/${RUST_PROFILE}/clnrest: ${CLN_REST_PLUGIN_SRC}
cargo build ${CARGO_OPTS} --bin clnrest
target/${RUST_PROFILE}/cln-lsps-client: ${CLN_LSPS_PLUGIN_SRC}
cargo build ${CARGO_OPTS} --bin cln-lsps-client
ifneq ($(RUST),0)
include plugins/rest-plugin/Makefile
DEFAULT_TARGETS += $(CLN_PLUGIN_EXAMPLES) plugins/cln-grpc plugins/clnrest
DEFAULT_TARGETS += $(CLN_PLUGIN_EXAMPLES) plugins/cln-grpc plugins/clnrest plugins/cln-lsps-client
endif
clean: plugins-clean

View File

@@ -3,6 +3,10 @@ name = "cln-lsps"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "cln-lsps-client"
path = "src/client.rs"
[dependencies]
anyhow = "1.0"
async-trait = "0.1"

View File

@@ -0,0 +1,64 @@
use cln_lsps::jsonrpc::client::JsonRpcClient;
use cln_lsps::lsps0::{
self,
transport::{Bolt8Transport, CustomMessageHookManager, WithCustomMessageHookManager},
};
use serde::Deserialize;
use std::path::Path;
#[derive(Clone)]
struct State {
hook_manager: CustomMessageHookManager,
}
impl WithCustomMessageHookManager for State {
fn get_custommsg_hook_manager(&self) -> &CustomMessageHookManager {
&self.hook_manager
}
}
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let hook_manager = CustomMessageHookManager::new();
let state = State { hook_manager };
if let Some(plugin) = cln_plugin::Builder::new(tokio::io::stdin(), tokio::io::stdout())
.hook("custommsg", CustomMessageHookManager::on_custommsg::<State>)
.rpcmethod(
"lsps-listprotocols",
"list protocols supported by lsp",
on_lsps_listprotocols,
)
.start(state)
.await?
{
plugin.join().await
} else {
Ok(())
}
}
async fn on_lsps_listprotocols(
p: cln_plugin::Plugin<State>,
v: serde_json::Value,
) -> Result<serde_json::Value, anyhow::Error> {
#[derive(Deserialize)]
struct Request {
peer: String,
}
let dir = p.configuration().lightning_dir;
let rpc_path = Path::new(&dir).join(&p.configuration().rpc_file);
let req: Request = serde_json::from_value(v).unwrap();
let client = JsonRpcClient::new(Bolt8Transport::new(
&req.peer,
rpc_path,
p.state().hook_manager.clone(),
None,
)?);
let res: lsps0::model::Lsps0listProtocolsResponse = client
.call_typed(lsps0::model::Lsps0listProtocolsRequest {})
.await?;
Ok(serde_json::to_value(res)?)
}

View File

@@ -1,2 +1,2 @@
mod jsonrpc;
mod lsps0;
pub mod jsonrpc;
pub mod lsps0;

View File

@@ -1,3 +0,0 @@
fn main() {
println!("Hello, world!");
}