clockwork_plugin_utils/
config.rs1use {
2 serde::{
3 Serialize,
4 Deserialize
5 },
6 solana_geyser_plugin_interface::geyser_plugin_interface::{
7 GeyserPluginError, Result as PluginResult,
8 },
9 std::{fs::File, path::Path},
10};
11
12static DEFAULT_TRANSACTION_TIMEOUT_THRESHOLD: u64 = 150;
13static DEFAULT_THREAD_COUNT: usize = 10;
14
15#[derive(Clone, Debug, Serialize, Deserialize)]
17pub struct PluginConfig {
18 pub keypath: Option<String>,
19 pub libpath: Option<String>,
20 pub thread_count: usize,
21 pub transaction_timeout_threshold: u64,
22 pub worker_id: u64,
23}
24
25impl Default for PluginConfig {
26 fn default() -> Self {
27 Self {
28 keypath: None,
29 libpath: None,
30 transaction_timeout_threshold: DEFAULT_TRANSACTION_TIMEOUT_THRESHOLD,
31 thread_count: DEFAULT_THREAD_COUNT,
32 worker_id: 0,
33 }
34 }
35}
36
37impl PluginConfig {
38 pub fn read_from<P: AsRef<Path>>(config_path: P) -> PluginResult<Self> {
40 let file = File::open(config_path)?;
41 let this: Self = serde_json::from_reader(file)
42 .map_err(|e| GeyserPluginError::ConfigFileReadError { msg: e.to_string() })?;
43 Ok(this)
44 }
45}