core-lightning/plugins/examples/cln-subscribe-wildcard.rs
Erik De Smedt 95b98cf0ee 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
2024-04-30 15:24:00 -05:00

36 lines
808 B
Rust

/// 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(())
}