@@ -224,7 +224,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
224224
225225 // Create the wallet manager
226226 let mut wallet_manager = WalletManager :: < ManagedWalletInfo > :: new ( ) ;
227- wallet_manager. create_wallet_from_mnemonic (
227+ let wallet_id = wallet_manager. create_wallet_from_mnemonic (
228228 "enemy check owner stumble unaware debris suffer peanut good fabric bleak outside" ,
229229 "" ,
230230 & [ network] ,
@@ -261,6 +261,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
261261 wallet,
262262 enable_terminal_ui,
263263 & matches,
264+ wallet_id,
264265 )
265266 . await ?;
266267 } else {
@@ -278,6 +279,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
278279 wallet,
279280 enable_terminal_ui,
280281 & matches,
282+ wallet_id,
281283 )
282284 . await ?;
283285 }
@@ -289,8 +291,16 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
289291 process:: exit ( 1 ) ;
290292 }
291293 } ;
292- run_client ( config, network_manager, storage_manager, wallet, enable_terminal_ui, & matches)
293- . await ?;
294+ run_client (
295+ config,
296+ network_manager,
297+ storage_manager,
298+ wallet,
299+ enable_terminal_ui,
300+ & matches,
301+ wallet_id,
302+ )
303+ . await ?;
294304 }
295305
296306 Ok ( ( ) )
@@ -303,6 +313,7 @@ async fn run_client<S: dash_spv::storage::StorageManager + Send + Sync + 'static
303313 wallet : Arc < tokio:: sync:: RwLock < WalletManager < ManagedWalletInfo > > > ,
304314 enable_terminal_ui : bool ,
305315 matches : & clap:: ArgMatches ,
316+ wallet_id : [ u8 ; 32 ] ,
306317) -> Result < ( ) , Box < dyn std:: error:: Error > > {
307318 // Create and start the client
308319 let mut client =
@@ -358,6 +369,100 @@ async fn run_client<S: dash_spv::storage::StorageManager + Send + Sync + 'static
358369
359370 tracing:: info!( "SPV client started successfully" ) ;
360371
372+ // Set up event logging: count detected transactions and log wallet balances periodically
373+ // Take the client's event receiver and spawn a logger task
374+ if let Some ( mut event_rx) = client. take_event_receiver ( ) {
375+ let wallet_for_logger = wallet. clone ( ) ;
376+ let network_for_logger = config. network ;
377+ let wallet_id_for_logger = wallet_id;
378+ tokio:: spawn ( async move {
379+ use dash_spv:: types:: SpvEvent ;
380+ let mut total_detected_block_txs: u64 = 0 ;
381+ let mut total_detected_mempool_txs: u64 = 0 ;
382+ let mut last_snapshot = std:: time:: Instant :: now ( ) ;
383+ let snapshot_interval = std:: time:: Duration :: from_secs ( 10 ) ;
384+
385+ loop {
386+ tokio:: select! {
387+ maybe_event = event_rx. recv( ) => {
388+ match maybe_event {
389+ Some ( SpvEvent :: BlockProcessed { relevant_transactions, .. } ) => {
390+ if relevant_transactions > 0 {
391+ total_detected_block_txs = total_detected_block_txs. saturating_add( relevant_transactions as u64 ) ;
392+ tracing:: info!(
393+ "Detected {} wallet-relevant tx(s) in block; cumulative (blocks): {}" ,
394+ relevant_transactions,
395+ total_detected_block_txs
396+ ) ;
397+ }
398+ }
399+ Some ( SpvEvent :: MempoolTransactionAdded { .. } ) => {
400+ total_detected_mempool_txs = total_detected_mempool_txs. saturating_add( 1 ) ;
401+ tracing:: info!(
402+ "Detected wallet-relevant mempool tx; cumulative (mempool): {}" ,
403+ total_detected_mempool_txs
404+ ) ;
405+ }
406+ Some ( _) => { /* ignore other events */ }
407+ None => break , // sender closed
408+ }
409+ }
410+ // Also do a periodic snapshot while events are flowing
411+ _ = tokio:: time:: sleep( snapshot_interval) => {
412+ // Log snapshot if interval has elapsed
413+ if last_snapshot. elapsed( ) >= snapshot_interval {
414+ let ( tx_count, confirmed, unconfirmed, locked, total, derived_incoming) = {
415+ let mgr = wallet_for_logger. read( ) . await ;
416+ // Count transactions via network state for the selected network
417+ let txs = mgr
418+ . get_network_state( network_for_logger)
419+ . map( |ns| ns. transactions. len( ) )
420+ . unwrap_or( 0 ) ;
421+
422+ // Read wallet balance from the managed wallet info
423+ let wb = mgr. get_wallet_balance( & wallet_id_for_logger) . ok( ) ;
424+ let ( c, u, l, t) = wb. map( |b| ( b. confirmed, b. unconfirmed, b. locked, b. total) ) . unwrap_or( ( 0 , 0 , 0 , 0 ) ) ;
425+
426+ // Derive a conservative incoming total by summing tx outputs to our addresses.
427+ let incoming_sum = if let Some ( ns) = mgr. get_network_state( network_for_logger) {
428+ let addrs = mgr. monitored_addresses( network_for_logger) ;
429+ let addr_set: std:: collections:: HashSet <_> = addrs. into_iter( ) . collect( ) ;
430+ let mut sum_incoming: u64 = 0 ;
431+ for rec in ns. transactions. values( ) {
432+ for out in & rec. transaction. output {
433+ if let Ok ( out_addr) = dashcore:: Address :: from_script( & out. script_pubkey, network_for_logger) {
434+ if addr_set. contains( & out_addr) {
435+ sum_incoming = sum_incoming. saturating_add( out. value) ;
436+ }
437+ }
438+ }
439+ }
440+ sum_incoming
441+ } else { 0 } ;
442+
443+ ( txs, c, u, l, t, incoming_sum)
444+ } ;
445+ tracing:: info!(
446+ "Wallet tx summary: detected={} (blocks={} + mempool={}), balances: confirmed={} unconfirmed={} locked={} total={}, derived_incoming_total={} (approx)" ,
447+ tx_count,
448+ total_detected_block_txs,
449+ total_detected_mempool_txs,
450+ confirmed,
451+ unconfirmed,
452+ locked,
453+ total,
454+ derived_incoming
455+ ) ;
456+ last_snapshot = std:: time:: Instant :: now( ) ;
457+ }
458+ }
459+ }
460+ }
461+ } ) ;
462+ } else {
463+ tracing:: warn!( "Event channel not available; transaction/balance logging disabled" ) ;
464+ }
465+
361466 // Add watch addresses if specified
362467 if let Some ( addresses) = matches. get_many :: < String > ( "watch-address" ) {
363468 for addr_str in addresses {
0 commit comments