Skip to content

Commit 51016a5

Browse files
committed
lsps: Add client implementation of LSPS0
We want a working client to run some integration tests. Changelog-Added: lsps-plugin: lsps0 client support
1 parent ef6f609 commit 51016a5

File tree

6 files changed

+77
-8
lines changed

6 files changed

+77
-8
lines changed

plugins/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ cln-askrene
2020
recklessrpc
2121
exposesecret
2222
cln-xpay
23-
cln-lsps
23+
cln-lsps-client

plugins/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,10 @@ plugins/cln-grpc: target/${RUST_PROFILE}/cln-grpc
147147
@cp $< $@
148148
plugins/clnrest: target/${RUST_PROFILE}/clnrest
149149
@cp $< $@
150+
plugins/cln-lsps-client: target/${RUST_PROFILE}/cln-lsps-client
151+
@cp $< $@
150152

151-
PLUGINS += plugins/cln-grpc plugins/clnrest plugins/cln-lsps
153+
PLUGINS += plugins/cln-grpc plugins/clnrest plugins/cln-lsps-client
152154
endif
153155

154156
PLUGIN_COMMON_OBJS := \
@@ -306,10 +308,12 @@ target/${RUST_PROFILE}/cln-grpc: ${CLN_PLUGIN_SRC} ${CLN_GRPC_PLUGIN_SRC} $(MSGG
306308
cargo build ${CARGO_OPTS} --bin cln-grpc
307309
target/${RUST_PROFILE}/clnrest: ${CLN_REST_PLUGIN_SRC}
308310
cargo build ${CARGO_OPTS} --bin clnrest
311+
target/${RUST_PROFILE}/cln-lsps-client: ${CLN_LSPS_PLUGIN_SRC}
312+
cargo build ${CARGO_OPTS} --bin cln-lsps-client
309313

310314
ifneq ($(RUST),0)
311315
include plugins/rest-plugin/Makefile
312-
DEFAULT_TARGETS += $(CLN_PLUGIN_EXAMPLES) plugins/cln-grpc plugins/clnrest
316+
DEFAULT_TARGETS += $(CLN_PLUGIN_EXAMPLES) plugins/cln-grpc plugins/clnrest plugins/cln-lsps-client
313317
endif
314318

315319
clean: plugins-clean

plugins/lsps-plugin/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name = "cln-lsps"
33
version = "0.1.0"
44
edition = "2021"
55

6+
[[bin]]
7+
name = "cln-lsps-client"
8+
path = "src/client.rs"
9+
610
[dependencies]
711
anyhow = "1.0"
812
async-trait = "0.1"

plugins/lsps-plugin/src/client.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
use cln_lsps::jsonrpc::client::JsonRpcClient;
2+
use cln_lsps::lsps0::{
3+
self,
4+
transport::{Bolt8Transport, CustomMessageHookManager, WithCustomMessageHookManager},
5+
};
6+
use serde::Deserialize;
7+
use std::path::Path;
8+
9+
#[derive(Clone)]
10+
struct State {
11+
hook_manager: CustomMessageHookManager,
12+
}
13+
14+
impl WithCustomMessageHookManager for State {
15+
fn get_custommsg_hook_manager(&self) -> &CustomMessageHookManager {
16+
&self.hook_manager
17+
}
18+
}
19+
20+
#[tokio::main]
21+
async fn main() -> Result<(), anyhow::Error> {
22+
let hook_manager = CustomMessageHookManager::new();
23+
let state = State { hook_manager };
24+
25+
if let Some(plugin) = cln_plugin::Builder::new(tokio::io::stdin(), tokio::io::stdout())
26+
.hook("custommsg", CustomMessageHookManager::on_custommsg::<State>)
27+
.rpcmethod(
28+
"lsps-listprotocols",
29+
"list protocols supported by lsp",
30+
on_lsps_listprotocols,
31+
)
32+
.start(state)
33+
.await?
34+
{
35+
plugin.join().await
36+
} else {
37+
Ok(())
38+
}
39+
}
40+
41+
async fn on_lsps_listprotocols(
42+
p: cln_plugin::Plugin<State>,
43+
v: serde_json::Value,
44+
) -> Result<serde_json::Value, anyhow::Error> {
45+
#[derive(Deserialize)]
46+
struct Request {
47+
peer: String,
48+
}
49+
let dir = p.configuration().lightning_dir;
50+
let rpc_path = Path::new(&dir).join(&p.configuration().rpc_file);
51+
52+
let req: Request = serde_json::from_value(v).unwrap();
53+
54+
let client = JsonRpcClient::new(Bolt8Transport::new(
55+
&req.peer,
56+
rpc_path,
57+
p.state().hook_manager.clone(),
58+
None,
59+
)?);
60+
let res: lsps0::model::Lsps0listProtocolsResponse = client
61+
.call_typed(lsps0::model::Lsps0listProtocolsRequest {})
62+
.await?;
63+
Ok(serde_json::to_value(res)?)
64+
}

plugins/lsps-plugin/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
mod jsonrpc;
2-
mod lsps0;
1+
pub mod jsonrpc;
2+
pub mod lsps0;

plugins/lsps-plugin/src/main.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)