| 323 | } |
| 324 | |
| 325 | fn handle_init(&mut self, call: messages::InitCall) -> Result<Configuration, Error> { |
| 326 | use options::Value as OValue; |
| 327 | use serde_json::Value as JValue; |
| 328 | |
| 329 | // Match up the ConfigOptions and fill in their values if we |
| 330 | // have a matching entry. |
| 331 | for opt in self.options.iter_mut() { |
| 332 | if let Some(val) = call.options.get(opt.name()) { |
| 333 | opt.value = Some(match (opt.default(), &val) { |
| 334 | (OValue::String(_), JValue::String(s)) => OValue::String(s.clone()), |
| 335 | (OValue::Integer(_), JValue::Number(n)) => OValue::Integer(n.as_i64().unwrap()), |
| 336 | (OValue::Boolean(_), JValue::Bool(n)) => OValue::Boolean(*n), |
| 337 | |
| 338 | // It's ok to panic, if we get here Core Lightning |
| 339 | // has not enforced the option type. |
| 340 | (_, _) => panic!("Mismatching types in options: {:?} != {:?}", opt, val), |
| 341 | }); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | Ok(call.configuration) |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | // Just some type aliases so we don't get confused in a lisp-like sea |