mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 01:43:36 +01:00
95b98cf0ee
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
36 lines
808 B
Rust
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(())
|
|
}
|