feat: Read default executors at compile time into a json

This way we don't have issues with paths and trying to read files that are at other locations after compile time

--- don't change below this line ---
ENG-4088 Took 44 seconds

Took 52 seconds
This commit is contained in:
Diana Carvalho
2025-02-06 12:39:19 +00:00
parent c791c93cb5
commit f5232f403e
4 changed files with 20 additions and 16 deletions

View File

@@ -1,7 +1,8 @@
use std::{collections::HashMap, fs};
use crate::encoding::{
errors::EncodingError, evm::swap_encoder::builder::SwapEncoderBuilder, models::Chain,
errors::EncodingError,
evm::{constants::DEFAULT_EXECUTORS_JSON, swap_encoder::builder::SwapEncoderBuilder}, models::Chain,
swap_encoder::SwapEncoder,
};
@@ -15,14 +16,20 @@ pub struct SwapEncoderRegistry {
impl SwapEncoderRegistry {
/// Populates the registry with the `SwapEncoders` for the given blockchain by parsing the
/// executors' addresses in the file at the given path.
pub fn new(executors_file_path: &str, blockchain: Chain) -> Result<Self, EncodingError> {
let config_str = fs::read_to_string(executors_file_path).map_err(|e| {
EncodingError::FatalError(format!(
"Error reading executors file from {}: {}",
executors_file_path,
e.to_string()
))
})?;
pub fn new(
executors_file_path: Option<&str>,
blockchain: Chain,
) -> Result<Self, EncodingError> {
let config_str = if let Some(path) = executors_file_path {
fs::read_to_string(path).map_err(|e| {
EncodingError::FatalError(format!(
"Error reading executors file from {:?}: {}",
executors_file_path, e
))
})?
} else {
DEFAULT_EXECUTORS_JSON.to_string()
};
let config: HashMap<String, HashMap<String, String>> = serde_json::from_str(&config_str)?;
let mut encoders = HashMap::new();
let executors = config