cln_plugin: Example package subscribing to "*"

Creates an example package that subscribes to all notifications and logs
them. This is useful for testing the behavior of subscribing to "*".

I've also edited the Makefile to ensure that `make` builds the example
and that `make clean` removes the example
This commit is contained in:
Erik De Smedt
2024-02-23 09:29:03 +01:00
committed by Alex Myers
parent ff7efec723
commit 95b98cf0ee
2 changed files with 40 additions and 1 deletions

View File

@@ -0,0 +1,35 @@
/// This plug-in subscribes to the wildcard-notifications
/// and creates a corresponding log-entry
use anyhow::Result;
use cln_plugin::{Builder, Plugin};
#[tokio::main]
async fn main() -> Result<()> {
let state = ();
let configured = Builder::new(tokio::io::stdin(), tokio::io::stdout())
.subscribe("*", handle_wildcard_notification)
.start(state)
.await?;
match configured {
Some(p) => p.join().await?,
None => return Ok(()) // cln was started with --help
};
Ok(())
}
async fn handle_wildcard_notification(_plugin: Plugin<()>, value : serde_json::Value) -> Result<()> {
let notification_type : String = value
.as_object()
.unwrap()
.keys()
.next()
.unwrap()
.into();
log::info!("Received notification {}", notification_type);
Ok(())
}