Skip to content

Commit e6a5de4

Browse files
JulianVenturaJulian Venturaavilagaston9MauroToscanoJuArce
authored
hotfix(explorer): Add endpoint to fetch last 24 hours number of proofs verified (#1710)
Co-authored-by: Julian Ventura <[email protected]> Co-authored-by: avilagaston9 <[email protected]> Co-authored-by: Mauro Toscano <[email protected]> Co-authored-by: JuArce <[email protected]>
1 parent de2f3d5 commit e6a5de4

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

explorer/lib/explorer/models/batches.ex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,20 @@ defmodule Batches do
164164
end
165165
end
166166

167+
def get_verified_proofs_in_last_24_hours() do
168+
minutes_in_a_day = 1440
169+
threshold_datetime = DateTime.utc_now() |> DateTime.add(-1 * minutes_in_a_day, :minute) # Last 24 hours
170+
171+
query = from(b in Batches,
172+
where: b.is_verified == true and b.submission_timestamp > ^threshold_datetime,
173+
select: sum(b.amount_of_proofs))
174+
175+
case Explorer.Repo.one(query) do
176+
nil -> 0
177+
result -> result
178+
end
179+
end
180+
167181
def insert_or_update(batch_changeset, proofs) do
168182
merkle_root = batch_changeset.changes.merkle_root
169183
stored_proofs = Proofs.get_proofs_from_batch(%{merkle_root: merkle_root})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
defmodule ExplorerWeb.DataController do
2+
use ExplorerWeb, :controller
3+
4+
def verified_proofs_in_last_24_hours(conn, _params) do
5+
verified_proofs_in_last_24_hours = Batches.get_verified_proofs_in_last_24_hours()
6+
render(conn, :show, count: verified_proofs_in_last_24_hours)
7+
end
8+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
defmodule ExplorerWeb.DataJSON do
2+
def show(%{count: last_verified_proofs_count}) do
3+
%{
4+
count: last_verified_proofs_count
5+
}
6+
end
7+
end

explorer/lib/explorer_web/router.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ defmodule ExplorerWeb.Router do
3232
plug :accepts, ["json"]
3333
end
3434

35+
scope "/api", ExplorerWeb do
36+
pipe_through :api
37+
get "/proofs_verified_last_24h", DataController, :verified_proofs_in_last_24_hours
38+
end
39+
3540
scope "/", ExplorerWeb do
3641
pipe_through :browser
3742

3843
# https://fly.io/phoenix-files/live-session/
39-
live_session :default,
44+
live_session :default,
4045
on_mount: [{ExplorerWeb.Hooks, :add_host}, {ExplorerWeb.Hooks, :add_theme}] do
4146
live "/", Home.Index
4247
live "/batches/:merkle_root", Batch.Index

0 commit comments

Comments
 (0)