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

Method hook

plugins/src/lib.rs:203–220  ·  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

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