Skip to content

Commit

Permalink
refactor: simplify v4_base_actions_parser::parse_calldata
Browse files Browse the repository at this point in the history
Streamlined the `parse_calldata` function by using an iterator chain and collection method, reducing the need for manual looping and vector management. This change enhances readability and maintains the same functionality.
  • Loading branch information
shuhuiluo committed Nov 8, 2024
1 parent f5454fb commit 34108b5
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/utils/v4_base_actions_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ pub struct V4RouterCall {
pub fn parse_calldata(calldata: &Bytes) -> Result<V4RouterCall, Error> {
let ActionsParams { actions, params } =
ActionsParams::abi_decode(calldata.iter().as_slice(), true)?;
let mut res = V4RouterCall {
actions: Vec::with_capacity(actions.len()),
};
for (command, data) in zip(actions, params) {
res.actions.push(Actions::abi_decode(command, &data)?);
}
Ok(res)
Ok(V4RouterCall {
actions: zip(actions, params)
.map(|(command, data)| Actions::abi_decode(command, &data))
.collect::<Result<Vec<Actions>, Error>>()?,
})
}

0 comments on commit 34108b5

Please sign in to comment.