fix(timelag): normalize block if block = None (#1146)

* fix(timelag): normalize block if block = None

* lint: nightly formatter

Co-authored-by: James <james@prestwi.ch>
This commit is contained in:
Luke Tchang 2022-04-14 13:20:35 -06:00 committed by GitHub
parent 02ad93a1cf
commit 1cc42cbba0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 7 deletions

View File

@ -57,6 +57,7 @@ where
Some(BlockId::Number(n)) => { Some(BlockId::Number(n)) => {
Ok(self.normalize_block_number(Some(n)).await?.map(Into::into)) Ok(self.normalize_block_number(Some(n)).await?.map(Into::into))
} }
None => Ok(self.normalize_block_number(None).await?.map(Into::into)),
_ => Ok(id), _ => Ok(id),
} }
} }
@ -65,16 +66,17 @@ where
&self, &self,
number: Option<BlockNumber>, number: Option<BlockNumber>,
) -> TimeLagResult<Option<BlockNumber>, M> { ) -> TimeLagResult<Option<BlockNumber>, M> {
let tip = self.get_block_number().await?; let lag_tip = self.get_block_number().await?;
match number { match number {
Some(BlockNumber::Latest) => Ok(Some(BlockNumber::Number(tip))), Some(BlockNumber::Latest) => Ok(Some(BlockNumber::Number(lag_tip))),
Some(BlockNumber::Number(n)) => { Some(BlockNumber::Number(n)) => {
if n > tip { if n < lag_tip {
Ok(Some(BlockNumber::Latest)) Ok(Some(BlockNumber::Number(n)))
} else { } else {
Ok(number) Ok(Some(BlockNumber::Number(lag_tip)))
} }
} }
None => Ok(Some(BlockNumber::Number(lag_tip))),
_ => Ok(number), _ => Ok(number),
} }
} }
@ -121,7 +123,6 @@ where
tx: T, tx: T,
block: Option<BlockId>, block: Option<BlockId>,
) -> Result<ethers_providers::PendingTransaction<'_, Self::Provider>, Self::Error> { ) -> Result<ethers_providers::PendingTransaction<'_, Self::Provider>, Self::Error> {
let block = self.normalize_block_id(block).await?;
self.inner().send_transaction(tx, block).await.map_err(ethers_providers::FromErr::from) self.inner().send_transaction(tx, block).await.map_err(ethers_providers::FromErr::from)
} }
@ -271,7 +272,6 @@ where
tx: &mut TypedTransaction, tx: &mut TypedTransaction,
block: Option<BlockId>, block: Option<BlockId>,
) -> Result<(), Self::Error> { ) -> Result<(), Self::Error> {
let block = self.normalize_block_id(block).await?;
self.inner().fill_transaction(tx, block).await.map_err(ethers_providers::FromErr::from) self.inner().fill_transaction(tx, block).await.map_err(ethers_providers::FromErr::from)
} }