Interface changes: - Rename StrategySelector to StrategyEncoderRegistry - Implement clone for SwapEncoder The StrategyEncoderRegistry needs to be initialised at the highest level and the passed to the TychoEncoder. The TychoEncoder doesn't hold the chain nor the signer_pk as attributes anymore The StrategyEncoderRegistry does: - Initialises the SwapEncoderRegistry - Initialises all the strategies and saves them in a HashMap - Later, the TychoEncoder only reads from this hashmap The StrategyEncoder now each holds a SwapEncoderRegistry as an attribute and they use this to get the correct SwapEncoder instead of reading from the global SWAP_ENCODER_REGISTRY Simplified the SwapEncoderRegistry to not need a Config (everything is done inside itself) All SwapEncoders implement clone Took 2 hours 29 minutes Took 11 seconds Took 2 minutes
27 lines
740 B
Rust
27 lines
740 B
Rust
use crate::encoding::{
|
|
errors::EncodingError,
|
|
models::{EncodingContext, Swap},
|
|
};
|
|
pub trait SwapEncoder: Sync + Send {
|
|
fn new(executor_address: String) -> Self
|
|
where
|
|
Self: Sized;
|
|
fn encode_swap(
|
|
&self,
|
|
swap: Swap,
|
|
encoding_context: EncodingContext,
|
|
) -> Result<Vec<u8>, EncodingError>;
|
|
fn executor_address(&self) -> &str;
|
|
fn executor_selector(&self) -> &str;
|
|
|
|
/// Clones the swap encoder as a trait object.
|
|
/// This allows the encoder to be cloned when it is being used as a `Box<dyn SwapEncoder>`.
|
|
fn clone_box(&self) -> Box<dyn SwapEncoder>;
|
|
}
|
|
|
|
impl Clone for Box<dyn SwapEncoder> {
|
|
fn clone(&self) -> Box<dyn SwapEncoder> {
|
|
self.clone_box()
|
|
}
|
|
}
|