From 36d4029ce8f39109da972acaa948849b2a3793af Mon Sep 17 00:00:00 2001 From: apoorvsadana <95699312+apoorvsadana@users.noreply.github.com> Date: Thu, 4 Jan 2024 20:31:04 +0530 Subject: [PATCH] fix events call with continuation token (#394) --- .gitignore | 3 +++ lib/starknet_explorer/events.ex | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index cb5a36b8..bba87b64 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,9 @@ npm-debug.log # Ignore docker volumes .volumes +# Ignore .env +.env + # Ignore juno files juno_files diff --git a/lib/starknet_explorer/events.ex b/lib/starknet_explorer/events.ex index 42829636..278787bf 100644 --- a/lib/starknet_explorer/events.ex +++ b/lib/starknet_explorer/events.ex @@ -204,18 +204,18 @@ defmodule StarknetExplorer.Events do Enum.flat_map_reduce(1..1000, nil, fn _, acc -> if acc == "last_page_reached" do {:halt, acc} - end - - case try_fetch_next_page(block_hash, network, acc) do - {:ok, %{"events" => events, "continuation_token" => continuation_token}} -> - {events, continuation_token} - - # when no continuation token is present, this means that we reached the end of the events. - {:ok, %{"events" => events}} -> - {events, "last_page_reached"} - - _err -> - {:halt, acc} + else + case try_fetch_next_page(block_hash, network, acc) do + {:ok, %{"events" => events, "continuation_token" => continuation_token}} -> + {events, continuation_token} + + # when no continuation token is present, this means that we reached the end of the events. + {:ok, %{"events" => events}} -> + {events, "last_page_reached"} + + _err -> + {:halt, acc} + end end end)