mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
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:
parent
ff7efec723
commit
95b98cf0ee
2 changed files with 40 additions and 1 deletions
|
@ -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")
|
||||
|
||||
|
|
35
plugins/examples/cln-subscribe-wildcard.rs
Normal file
35
plugins/examples/cln-subscribe-wildcard.rs
Normal 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(())
|
||||
}
|
Loading…
Add table
Reference in a new issue