@@ -6,6 +6,7 @@ use tokio::sync::{Mutex, RwLock};
66use crate :: client:: ClientConfig ;
77use crate :: error:: Result ;
88use crate :: storage:: StorageManager ;
9+ #[ cfg( feature = "terminal-ui" ) ]
910use crate :: terminal:: TerminalUI ;
1011use crate :: types:: { ChainState , SpvStats , SyncProgress } ;
1112
@@ -14,12 +15,15 @@ pub struct StatusDisplay<'a, S: StorageManager> {
1415 state : & ' a Arc < RwLock < ChainState > > ,
1516 stats : & ' a Arc < RwLock < SpvStats > > ,
1617 storage : Arc < Mutex < S > > ,
18+ #[ cfg( feature = "terminal-ui" ) ]
1719 terminal_ui : & ' a Option < Arc < TerminalUI > > ,
20+ #[ allow( dead_code) ]
1821 config : & ' a ClientConfig ,
1922}
2023
2124impl < ' a , S : StorageManager + Send + Sync + ' static > StatusDisplay < ' a , S > {
2225 /// Create a new status display manager.
26+ #[ cfg( feature = "terminal-ui" ) ]
2327 pub fn new (
2428 state : & ' a Arc < RwLock < ChainState > > ,
2529 stats : & ' a Arc < RwLock < SpvStats > > ,
@@ -36,6 +40,23 @@ impl<'a, S: StorageManager + Send + Sync + 'static> StatusDisplay<'a, S> {
3640 }
3741 }
3842
43+ /// Create a new status display manager (without terminal UI support).
44+ #[ cfg( not( feature = "terminal-ui" ) ) ]
45+ pub fn new (
46+ state : & ' a Arc < RwLock < ChainState > > ,
47+ stats : & ' a Arc < RwLock < SpvStats > > ,
48+ storage : Arc < Mutex < S > > ,
49+ _terminal_ui : & ' a Option < ( ) > ,
50+ config : & ' a ClientConfig ,
51+ ) -> Self {
52+ Self {
53+ state,
54+ stats,
55+ storage,
56+ config,
57+ }
58+ }
59+
3960 /// Calculate the header height based on the current state and storage.
4061 /// This handles both checkpoint sync and normal sync scenarios.
4162 async fn calculate_header_height_with_logging (
@@ -121,57 +142,64 @@ impl<'a, S: StorageManager + Send + Sync + 'static> StatusDisplay<'a, S> {
121142
122143 /// Update the status display.
123144 pub async fn update_status_display ( & self ) {
124- if let Some ( ui) = self . terminal_ui {
125- // Get header height - when syncing from checkpoint, use the actual blockchain height
126- let header_height = {
127- let state = self . state . read ( ) . await ;
128- self . calculate_header_height_with_logging ( & state, true ) . await
129- } ;
130-
131- // Get filter header height from storage
132- let storage = self . storage . lock ( ) . await ;
133- let filter_height = storage. get_filter_tip_height ( ) . await . ok ( ) . flatten ( ) . unwrap_or ( 0 ) ;
134- drop ( storage) ;
135-
136- // Get latest chainlock height from state
137- let chainlock_height = {
138- let state = self . state . read ( ) . await ;
139- state. last_chainlock_height
140- } ;
141-
142- // Get latest chainlock height from storage metadata (in case state wasn't updated)
143- let stored_chainlock_height = {
145+ #[ cfg( feature = "terminal-ui" ) ]
146+ {
147+ if let Some ( ui) = self . terminal_ui {
148+ // Get header height - when syncing from checkpoint, use the actual blockchain height
149+ let header_height = {
150+ let state = self . state . read ( ) . await ;
151+ self . calculate_header_height_with_logging ( & state, true ) . await
152+ } ;
153+
154+ // Get filter header height from storage
144155 let storage = self . storage . lock ( ) . await ;
145- if let Ok ( Some ( data) ) = storage. load_metadata ( "latest_chainlock_height" ) . await {
146- if data. len ( ) >= 4 {
147- Some ( u32:: from_le_bytes ( [ data[ 0 ] , data[ 1 ] , data[ 2 ] , data[ 3 ] ] ) )
156+ let filter_height =
157+ storage. get_filter_tip_height ( ) . await . ok ( ) . flatten ( ) . unwrap_or ( 0 ) ;
158+ drop ( storage) ;
159+
160+ // Get latest chainlock height from state
161+ let chainlock_height = {
162+ let state = self . state . read ( ) . await ;
163+ state. last_chainlock_height
164+ } ;
165+
166+ // Get latest chainlock height from storage metadata (in case state wasn't updated)
167+ let stored_chainlock_height = {
168+ let storage = self . storage . lock ( ) . await ;
169+ if let Ok ( Some ( data) ) = storage. load_metadata ( "latest_chainlock_height" ) . await {
170+ if data. len ( ) >= 4 {
171+ Some ( u32:: from_le_bytes ( [ data[ 0 ] , data[ 1 ] , data[ 2 ] , data[ 3 ] ] ) )
172+ } else {
173+ None
174+ }
148175 } else {
149176 None
150177 }
151- } else {
152- None
153- }
154- } ;
155-
156- // Use the higher of the two chainlock heights
157- let latest_chainlock = match ( chainlock_height, stored_chainlock_height) {
158- ( Some ( a) , Some ( b) ) => Some ( a. max ( b) ) ,
159- ( Some ( a) , None ) => Some ( a) ,
160- ( None , Some ( b) ) => Some ( b) ,
161- ( None , None ) => None ,
162- } ;
178+ } ;
179+
180+ // Use the higher of the two chainlock heights
181+ let latest_chainlock = match ( chainlock_height, stored_chainlock_height) {
182+ ( Some ( a) , Some ( b) ) => Some ( a. max ( b) ) ,
183+ ( Some ( a) , None ) => Some ( a) ,
184+ ( None , Some ( b) ) => Some ( b) ,
185+ ( None , None ) => None ,
186+ } ;
187+
188+ // Update terminal UI
189+ let _ = ui
190+ . update_status ( |status| {
191+ status. headers = header_height;
192+ status. filter_headers = filter_height;
193+ status. chainlock_height = latest_chainlock;
194+ status. peer_count = 1 ; // TODO: Get actual peer count
195+ status. network = format ! ( "{:?}" , self . config. network) ;
196+ } )
197+ . await ;
198+ return ;
199+ }
200+ }
163201
164- // Update terminal UI
165- let _ = ui
166- . update_status ( |status| {
167- status. headers = header_height;
168- status. filter_headers = filter_height;
169- status. chainlock_height = latest_chainlock;
170- status. peer_count = 1 ; // TODO: Get actual peer count
171- status. network = format ! ( "{:?}" , self . config. network) ;
172- } )
173- . await ;
174- } else {
202+ {
175203 // Fall back to simple logging if terminal UI is not enabled
176204 // Get header height - when syncing from checkpoint, use the actual blockchain height
177205 let header_height = {
0 commit comments