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:
@@ -1 +1,2 @@
|
||||
pub const DEFAULT_EXECUTORS_FILE_PATH: &str = "src/encoding/config/executor_addresses.json";
|
||||
pub const DEFAULT_EXECUTORS_JSON: &str =
|
||||
include_str!("../../../src/encoding/config/executor_addresses.json");
|
||||
|
||||
@@ -3,7 +3,6 @@ use std::collections::HashMap;
|
||||
use crate::encoding::{
|
||||
errors::EncodingError,
|
||||
evm::{
|
||||
constants::DEFAULT_EXECUTORS_FILE_PATH,
|
||||
strategy_encoder::strategy_encoders::{ExecutorStrategyEncoder, SplitSwapStrategyEncoder},
|
||||
swap_encoder::swap_encoder_registry::SwapEncoderRegistry,
|
||||
},
|
||||
@@ -26,10 +25,7 @@ impl StrategyEncoderRegistry for EVMStrategyEncoderRegistry {
|
||||
executors_file_path: Option<&str>,
|
||||
signer_pk: Option<String>,
|
||||
) -> Result<Self, EncodingError> {
|
||||
let swap_encoder_registry = SwapEncoderRegistry::new(
|
||||
executors_file_path.unwrap_or(DEFAULT_EXECUTORS_FILE_PATH),
|
||||
chain.clone(),
|
||||
)?;
|
||||
let swap_encoder_registry = SwapEncoderRegistry::new(executors_file_path, chain.clone())?;
|
||||
|
||||
let mut strategies: HashMap<String, Box<dyn StrategyEncoder>> = HashMap::new();
|
||||
strategies.insert(
|
||||
|
||||
@@ -506,7 +506,7 @@ mod tests {
|
||||
|
||||
fn get_swap_encoder_registry() -> SwapEncoderRegistry {
|
||||
let eth_chain = eth_chain();
|
||||
SwapEncoderRegistry::new("src/encoding/config/executor_addresses.json", eth_chain).unwrap()
|
||||
SwapEncoderRegistry::new(None, eth_chain).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user