@@ -7,14 +7,19 @@ pub struct ECDSAConfig {
77 pub private_key_store_password : String ,
88}
99
10+ #[ derive( Debug , Deserialize , Serialize ) ]
11+ pub struct LastProcessedBlock {
12+ pub last_processed_block : u64 ,
13+ }
14+
1015#[ derive( Debug , Deserialize , Serialize ) ]
1116pub struct Config {
1217 pub eth_rpc_url : String ,
1318 pub eth_ws_url : String ,
1419 pub max_proofs_in_queue : u16 ,
1520 pub proof_aggregation_service_address : String ,
1621 pub aligned_service_manager_address : String ,
17- pub last_processed_block : u64 ,
22+ pub last_processed_block_filepath : String ,
1823 pub ecdsa : ECDSAConfig ,
1924}
2025
@@ -27,13 +32,30 @@ impl Config {
2732 Ok ( config)
2833 }
2934
30- pub fn save_to_file ( & self , file_path : & str ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
35+ pub fn get_last_processed_block ( & self ) -> Result < u64 , Box < dyn std:: error:: Error > > {
36+ let mut file = File :: open ( & self . last_processed_block_filepath ) ?;
37+ let mut contents = String :: new ( ) ;
38+ file. read_to_string ( & mut contents) ?;
39+ let lpb: LastProcessedBlock = serde_json:: from_str ( & contents) ?;
40+ Ok ( lpb. last_processed_block )
41+ }
42+
43+ pub fn update_last_processed_block (
44+ & self ,
45+ last_processed_block : u64 ,
46+ ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
47+ let last_processed_block_struct = LastProcessedBlock {
48+ last_processed_block : last_processed_block,
49+ } ;
50+
3151 let mut file = OpenOptions :: new ( )
3252 . write ( true )
3353 . truncate ( true )
34- . open ( file_path) ?;
35- let content = serde_yaml:: to_string ( & self ) ?;
54+ . open ( & self . last_processed_block_filepath ) ?;
55+
56+ let content = serde_json:: to_string ( & last_processed_block_struct) ?;
3657 file. write_all ( content. as_bytes ( ) ) ?;
58+
3759 Ok ( ( ) )
3860 }
3961}
0 commit comments