Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mod.rs #2666

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions crates/katana/rpc/rpc/src/starknet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ use crate::utils;
use crate::utils::events::{Cursor, EventBlockId};

pub type StarknetApiResult<T> = Result<T, StarknetApiError>;
const MAX_CHUNK_SIZE: usize = 100;

#[allow(missing_debug_implementations)]
pub struct StarknetApi<EF: ExecutorFactory> {
Expand Down Expand Up @@ -499,6 +500,36 @@ impl<EF: ExecutorFactory> StarknetApi<EF> {
}
}


async fn get_events_with_limit(
&self,
filter: EventFilterWithPage,
chunk_size: usize,
) -> StarknetApiResult<EventsPage> {
// Ensure the chunk size is within a reasonable limit
if chunk_size == 0 || chunk_size > Self::MAX_CHUNK_SIZE {
return Err(StarknetApiError::InvalidChunkSize);
}

// Fetch events based on the provided filter and chunk size
let events = self.fetch_events(filter).await?;

// Paginate the results based on the specified chunk size
let paginated_events = events.into_iter().take(chunk_size).collect::<Vec<_>>();

// Prepare the response with the paginated events
let next_token = if events.len() > chunk_size {
Some(generate_next_token(&paginated_events))
} else {
None
};

Ok(EventsPage {
events: paginated_events,
continuation_token: next_token,
})
}

async fn transaction_status(&self, hash: TxHash) -> StarknetApiResult<TransactionStatus> {
let status = self
.on_io_blocking_task(move |this| {
Expand Down