Skip to content

Commit

Permalink
delete comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Oct 30, 2024
1 parent 9a845ca commit 200c95c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 100 deletions.
100 changes: 4 additions & 96 deletions crates/katana/rpc/rpc/src/starknet/forking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -244,38 +244,18 @@ impl<P: Provider> ForkedClient<P> {
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<ContractAddress>,
keys: Option<Vec<Vec<Felt>>>,
continuation_token: Option<String>,
chunk_size: u64,
) -> Result<EventsPage, Error> {
// // 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);
Expand All @@ -298,75 +278,3 @@ impl From<Error> 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)));
// }
// }
8 changes: 4 additions & 4 deletions crates/katana/rpc/rpc/src/starknet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand Down Expand Up @@ -839,7 +838,6 @@ impl<EF: ExecutorFactory> StarknetApi<EF> {
to,
event_filter.address.map(|f| f.into()),
keys,
// event_filter,
continuation_token,
chunk_size,
)?;
Expand Down Expand Up @@ -895,6 +893,7 @@ impl<EF: ExecutorFactory> StarknetApi<EF> {
// 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 {
Expand Down Expand Up @@ -963,6 +962,7 @@ impl<EF: ExecutorFactory> StarknetApi<EF> {
// 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 {
Expand Down

0 comments on commit 200c95c

Please sign in to comment.