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

Method handle_init

plugins/src/lib.rs:500–531  ·  view source on GitHub ↗
(&mut self, call: messages::InitCall)

Source from the content-addressed store, hash-verified

498 }
499
500 fn handle_init(&mut self, call: messages::InitCall) -> Result<Configuration, Error> {
501 use options::Value as OValue;
502 use serde_json::Value as JValue;
503
504 // Match up the ConfigOptions and fill in their values if we
505 // have a matching entry.
506 for (name, option) in self.options.iter() {
507 let json_value = call.options.get(name);
508 let default_value = option.default();
509
510 let option_value: Option<options::Value> = match (json_value, default_value) {
511 (None, None) => None,
512 (None, Some(default)) => Some(default.clone()),
513 (Some(JValue::Array(a)), _) => match a.first() {
514 Some(JValue::String(_)) => Some(OValue::StringArray(
515 a.iter().map(|x| x.as_str().unwrap().to_string()).collect(),
516 )),
517 Some(JValue::Number(_)) => Some(OValue::IntegerArray(
518 a.iter().map(|x| x.as_i64().unwrap()).collect(),
519 )),
520 _ => panic!("Array type not supported for option: {}", name),
521 },
522 (Some(JValue::String(s)), _) => Some(OValue::String(s.to_string())),
523 (Some(JValue::Number(i)), _) => Some(OValue::Integer(i.as_i64().unwrap())),
524 (Some(JValue::Bool(b)), _) => Some(OValue::Boolean(*b)),
525 _ => panic!("Type mismatch for option {}", name),
526 };
527
528 self.option_values.insert(name.to_string(), option_value);
529 }
530 Ok(call.configuration)
531 }
532}
533
534impl<S> HookBuilder<S>

Callers 1

configureMethod · 0.80

Calls 13

StringArrayClass · 0.85
IntegerArrayClass · 0.85
StringClass · 0.85
IntegerClass · 0.85
BooleanClass · 0.85
mapMethod · 0.80
as_strMethod · 0.80
as_i64Method · 0.80
getMethod · 0.45
defaultMethod · 0.45
to_stringMethod · 0.45
unwrapMethod · 0.45

Tested by

no test coverage detected