mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 16:14:23 +01:00
cln-plugin: Add notification subscriptions and hooks to the plugins
For now hooks are treated identically to rpcmethods, with the exception of not being returned in the `getmanifest` call. Later on we can add typed handlers as well.
This commit is contained in:
committed by
Rusty Russell
parent
8c6af21169
commit
60e773239c
@@ -14,6 +14,8 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||
"a test-option with default 42",
|
||||
))
|
||||
.rpcmethod("testmethod", "This is a test", Box::new(testmethod))
|
||||
.subscribe("connect", Box::new(connect_handler))
|
||||
.hook("peer_connected", Box::new(peer_connected_handler))
|
||||
.start()
|
||||
.await?;
|
||||
plugin.join().await
|
||||
@@ -22,3 +24,13 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||
fn testmethod(_p: Plugin<()>, _v: &serde_json::Value) -> Result<serde_json::Value, Error> {
|
||||
Ok(json!("Hello"))
|
||||
}
|
||||
|
||||
fn connect_handler(_p: Plugin<()>, v: &serde_json::Value) -> Result<(), Error> {
|
||||
log::info!("Got a connect notification: {}", v);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn peer_connected_handler(_p: Plugin<()>, v: &serde_json::Value) -> Result<serde_json::Value, Error> {
|
||||
log::info!("Got a connect hook call: {}", v);
|
||||
Ok(json!({"result": "continue"}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user