diff --git a/CHANGELOG.md b/CHANGELOG.md index b458708e6b..8108db4e23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Current ### Features +- [#3354](https://github.com/poanetwork/blockscout/pull/3354) - Tx hash in coin balance history - [#3333](https://github.com/poanetwork/blockscout/pull/3333), [#3337](https://github.com/poanetwork/blockscout/pull/3337) - Dark forest contract custom theme - [#3330](https://github.com/poanetwork/blockscout/pull/3330) - Caching of address transactions counter, remove query 10_000 rows limit diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_coin_balance/_coin_balances.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_coin_balance/_coin_balances.html.eex index bf9acb15f0..74e974b32a 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_coin_balance/_coin_balances.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_coin_balance/_coin_balances.html.eex @@ -1,15 +1,22 @@
-
+
<%= link( to: block_path(@conn, :show, @coin_balance.block_number), class: "tile-title-lg" ) do %> <%= gettext "Block" %> <%= @coin_balance.block_number %> <% end %> + <%= if @coin_balance.transaction_hash do %> + <%= link( + to: transaction_path(@conn, :show, @coin_balance.transaction_hash) + ) do %> + <%= @coin_balance.transaction_hash %> + <% end %> + <% end %>
-
+
<%= delta_arrow(@coin_balance.delta) %> <%= format_delta(@coin_balance.delta) %> diff --git a/apps/explorer/lib/explorer/chain/address/coin_balance.ex b/apps/explorer/lib/explorer/chain/address/coin_balance.ex index 212b25075d..7d36c57f67 100644 --- a/apps/explorer/lib/explorer/chain/address/coin_balance.ex +++ b/apps/explorer/lib/explorer/chain/address/coin_balance.ex @@ -7,7 +7,7 @@ defmodule Explorer.Chain.Address.CoinBalance do use Explorer.Schema alias Explorer.PagingOptions - alias Explorer.Chain.{Address, Block, Hash, Wei} + alias Explorer.Chain.{Address, Block, Hash, Transaction, Wei} alias Explorer.Chain.Address.CoinBalance @optional_fields ~w(value value_fetched_at)a @@ -42,6 +42,8 @@ defmodule Explorer.Chain.Address.CoinBalance do field(:value, Wei) field(:value_fetched_at, :utc_datetime_usec) field(:delta, Wei, virtual: true) + field(:transaction_hash, Hash.Full, virtual: true) + field(:transaction_value, Wei, virtual: true) field(:block_timestamp, :utc_datetime_usec, virtual: true) timestamps() @@ -82,10 +84,18 @@ defmodule Explorer.Chain.Address.CoinBalance do query = from( cb in CoinBalance, + left_join: tx in Transaction, + on: + cb.block_number == tx.block_number and tx.value > ^0 and + (cb.address_hash == tx.to_address_hash or cb.address_hash == tx.from_address_hash), where: cb.address_hash == ^address_hash, where: not is_nil(cb.value), order_by: [desc: :block_number], - select_merge: %{delta: fragment("value - coalesce(lead(value, 1) over (order by block_number desc), 0)")} + select_merge: %{ + delta: fragment("a0.value - coalesce(lead(a0.value, 1) over (order by a0.block_number desc), 0)"), + transaction_hash: tx.hash, + transaction_value: tx.value + } ) from(balance in subquery(query),