Tx in coin balance history

pull/3354/head
Victor Baranov 4 years ago
parent 32f52b8e76
commit 9cead099c7
  1. 1
      CHANGELOG.md
  2. 11
      apps/block_scout_web/lib/block_scout_web/templates/address_coin_balance/_coin_balances.html.eex
  3. 14
      apps/explorer/lib/explorer/chain/address/coin_balance.ex

@ -1,6 +1,7 @@
## Current ## Current
### Features ### 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 - [#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 - [#3330](https://github.com/poanetwork/blockscout/pull/3330) - Caching of address transactions counter, remove query 10_000 rows limit

@ -1,15 +1,22 @@
<div class="tile tile-type-coin-balance fade-up" data-test="coin_balance" data-block-number="<%= to_string(@coin_balance.block_number) %>"> <div class="tile tile-type-coin-balance fade-up" data-test="coin_balance" data-block-number="<%= to_string(@coin_balance.block_number) %>">
<div class="row justify-content align-items-center"> <div class="row justify-content align-items-center">
<div class="col-md-3 d-flex flex-column mt-3 mt-md-0"> <div class="col-md-6 d-flex flex-column mt-3 mt-md-0">
<%= link( <%= link(
to: block_path(@conn, :show, @coin_balance.block_number), to: block_path(@conn, :show, @coin_balance.block_number),
class: "tile-title-lg" class: "tile-title-lg"
) do %> ) do %>
<%= gettext "Block" %> <%= @coin_balance.block_number %> <%= gettext "Block" %> <%= @coin_balance.block_number %>
<% end %> <% end %>
<%= if @coin_balance.transaction_hash do %>
<%= link(
to: transaction_path(@conn, :show, @coin_balance.transaction_hash)
) do %>
<%= @coin_balance.transaction_hash %>
<% end %>
<% end %>
<span data-from-now="<%= @coin_balance.block_timestamp %>"></span> <span data-from-now="<%= @coin_balance.block_timestamp %>"></span>
</div> </div>
<div class="col-md-3 offset-md-3 d-flex flex-column text-md-right mt-3 mt-md-0"> <div class="col-md-3 d-flex flex-column text-md-right mt-3 mt-md-0">
<span class="tile-title-lg align-bottom" data-balance-change-sign="<%= delta_sign(@coin_balance.delta) %>"> <span class="tile-title-lg align-bottom" data-balance-change-sign="<%= delta_sign(@coin_balance.delta) %>">
<%= delta_arrow(@coin_balance.delta) %> <%= delta_arrow(@coin_balance.delta) %>
<%= format_delta(@coin_balance.delta) %> <%= format_delta(@coin_balance.delta) %>

@ -7,7 +7,7 @@ defmodule Explorer.Chain.Address.CoinBalance do
use Explorer.Schema use Explorer.Schema
alias Explorer.PagingOptions alias Explorer.PagingOptions
alias Explorer.Chain.{Address, Block, Hash, Wei} alias Explorer.Chain.{Address, Block, Hash, Transaction, Wei}
alias Explorer.Chain.Address.CoinBalance alias Explorer.Chain.Address.CoinBalance
@optional_fields ~w(value value_fetched_at)a @optional_fields ~w(value value_fetched_at)a
@ -42,6 +42,8 @@ defmodule Explorer.Chain.Address.CoinBalance do
field(:value, Wei) field(:value, Wei)
field(:value_fetched_at, :utc_datetime_usec) field(:value_fetched_at, :utc_datetime_usec)
field(:delta, Wei, virtual: true) 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) field(:block_timestamp, :utc_datetime_usec, virtual: true)
timestamps() timestamps()
@ -82,10 +84,18 @@ defmodule Explorer.Chain.Address.CoinBalance do
query = query =
from( from(
cb in CoinBalance, 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: cb.address_hash == ^address_hash,
where: not is_nil(cb.value), where: not is_nil(cb.value),
order_by: [desc: :block_number], 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), from(balance in subquery(query),

Loading…
Cancel
Save