Skip to content

Commit 155d5de

Browse files
fix(explorer): handle empty events from batcher payment system (#888)
Co-authored-by: Mariano A. Nicolini <[email protected]>
1 parent b2982a9 commit 155d5de

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

explorer/lib/explorer/contract_managers/batcher_payment_service_manager.ex

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,24 @@ defmodule BatcherPaymentServiceManager do
4848
)
4949
|> Ethers.get_logs(fromBlock: @first_block)
5050
|> case do
51+
{:ok, []} ->
52+
Logger.warning("No fee per proof events found for merkle root: #{merkle_root}.")
53+
0
54+
5155
{:ok, events} ->
5256
event = events |> hd()
5357
fee_per_proof = event.data |> hd()
54-
Logger.debug("Fee per proof of #{merkle_root}: #{fee_per_proof} wei")
58+
Logger.debug("Fee per proof of #{merkle_root}: #{fee_per_proof} WEI.")
5559

5660
fee_per_proof
5761

5862
{:error, reason} ->
59-
Logger.error("Error getting gas per proof: #{inspect(reason)}")
60-
raise("Error getting gas per proof")
63+
Logger.error("Error getting fee per proof: #{inspect(reason)}.")
64+
raise("Error getting fee per proof events.")
6165

6266
other ->
63-
Logger.error("Unexpected response: #{inspect(other)}")
64-
raise("Unexpected response")
67+
Logger.error("Unexpected response on fee per proof events: #{inspect(other)}")
68+
raise("Unexpected response on fee per proof events.")
6569
end
6670
end
6771
end

explorer/lib/explorer/models/batches.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ defmodule Batches do
3434
|> validate_format(:submission_transaction_hash, ~r/0x[a-fA-F0-9]{64}/)
3535
|> validate_number(:response_block_number, greater_than: 0)
3636
|> validate_format(:response_transaction_hash, ~r/0x[a-fA-F0-9]{64}/)
37-
|> validate_number(:fee_per_proof, greater_than: 0)
37+
|> validate_number(:fee_per_proof, greater_than_or_equal_to: 0)
3838
end
3939

4040
def cast_to_batches(%BatchDB{} = batch_db) do

explorer/lib/explorer_web/live/pages/batch/index.html.heex

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,20 @@
3939
</h3>
4040
<p><%= @current_batch.amount_of_proofs %></p>
4141
</div>
42-
<%= if @current_batch.fee_per_proof != nil do %>
43-
<div class="flex flex-col sm:flex-row">
44-
<h3>
45-
Cost per Proof:
46-
</h3>
47-
<p>
48-
<%= @current_batch.fee_per_proof |> EthConverter.wei_to_eth() %> ETH
49-
<%= if @eth_usd_price != :empty and @eth_usd_price != "0.00000" do %>
50-
<span class="inline-flex md:inline-block">(<%= @eth_usd_price %> USD)</span>
51-
<% end %>
52-
</p>
53-
</div>
54-
<% end %>
42+
<div
43+
:if={@current_batch.fee_per_proof != 0}
44+
class="flex flex-col sm:flex-row"
45+
>
46+
<h3>
47+
Fee per Proof:
48+
</h3>
49+
<p>
50+
<%= @current_batch.fee_per_proof |> EthConverter.wei_to_eth() %> ETH
51+
<%= if @eth_usd_price != :empty and @eth_usd_price != "0.00000" do %>
52+
<span class="inline-flex md:inline-block">(<%= @eth_usd_price %> USD)</span>
53+
<% end %>
54+
</p>
55+
</div>
5556
<div>
5657
<h3>
5758
Proofs in this batch:

0 commit comments

Comments
 (0)