MCPcopy Create free account
hub / github.com/ElementsProject/lightning / hook

Method hook

plugins/src/lib.rs:202–219  ·  view source on GitHub ↗

Add a hook subscription for `hookname` with a raw [`serde_json::Value`] request and response. Prefer [`Builder::hook_typed`] for type-safe hooks, or [`Builder::hook_from_builder`] if you need to configure `before`, `after`, or `filters`.

(mut self, hookname: &str, callback: C)

Source from the content-addressed store, hash-verified

200 /// Prefer [`Builder::hook_typed`] for type-safe hooks, or [`Builder::hook_from_builder`] if you
201 /// need to configure `before`, `after`, or `filters`.
202 pub fn hook<C, F>(mut self, hookname: &str, callback: C) -> Self
203 where
204 C: Send + Sync + 'static,
205 C: Fn(Plugin<S>, Request) -> F + 'static,
206 F: Future<Output = Response> + Send + 'static,
207 {
208 self.hooks.insert(
209 hookname.to_string(),
210 Hook {
211 name: hookname.to_string(),
212 callback: Box::new(move |p, r| Box::pin(callback(p, r))),
213 before: Vec::new(),
214 after: Vec::new(),
215 filters: None,
216 },
217 );
218 self
219 }
220
221 /// Add a hook subscription using a [`HookBuilder`], which allows configuring `before`, `after`,
222 /// and `filters` in addition to the callback. Use [`HookBuilder::new`] for raw

Callers 3

mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45

Calls 2

insertMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected