docs: Add docstrings to EVMEncoderBuilder
--- don't change below this line --- ENG-4246 Took 41 minutes
This commit is contained in:
@@ -10,6 +10,9 @@ use crate::encoding::{
|
||||
strategy_encoder::StrategyEncoder,
|
||||
};
|
||||
|
||||
/// Builder pattern for constructing an `EVMTychoEncoder` with customizable options.
|
||||
///
|
||||
/// This struct allows setting a chain and strategy encoder before building the final encoder.
|
||||
pub struct EVMEncoderBuilder {
|
||||
strategy: Option<Box<dyn StrategyEncoder>>,
|
||||
chain: Option<Chain>,
|
||||
@@ -29,10 +32,18 @@ impl EVMEncoderBuilder {
|
||||
self.chain = Some(chain);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the `strategy_encoder` manually.
|
||||
///
|
||||
/// **Note**: This method should not be used in combination with `tycho_router` or
|
||||
/// `direct_execution`.
|
||||
pub fn strategy_encoder(mut self, strategy: Box<dyn StrategyEncoder>) -> Self {
|
||||
self.strategy = Some(strategy);
|
||||
self
|
||||
}
|
||||
|
||||
/// Shortcut method to initialize a `SplitSwapStrategyEncoder` with a given `swapper_pk`.
|
||||
/// **Note**: Should not be used at the same time as `strategy_encoder`.
|
||||
pub fn tycho_router(
|
||||
self,
|
||||
swapper_pk: String,
|
||||
@@ -45,10 +56,13 @@ impl EVMEncoderBuilder {
|
||||
Ok(EVMEncoderBuilder { chain: Some(chain), strategy: Some(strategy) })
|
||||
} else {
|
||||
Err(EncodingError::FatalError(
|
||||
"Please set the chain before setting the strategy".to_string(),
|
||||
"Please set the chain before setting the tycho router".to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/// Shortcut method to initialize an `ExecutorStrategyEncoder`.
|
||||
/// **Note**: Should not be used at the same time as `strategy_encoder`.
|
||||
pub fn direct_execution(
|
||||
self,
|
||||
executors_file_path: Option<String>,
|
||||
@@ -64,6 +78,8 @@ impl EVMEncoderBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds the `EVMTychoEncoder` instance using the configured chain and strategy.
|
||||
/// Returns an error if either the chain or strategy has not been set.
|
||||
pub fn build(self) -> Result<EVMTychoEncoder, EncodingError> {
|
||||
if let (Some(chain), Some(strategy)) = (self.chain, self.strategy) {
|
||||
EVMTychoEncoder::new(chain, strategy)
|
||||
|
||||
Reference in New Issue
Block a user