-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathconfig.rs
More file actions
66 lines (57 loc) · 2.07 KB
/
config.rs
File metadata and controls
66 lines (57 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use serde::{Deserialize, Serialize};
use std::{fs::File, fs::OpenOptions, io::Read, io::Write};
#[derive(Debug, Deserialize, Serialize)]
pub struct ECDSAConfig {
pub private_key_store_path: String,
pub private_key_store_password: String,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct LastAggregatedBlock {
pub last_aggregated_block: u64,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct Config {
pub eth_rpc_url: String,
pub eth_ws_url: String,
pub max_proofs_in_queue: u16,
pub proof_aggregation_service_address: String,
pub aligned_service_manager_address: String,
pub last_aggregated_block_filepath: String,
pub ecdsa: ECDSAConfig,
pub proofs_per_chunk: u16,
pub total_proofs_limit: u16,
pub sp1_chunk_aggregator_vk_hash: String,
pub risc0_chunk_aggregator_image_id: String,
}
impl Config {
pub fn from_file(file_path: &str) -> Result<Config, Box<dyn std::error::Error>> {
let mut file = File::open(file_path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
let config: Config = serde_yaml::from_str(&contents)?;
Ok(config)
}
pub fn get_last_aggregated_block(&self) -> Result<u64, Box<dyn std::error::Error>> {
let mut file = File::open(&self.last_aggregated_block_filepath)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
let lab: LastAggregatedBlock = serde_json::from_str(&contents)?;
Ok(lab.last_aggregated_block)
}
pub fn update_last_aggregated_block(
&self,
last_aggregated_block: u64,
) -> Result<(), Box<dyn std::error::Error>> {
let last_aggregated_block_struct = LastAggregatedBlock {
last_aggregated_block,
};
let mut file = OpenOptions::new()
.write(true)
.truncate(true)
.create(true)
.open(&self.last_aggregated_block_filepath)?;
let content = serde_json::to_string(&last_aggregated_block_struct)?;
file.write_all(content.as_bytes())?;
Ok(())
}
}