@@ -13,14 +13,7 @@ use std::fs::File;
1313use std:: io:: Write ;
1414use std:: path:: Path ;
1515use std:: sync:: { Arc , RwLock } ;
16- use cardano_serialization_lib:: { Block , Transaction , TransactionWitnessSet } ;
17- use cardano_serialization_lib:: utils:: BigNum ;
18- use futures:: executor:: block_on;
19- use futures_util:: StreamExt ;
20- use serde:: { Deserialize , Serialize } ;
21- use pharos:: { Channel , Observable } ;
2216use tokio:: task:: JoinHandle ;
23- use crate :: InMemoryNode ;
2417
2518pub type BlockNo = u32 ;
2619pub type Address = String ;
@@ -31,14 +24,7 @@ pub struct SharedInMemoryDbSync {
3124 pub ( crate ) update_thread : JoinHandle < ( ) > ,
3225 // Allowing for now since there is no usage yet in explorer service
3326 #[ allow( dead_code) ]
34-
35- /// thread safe `InMemoryDbSync`. It has inner struct db_sync with rw lock guard and handle to update
36- /// thread which listen to `InMemoryNode` mock block updates
37- pub struct SharedInMemoryDbSync {
38- pub ( crate ) update_thread : JoinHandle < ( ) > ,
39- // Allowing for now since there is no usage yet in explorer service
40- #[ allow( dead_code) ]
41- pub ( crate ) db_sync : Arc < RwLock < InMemoryDbSync > >
27+ pub ( crate ) db_sync : Arc < RwLock < InMemoryDbSync > > ,
4228}
4329
4430impl Drop for SharedInMemoryDbSync {
@@ -47,7 +33,6 @@ impl Drop for SharedInMemoryDbSync {
4733 }
4834}
4935
50-
5136/// Mock of real cardano db sync. At this moment we only stores transactions metadata
5237/// as the only purpose of existance for this struct is to provide catalyst voting registrations
5338/// Struct can be persisted and restored from json file using `serde_json`.
@@ -56,7 +41,7 @@ pub struct InMemoryDbSync {
5641 pub ( crate ) transactions : HashMap < BlockNo , Vec < Transaction > > ,
5742 pub ( crate ) blocks : Vec < Block > ,
5843 stakes : HashMap < Address , BigNum > ,
59- settings : Settings
44+ settings : Settings ,
6045}
6146
6247impl Debug for InMemoryDbSync {
@@ -89,18 +74,18 @@ impl InMemoryDbSync {
8974 let shared_db_sync = Arc :: new ( RwLock :: new ( self ) ) ;
9075 let db_sync = shared_db_sync. clone ( ) ;
9176
92- let handle = tokio:: spawn ( async move {
93- loop {
77+ let handle = tokio:: spawn ( async move {
78+ loop {
9479 let block = observer. next ( ) . await ;
9580 if let Some ( block) = block {
9681 db_sync. write ( ) . unwrap ( ) . on_block_propagation ( & block) ;
9782 }
9883 }
9984 } ) ;
10085
101- SharedInMemoryDbSync {
86+ SharedInMemoryDbSync {
10287 update_thread : handle,
103- db_sync : shared_db_sync
88+ db_sync : shared_db_sync,
10489 }
10590 }
10691
0 commit comments