From 2ab07e6ed242ae9f34d59f8b6a4c95786fb029cb Mon Sep 17 00:00:00 2001 From: Elias Tazartes <66871571+Eikix@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:02:29 +0100 Subject: [PATCH] set conversion of blocktag latest to sn pending (#816) * set conversion of blocktag latest to sn pending * transform pending blocks into pending blocks * clean up --- src/eth_provider/provider.rs | 8 ++++---- src/models/block.rs | 8 +++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/eth_provider/provider.rs b/src/eth_provider/provider.rs index fefa40121..e05fc858a 100644 --- a/src/eth_provider/provider.rs +++ b/src/eth_provider/provider.rs @@ -668,10 +668,10 @@ where match tag { BlockNumberOrTag::Earliest => Ok(U64::ZERO), BlockNumberOrTag::Number(number) => Ok(U64::from(number)), - BlockNumberOrTag::Latest | BlockNumberOrTag::Finalized | BlockNumberOrTag::Safe => { - self.block_number().await - } - BlockNumberOrTag::Pending => todo!("pending block number not implemented"), + BlockNumberOrTag::Latest + | BlockNumberOrTag::Finalized + | BlockNumberOrTag::Safe + | BlockNumberOrTag::Pending => self.block_number().await, } } } diff --git a/src/models/block.rs b/src/models/block.rs index 7930ad589..8166c40fe 100644 --- a/src/models/block.rs +++ b/src/models/block.rs @@ -50,11 +50,13 @@ impl From for StarknetBlockId { fn from(block_number_or_tag: EthBlockNumberOrTag) -> Self { let block_number_or_tag = block_number_or_tag.into(); match block_number_or_tag { - BlockNumberOrTag::Safe | BlockNumberOrTag::Latest | BlockNumberOrTag::Finalized => { - Self::Tag(BlockTag::Latest) + BlockNumberOrTag::Latest | BlockNumberOrTag::Pending => { + // We set to pending because in Starknet, a pending block is an unsealed block, + // With a centralized sequencer, the latest block is the pending block being filled. + Self::Tag(BlockTag::Pending) } + BlockNumberOrTag::Safe | BlockNumberOrTag::Finalized => Self::Tag(BlockTag::Latest), BlockNumberOrTag::Earliest => Self::Number(0), - BlockNumberOrTag::Pending => Self::Tag(BlockTag::Pending), BlockNumberOrTag::Number(number) => Self::Number(number), } }