tendermint_light_node/
application.rs1use crate::{commands::LightNodeCmd, config::LightNodeConfig};
4use abscissa_core::{
5 application::{self, AppCell},
6 config, trace, Application, EntryPoint, FrameworkError, StandardPaths,
7};
8
9pub static APPLICATION: AppCell<LightNodeApp> = AppCell::new();
11
12pub fn app_reader() -> application::lock::Reader<LightNodeApp> {
16 APPLICATION.read()
17}
18
19pub fn app_writer() -> application::lock::Writer<LightNodeApp> {
21 APPLICATION.write()
22}
23
24pub fn app_config() -> config::Reader<LightNodeApp> {
28 config::Reader::new(&APPLICATION)
29}
30
31#[derive(Debug)]
33pub struct LightNodeApp {
34 config: Option<LightNodeConfig>,
36
37 state: application::State<Self>,
39}
40
41impl Default for LightNodeApp {
46 fn default() -> Self {
47 Self {
48 config: None,
49 state: application::State::default(),
50 }
51 }
52}
53
54impl Application for LightNodeApp {
55 type Cmd = EntryPoint<LightNodeCmd>;
57
58 type Cfg = LightNodeConfig;
60
61 type Paths = StandardPaths;
63
64 fn config(&self) -> &LightNodeConfig {
66 self.config.as_ref().expect("config not loaded")
67 }
68
69 fn state(&self) -> &application::State<Self> {
71 &self.state
72 }
73
74 fn state_mut(&mut self) -> &mut application::State<Self> {
76 &mut self.state
77 }
78
79 fn register_components(&mut self, command: &Self::Cmd) -> Result<(), FrameworkError> {
85 let components = self.framework_components(command)?;
86 self.state.components.register(components)
87 }
88
89 fn after_config(&mut self, config: Self::Cfg) -> Result<(), FrameworkError> {
95 self.state.components.after_config(&config)?;
97 self.config = Some(config);
98 Ok(())
99 }
100
101 fn tracing_config(&self, command: &EntryPoint<LightNodeCmd>) -> trace::Config {
103 if command.verbose {
104 trace::Config::verbose()
105 } else {
106 trace::Config::default()
107 }
108 }
109}