chore: Rename registry -> swap_encoder_registry

Took 14 minutes

Took 8 seconds
This commit is contained in:
Diana Carvalho
2025-02-04 16:57:44 +00:00
parent 23875b8b02
commit c89f46a2e6
4 changed files with 3 additions and 3 deletions

View File

@@ -0,0 +1,36 @@
use std::{collections::HashMap, fs};
use tycho_core::models::Chain;
use crate::encoding::{
errors::EncodingError, evm::swap_encoder::builder::SwapEncoderBuilder,
swap_encoder::SwapEncoder,
};
#[derive(Clone)]
pub struct SwapEncoderRegistry {
encoders: HashMap<String, Box<dyn SwapEncoder>>,
}
impl SwapEncoderRegistry {
pub fn new(executors_file_path: &str, blockchain: Chain) -> Result<Self, EncodingError> {
let config_str = fs::read_to_string(executors_file_path)?;
let config: HashMap<Chain, HashMap<String, String>> = serde_json::from_str(&config_str)?;
let mut encoders = HashMap::new();
let executors = config
.get(&blockchain)
.ok_or(EncodingError::FatalError("No executors found for blockchain".to_string()))?;
for (protocol, executor_address) in executors {
let builder = SwapEncoderBuilder::new(protocol, executor_address);
let encoder = builder.build()?;
encoders.insert(protocol.to_string(), encoder);
}
Ok(Self { encoders })
}
#[allow(clippy::borrowed_box)]
pub fn get_encoder(&self, protocol_system: &str) -> Option<&Box<dyn SwapEncoder>> {
self.encoders.get(protocol_system)
}
}