+ <%= for {idx, event = %{"block_number" => block_number, "from_address" => from_address, "transaction_hash" => tx_hash}} <- Enum.with_index(@page["events"], fn element, index -> {index, element} end) do %>
+
Identifier
- <%= live_redirect(
- Utils.shorten_block_hash(
- "0x01b4d24a461851e8eb9924369b5d9e23e79e8bbea6abc93eae4323462a25ddac_1"
- ),
- to:
- ~p"/#{@network}/events/0x06e681a4da193cfd86e28a2879a17f4aedb4439d61a4a776b1e5686e9a4f96b2",
- class: "text-hover-blue"
- ) %>
+ <% identifier =
+ Integer.to_string(block_number) <> "_" <> Integer.to_string(idx + @page_number) %>
+
+
+
+ <%= live_redirect(
+ identifier,
+ to: ~p"/#{@network}/events/#{identifier}",
+ class: "text-hover-blue"
+ ) %>
+
+
+
+
Block Number
-
98369
+
+
+ <%= live_redirect(to_string(block_number),
+ to: ~p"/#{@network}/blocks/#{event["block_hash"]}"
+ ) %>
+
+
Transaction Hash
- <%= live_redirect(
- Utils.shorten_block_hash(
- "0x01b4d24a461851e8eb9924369b5d9e23e79e8bbea6abc93eae4323462a25ddac"
- ),
- to:
- ~p"/#{@network}/transactions/0x01b4d24a461851e8eb9924369b5d9e23e79e8bbea6abc93eae4323462a25ddac",
- class: "text-hover-blue"
- ) %>
+
+ <%= live_redirect(tx_hash |> Utils.shorten_block_hash(),
+ to: ~p"/#{@network}/transactions/#{tx_hash}"
+ ) %>
+
Name
-
transfer
+
+ <%= Data.get_event_name(event, @network) %>
+
+
From Address
-
From Address
- <%= live_redirect(
- Utils.shorten_block_hash(
- "0x073314940630fd6dcda0d772d4c972c4e0a9946bef9dabf4ef84eda8ef542b82"
- ),
- to:
- ~p"/#{@network}/contracts/0x06e681a4da193cfd86e28a2879a17f4aedb4439d61a4a776b1e5686e9a4f96b2",
- class: "text-hover-blue"
+ <%= live_redirect(from_address |> Utils.shorten_block_hash(),
+ to: ~p"/#{@network}/contracts/#{from_address}"
) %>
Age
-
7min
+
+ <%= Utils.get_block_age(@block) %>
+
<% end %>
@@ -79,14 +105,25 @@ defmodule StarknetExplorerWeb.EventIndexLive do
@impl true
def mount(_params, _session, socket) do
- Process.send(self(), :load_events, [])
+ block_height = BlockUtils.block_height(socket.assigns.network) - 1
+ {:ok, block} = Rpc.get_block_by_number(block_height, socket.assigns.network)
- {:ok, assign(socket, events: [])}
- end
+ {:ok, page} =
+ Data.get_events(
+ %{
+ "chunk_size" => @page_size,
+ "from_block" => %{"block_number" => block_height},
+ "to_block" => %{"block_number" => block_height}
+ },
+ socket.assigns.network
+ )
- @impl true
- def handle_info(:load_events, socket) do
- # TODO: Fetch this from the db
- {:noreply, assign(socket, events: [])}
+ assigns = [
+ page: page,
+ page_number: 0,
+ block: block
+ ]
+
+ {:ok, assign(socket, assigns)}
end
end
diff --git a/lib/starknet_explorer_web/live/transaction_live.ex b/lib/starknet_explorer_web/live/transaction_live.ex
index 43b9aa2e..808b3704 100644
--- a/lib/starknet_explorer_web/live/transaction_live.ex
+++ b/lib/starknet_explorer_web/live/transaction_live.ex
@@ -1,8 +1,7 @@
defmodule StarknetExplorerWeb.TransactionLive do
use StarknetExplorerWeb, :live_view
alias StarknetExplorerWeb.Utils
- alias StarknetExplorer.Data
- alias StarknetExplorer.Message
+ alias StarknetExplorer.{Data, Message, Rpc, BlockUtils}
defp transaction_header(assigns) do
~H"""
@@ -108,45 +107,36 @@ defmodule StarknetExplorerWeb.TransactionLive do
Identifier
Block Number
-
Transaction Hash
Name
- <%= if @transaction.sender_address do %>
-
From Address
- <% end %>
+
From Address
Age
- <%= for %{keys: [identifier | _], from_address: _} <- @events do %>
+ <%= for event <- @transaction_receipt.events do %>
Identifier
- <%= identifier |> Utils.shorten_block_hash() %>
+ <%= # TODO, this wont work yet. Fix when using SQL.
+ @transaction_receipt.block_number %>
Block Number
<%= @transaction_receipt.block_number %>
-
-
Transaction Hash
-
<%= @transaction.hash |> Utils.shorten_block_hash() %>
-
Name
- Transfer
- Mocked
+ <%= Data.get_event_name(event, @network) %>
- <%= if @transaction.sender_address do %>
-
-
From Address
-
<%= @transaction.sender_address |> Utils.shorten_block_hash() %>
-
- <% end %>
+
+
From Address
+
<%= event.from_address |> Utils.shorten_block_hash() %>
+
Age
-
1h
+
<%= Utils.get_block_age_from_timestamp(@block_timestamp) %>
<% end %>
@@ -580,6 +570,9 @@ defmodule StarknetExplorerWeb.TransactionLive do
{:ok, transaction = %{receipt: receipt}} =
Data.full_transaction(transaction_hash, socket.assigns.network)
+ {:ok, %{"timestamp" => block_timestamp}} =
+ Rpc.get_block_by_hash(receipt.block_hash, socket.assigns.network)
+
# a tx should not have both L1->L2 and L2->L1 messages AFAIK, but just in case merge both scenarios
messages_sent =
(Message.from_transaction_receipt(receipt) ++ [Message.from_transaction(transaction)])
@@ -606,7 +599,8 @@ defmodule StarknetExplorerWeb.TransactionLive do
transaction_hash: transaction_hash,
transaction_view: "overview",
events: receipt.events,
- messages: messages_sent
+ messages: messages_sent,
+ block_timestamp: block_timestamp
]
socket = assign(socket, assigns)
diff --git a/lib/starknet_rpc.ex b/lib/starknet_rpc.ex
index 3de80e06..5b966409 100644
--- a/lib/starknet_rpc.ex
+++ b/lib/starknet_rpc.ex
@@ -24,6 +24,16 @@ defmodule StarknetExplorer.Rpc do
network
)
+ def get_events(params, network),
+ do:
+ send_request(
+ "starknet_getEvents",
+ [
+ params
+ ],
+ network
+ )
+
def get_block_height_no_cache(network),
do: send_request_no_cache("starknet_blockNumber", [], network)