Skip to content

Commit a25f012

Browse files
JulianVenturaJulian Venturaavilagaston9
authored
hotfix(explorer): Add fee_per_proof average to the data endpoint. (#1713)
Co-authored-by: Julian Ventura <[email protected]> Co-authored-by: avilagaston9 <[email protected]>
1 parent e6a5de4 commit a25f012

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

explorer/lib/explorer/models/batches.ex

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,23 @@ defmodule Batches do
164164
end
165165
end
166166

167-
def get_verified_proofs_in_last_24_hours() do
167+
def get_last_24h_verified_proof_stats() do
168168
minutes_in_a_day = 1440
169169
threshold_datetime = DateTime.utc_now() |> DateTime.add(-1 * minutes_in_a_day, :minute) # Last 24 hours
170170

171171
query = from(b in Batches,
172172
where: b.is_verified == true and b.submission_timestamp > ^threshold_datetime,
173-
select: sum(b.amount_of_proofs))
173+
select: {sum(b.amount_of_proofs), avg(b.fee_per_proof)})
174174

175-
case Explorer.Repo.one(query) do
176-
nil -> 0
175+
{amount_of_proofs, avg_fee_per_proof} = case Explorer.Repo.one(query) do
176+
nil -> {0, 0.0}
177177
result -> result
178178
end
179+
180+
%{
181+
amount_of_proofs: amount_of_proofs,
182+
avg_fee_per_proof: avg_fee_per_proof
183+
}
179184
end
180185

181186
def insert_or_update(batch_changeset, proofs) do

explorer/lib/explorer_web/controllers/data_controller.ex

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@ defmodule ExplorerWeb.DataController do
22
use ExplorerWeb, :controller
33

44
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)
5+
%{
6+
amount_of_proofs: amount_of_proofs,
7+
avg_fee_per_proof: avg_fee_per_proof
8+
} = Batches.get_last_24h_verified_proof_stats()
9+
10+
avg_fee_per_proof_usd =
11+
case EthConverter.wei_to_usd_sf(avg_fee_per_proof, 2) do
12+
{:ok, value} -> value
13+
_ -> 0
14+
end
15+
16+
render(conn, :show, %{
17+
amount_of_proofs: amount_of_proofs,
18+
avg_fee_per_proof_usd: avg_fee_per_proof_usd
19+
})
720
end
821
end
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
defmodule ExplorerWeb.DataJSON do
2-
def show(%{count: last_verified_proofs_count}) do
2+
def show(%{
3+
amount_of_proofs: amount_of_proofs,
4+
avg_fee_per_proof_usd: avg_fee_per_proof_usd
5+
}) do
36
%{
4-
count: last_verified_proofs_count
7+
amount_of_proofs: amount_of_proofs,
8+
avg_fee_per_proof_usd: avg_fee_per_proof_usd
59
}
610
end
711
end

0 commit comments

Comments
 (0)