Skip to content

Commit

Permalink
Patch provider error handling (#8)
Browse files Browse the repository at this point in the history
* Patch provider error handling

* Fix clippy
  • Loading branch information
Antony1060 authored Jan 14, 2024
1 parent e4a1adb commit 8838667
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,21 @@ impl<M: Middleware> CCIPReadMiddleware<M> {
return Err(CCIPReadMiddlewareError::MiddlewareError(err));
};

Ok(Bytes::from_hex(data)?)
let bytes = Bytes::from_hex(data)?;

if !bytes.starts_with(OFFCHAIN_LOOKUP_SELECTOR) {
return Err(CCIPReadMiddlewareError::MiddlewareError(err));
}

Ok(bytes)
})?;

if !matches!(block_id.unwrap_or(BlockId::Number(BlockNumber::Latest)), BlockId::Number(block) if block.is_latest())
{
return Ok((result, requests_buffer.to_vec()));
}

if tx_sender.is_zero()
|| !result.starts_with(OFFCHAIN_LOOKUP_SELECTOR)
|| result.len() % 32 != 4
{
if tx_sender.is_zero() || result.len() % 32 != 4 {
return Ok((result, requests_buffer.to_vec()));
}

Expand All @@ -279,6 +282,7 @@ impl<M: Middleware> CCIPReadMiddleware<M> {

let decoded_data: Vec<Token> = abi::decode(&output_types, &result[4..])?;

#[allow(clippy::get_first)]
let (
Some(Token::Address(sender)),
Some(Token::Array(urls)),
Expand Down

0 comments on commit 8838667

Please sign in to comment.