11use async_trait:: async_trait;
22use borsh:: BorshSerialize ;
3+ use race_core:: types:: GameSpec ;
34use race_transactor_frames:: EventFrame ;
45use race_event_record:: { RecordsHeader , Record } ;
56use race_core:: chain:: ChainType ;
7+ use race_core:: types:: EntryType ;
68use std:: fs:: { File , create_dir} ;
79use std:: io:: { Write , BufWriter } ;
810use std:: path:: { Path , PathBuf } ;
@@ -86,15 +88,16 @@ pub struct RecorderContext {
8688
8789impl Recorder {
8890 pub fn init (
89- game_addr : String ,
90- game_id : usize ,
91- bundle_addr : String ,
91+ spec : GameSpec ,
92+ init_data : Vec < u8 > ,
93+ entry_type : EntryType ,
9294 chain : ChainType ,
9395 in_mem : bool ,
9496 ) -> ( Self , RecorderContext ) {
9597 let writer: Arc < Mutex < dyn RecordWriter + Send + Sync > > ;
98+ let game_id = spec. game_id ;
9699
97- let header = RecordsHeader :: new ( game_addr . clone ( ) , game_id , bundle_addr , chain. to_string ( ) ) ;
100+ let header = RecordsHeader :: new ( spec . clone ( ) , init_data , entry_type , chain. to_string ( ) ) ;
98101
99102 if in_mem {
100103 writer = Arc :: new ( Mutex :: new ( InMemoryRecordWriter :: new ( header) ) )
@@ -103,10 +106,10 @@ impl Recorder {
103106 if !dir. exists ( ) {
104107 create_dir ( dir) . expect ( "Failed to create records directory" ) ;
105108 }
106- let file_path = if game_id == 0 {
107- format ! ( "records/{}" , game_addr)
109+ let file_path = if spec . game_id == 0 {
110+ format ! ( "records/{}" , spec . game_addr)
108111 } else {
109- format ! ( "records/{}_{}" , game_addr, game_id)
112+ format ! ( "records/{}_{}" , spec . game_addr, spec . game_id)
110113 } ;
111114 writer = Arc :: new ( Mutex :: new ( FileRecordWriter :: try_new ( file_path. into ( ) , header) . expect ( "Fail to create record writer" ) ) )
112115 }
@@ -154,13 +157,16 @@ impl Component<ConsumerPorts, RecorderContext> for Recorder {
154157 }
155158
156159 EventFrame :: Checkpoint {
160+ access_version,
161+ settle_version,
157162 checkpoint,
158163 nodes,
164+ balances,
159165 ..
160166 } => {
161167 if let Some ( state) = checkpoint. get_data ( game_id) {
162168 let record = Record :: Checkpoint {
163- state, nodes
169+ state, nodes, access_version , settle_version , balances ,
164170 } ;
165171
166172 writer. write ( record) ;
0 commit comments