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

Method register_with_context

plugins/lsps-plugin/src/core/router.rs:77–95  ·  view source on GitHub ↗
(&mut self, method: &'static str, handler: F)

Source from the content-addressed store, hash-verified

75 }
76
77 pub fn register_with_context<P, R, F, Fut>(&mut self, method: &'static str, handler: F)
78 where
79 P: DeserializeOwned + Send + 'static,
80 R: Serialize + Send + 'static,
81 F: Fn(RequestContext, P) -> Fut + Send + Sync + Clone + 'static,
82 Fut: Future<Output = Result<R, RpcError>> + Send + 'static,
83 {
84 let boxed: BoxedHandler = Box::new(move |ctx: &RequestContext, params: &[u8]| {
85 let handler = handler.clone();
86 let ctx = ctx.clone();
87 let params: Result<P, _> = serde_json::from_slice(params);
88 Box::pin(async move {
89 let params = params.map_err(|e| RpcError::invalid_params(e))?;
90 let result = handler(ctx, params).await?;
91 serde_json::to_value(&result).map_err(|_| RpcError::internal_error("parsing error"))
92 })
93 });
94 self.handlers.insert(method, boxed);
95 }
96
97 pub fn build(self) -> JsonRpcRouter {
98 JsonRpcRouter {

Callers

nothing calls this directly

Calls 3

from_sliceFunction · 0.85
handlerFunction · 0.50
insertMethod · 0.45

Tested by

no test coverage detected