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

Method configure

plugins/src/lib.rs:354–435  ·  view source on GitHub ↗

Communicate with `lightningd` to tell it about our options, RPC methods and subscribe to hooks, and then process the initialization, configuring the plugin. Returns `None` if we were invoked with `--help` and thus should exit after this handshake

(mut self)

Source from the content-addressed store, hash-verified

352 /// Returns `None` if we were invoked with `--help` and thus
353 /// should exit after this handshake
354 pub async fn configure(mut self) -> Result<Option<ConfiguredPlugin<S, I, O>>, anyhow::Error> {
355 let mut input = FramedRead::new(self.input.take().unwrap(), JsonRpcCodec::default());
356
357 // Sadly we need to wrap the output in a mutex in order to
358 // enable early logging, i.e., logging that is done before the
359 // PluginDriver is processing events during the
360 // handshake. Otherwise we could just write the log events to
361 // the event queue and have the PluginDriver be the sole owner
362 // of `Stdout`.
363 let output = Arc::new(Mutex::new(FramedWrite::new(
364 self.output.take().unwrap(),
365 JsonCodec::default(),
366 )));
367
368 // Now configure the logging, so any `log` call is wrapped
369 // in a JSON-RPC notification and sent to Core Lightning
370 if self.logging {
371 crate::logging::init(output.clone()).await?;
372 trace!("Plugin logging initialized");
373 }
374
375 // Read the `getmanifest` message:
376 match input.next().await {
377 Some(Ok(messages::JsonRpc::Request(id, messages::Request::Getmanifest(m)))) => {
378 output
379 .lock()
380 .await
381 .send(json!({
382 "jsonrpc": "2.0",
383 "result": self.handle_get_manifest(m),
384 "id": id,
385 }))
386 .await?
387 }
388 Some(o) => return Err(anyhow!("Got unexpected message {:?} from lightningd", o)),
389 None => {
390 return Err(anyhow!(
391 "Lost connection to lightning expecting getmanifest"
392 ));
393 }
394 };
395 let (init_id, configuration) = match input.next().await {
396 Some(Ok(messages::JsonRpc::Request(id, messages::Request::Init(m)))) => {
397 (id, self.handle_init(m)?)
398 }
399
400 Some(o) => return Err(anyhow!("Got unexpected message {:?} from lightningd", o)),
401 None => {
402 // If we are being called with --help we will get
403 // disconnected here. That's expected, so don't
404 // complain about it.
405 return Ok(None);
406 }
407 };
408
409 let rpcmethods: HashMap<String, AsyncCallback<S>> =
410 HashMap::from_iter(self.rpcmethods.drain().map(|(k, v)| (k, v.callback)));
411 let hooks: HashMap<String, AsyncCallback<S>> =

Callers 8

mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
startMethod · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80

Calls 6

handle_initMethod · 0.80
mapMethod · 0.80
drainMethod · 0.80
initFunction · 0.70
unwrapMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected