From 8a9a95af44bad196bf5fa4961da9ddd4516f5a18 Mon Sep 17 00:00:00 2001 From: Ammar Arif Date: Wed, 30 Oct 2024 11:14:52 -0400 Subject: [PATCH] delete comments --- crates/katana/rpc/rpc/src/starknet/forking.rs | 100 +----------------- crates/katana/rpc/rpc/src/starknet/mod.rs | 8 +- 2 files changed, 8 insertions(+), 100 deletions(-) diff --git a/crates/katana/rpc/rpc/src/starknet/forking.rs b/crates/katana/rpc/rpc/src/starknet/forking.rs index 19cf2c384e..aa2673dfd5 100644 --- a/crates/katana/rpc/rpc/src/starknet/forking.rs +++ b/crates/katana/rpc/rpc/src/starknet/forking.rs @@ -10,7 +10,7 @@ use katana_rpc_types::event::EventsPage; use katana_rpc_types::receipt::TxReceiptWithBlockInfo; use katana_rpc_types::state_update::MaybePendingStateUpdate; use katana_rpc_types::transaction::Tx; -use starknet::core::types::{BlockId, EventFilter, TransactionStatus}; +use starknet::core::types::{EventFilter, TransactionStatus}; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{JsonRpcClient, Provider, ProviderError}; use url::Url; @@ -244,9 +244,11 @@ impl ForkedClient

{ Ok(state_update.into()) } + // NOTE(kariy): The reason why I don't just use EventFilter as a param, bcs i wanna make sure + // the from/to blocks are not None. maybe should do the same for other methods that accept a + // BlockId in some way? pub async fn get_events( &self, - // mut filter: EventFilter, from: BlockNumber, to: BlockNumber, address: Option, @@ -254,28 +256,6 @@ impl ForkedClient

{ continuation_token: Option, chunk_size: u64, ) -> Result { - // // If from_block is given, ensure that it is below the forked block. - // if let Some(id) = filter.from_block { - // match id { - // BlockId::Tag(_) => return Err(Error::BlockTagNotAllowed), - // BlockId::Number(num) if num > self.block => return Err(Error::BlockOutOfRange), - // _ => {} - // } - // } - - // // If to_block is given, ensure that it is below the forked block. - // if let Some(id) = filter.to_block { - // match id { - // BlockId::Tag(_) => return Err(Error::BlockTagNotAllowed), - // BlockId::Number(num) if num > self.block => return Err(Error::BlockOutOfRange), - // _ => {} - // } - // } - // // else if not specified, we limit to the forked block - // else { - // filter.to_block = Some(BlockId::Number(self.block)); - // } - let from_block = Some(BlockIdOrTag::Number(from)); let to_block = Some(BlockIdOrTag::Number(to)); let address = address.map(Felt::from); @@ -298,75 +278,3 @@ impl From for StarknetApiError { } } } - -// #[cfg(test)] -// mod tests { -// use super::*; -// use katana_primitives::block::{BlockNumber, BlockTag}; - -// const SEPOLIA_URL: &str = "https://api.cartridge.gg/x/starknet/sepolia"; -// const FORK_BLOCK_NUMBER: BlockNumber = 268_471; - -// fn forked_client() -> ForkedClient { -// let url = Url::parse(SEPOLIA_URL).unwrap(); -// ForkedClient::new_http(url, FORK_BLOCK_NUMBER) -// } - -// #[tokio::test] -// async fn get_events_after_forked_block() { -// let client = forked_client(); - -// // ----------------------------------------------------------------------- -// // Get events where the from_block is after the forked block. - -// let from = FORK_BLOCK_NUMBER + 1; -// let filter = EventFilter { -// keys: None, -// address: None, -// to_block: None, -// from_block: Some(BlockId::Number(from)), -// }; - -// let result = client.get_events(filter, None, 1).await; -// assert!(matches!(result, Err(Error::BlockOutOfRange))); - -// // ----------------------------------------------------------------------- -// // Get events where the to_block is after the forked block. - -// let to = FORK_BLOCK_NUMBER + 1; -// let filter = EventFilter { -// keys: None, -// address: None, -// from_block: None, -// to_block: Some(BlockId::Number(to)), -// }; - -// let result = client.get_events(filter, None, 1).await; -// assert!(matches!(result, Err(Error::BlockOutOfRange))); -// } - -// #[tokio::test] -// async fn get_events_using_block_tag() { -// let client = forked_client(); - -// let filter = EventFilter { -// keys: None, -// address: None, -// to_block: None, -// from_block: Some(BlockId::Tag(BlockTag::Latest)), -// }; - -// let result = client.get_events(filter, None, 1).await; -// assert!(matches!(result, Err(Error::BlockTagNotAllowed))); - -// let filter = EventFilter { -// keys: None, -// address: None, -// from_block: None, -// to_block: Some(BlockId::Tag(BlockTag::Latest)), -// }; - -// let result = client.get_events(filter, None, 1).await; -// assert!(matches!(result, Err(Error::BlockTagNotAllowed))); -// } -// } diff --git a/crates/katana/rpc/rpc/src/starknet/mod.rs b/crates/katana/rpc/rpc/src/starknet/mod.rs index da4b19a462..1f1e0573af 100644 --- a/crates/katana/rpc/rpc/src/starknet/mod.rs +++ b/crates/katana/rpc/rpc/src/starknet/mod.rs @@ -22,7 +22,7 @@ use katana_primitives::contract::{ContractAddress, Nonce, StorageKey, StorageVal use katana_primitives::conversion::rpc::legacy_inner_to_rpc_class; use katana_primitives::da::L1DataAvailabilityMode; use katana_primitives::env::BlockEnv; -use katana_primitives::event::{ContinuationToken, MaybeForkedContinuationToken}; +use katana_primitives::event::MaybeForkedContinuationToken; use katana_primitives::transaction::{ExecutableTxWithHash, TxHash}; use katana_primitives::Felt; use katana_provider::traits::block::{BlockHashProvider, BlockIdReader, BlockNumberProvider}; @@ -45,8 +45,7 @@ use katana_rpc_types::FeeEstimate; use katana_rpc_types_builder::ReceiptBuilder; use katana_tasks::{BlockingTaskPool, TokioTaskSpawner}; use starknet::core::types::{ - ContractClass, EventFilter, PriceUnit, ResultPageRequest, TransactionExecutionStatus, - TransactionStatus, + ContractClass, PriceUnit, ResultPageRequest, TransactionExecutionStatus, TransactionStatus, }; use crate::utils; @@ -839,7 +838,6 @@ impl StarknetApi { to, event_filter.address.map(|f| f.into()), keys, - // event_filter, continuation_token, chunk_size, )?; @@ -895,6 +893,7 @@ impl StarknetApi { // up until the forked block let to = if to <= forked_block { to } else { forked_block }; + // TODO: simplify this let forked_token = Some(continuation_token.clone()).and_then(|t| match t { None => Some(None), Some(t) => match t { @@ -963,6 +962,7 @@ impl StarknetApi { // pointing to a locally block let to = forked_block; + // TODO: simplify this let forked_token = Some(continuation_token.clone()).and_then(|t| match t { None => Some(None), Some(t) => match t {