feat: Add EncodingError

Change method signatures to expect it and raise it where it makes sense

--- don't change below this line ---
ENG-4076 <#DTT#>
This commit is contained in:
Diana Carvalho
2025-01-17 13:18:28 +00:00
parent e77a50b2bb
commit bab5caa6f8
12 changed files with 100 additions and 38 deletions

View File

@@ -1,18 +1,19 @@
use alloy_primitives::{Address, Keccak256, U256};
use alloy_sol_types::SolValue;
use anyhow::Error;
use num_bigint::BigUint;
use tycho_core::Bytes;
use crate::encoding::errors::EncodingError;
/// Safely converts a `Bytes` object to an `Address` object.
///
/// Checks the length of the `Bytes` before attempting to convert, and returns a `SimulationError`
/// Checks the length of the `Bytes` before attempting to convert, and returns an `EncodingError`
/// if not 20 bytes long.
pub fn bytes_to_address(address: &Bytes) -> Result<Address, Error> {
pub fn bytes_to_address(address: &Bytes) -> Result<Address, EncodingError> {
if address.len() == 20 {
Ok(Address::from_slice(address))
} else {
Err(anyhow::format_err!("Invalid ERC20 token address: {:?}", address))
Err(EncodingError::InvalidInput(format!("Invalid ERC20 token address: {:?}", address)))
}
}