diff --git a/plugins/Makefile b/plugins/Makefile index 959d7eda7..1cf7452e5 100644 --- a/plugins/Makefile +++ b/plugins/Makefile @@ -254,10 +254,14 @@ PLUGIN_BASES := $(PLUGINS:plugins/%=%) $(PY_PLUGINS:plugins/%=%) plugins/list_of_builtin_plugins_gen.h: plugins/Makefile Makefile config.vars @$(call VERBOSE,GEN $@,echo "static const char *list_of_builtin_plugins[] = { $(PLUGIN_BASES:%=\"%\",) NULL };" > $@) +target/${RUST_PROFILE}/examples/cln-subscribe-wildcard: ${CLN_PLUGIN_SRC} plugins/examples/cln-subscribe-wildcard.rs + cargo build ${CARGO_OPTS} --example cln-subscribe-wildcard + CLN_PLUGIN_EXAMPLES := \ target/${RUST_PROFILE}/examples/cln-plugin-startup \ target/${RUST_PROFILE}/examples/cln-plugin-reentrant \ - target/${RUST_PROFILE}/examples/cln-rpc-getinfo + target/${RUST_PROFILE}/examples/cln-rpc-getinfo \ + target/${RUST_PROFILE}/examples/cln-subscribe-wildcard CLN_PLUGIN_SRC = $(shell find plugins/src -name "*.rs") diff --git a/plugins/examples/cln-subscribe-wildcard.rs b/plugins/examples/cln-subscribe-wildcard.rs new file mode 100644 index 000000000..4942f3533 --- /dev/null +++ b/plugins/examples/cln-subscribe-wildcard.rs @@ -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(()) +}