Merge pull request #2616 from poanetwork/ab-remove-duplicates-from-coin-history

deduplicate coin history records by delta
pull/2640/head
Victor Baranov 5 years ago committed by GitHub
commit 99475c2ad6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 7
      apps/explorer/lib/explorer/chain.ex
  3. 26
      apps/explorer/test/explorer/chain_test.exs

@ -8,6 +8,7 @@
### Fixes ### Fixes
- [#2623](https://github.com/poanetwork/blockscout/pull/2623) - fix a blinking test - [#2623](https://github.com/poanetwork/blockscout/pull/2623) - fix a blinking test
- [#2616](https://github.com/poanetwork/blockscout/pull/2616) - deduplicate coin history records by delta
- [#2613](https://github.com/poanetwork/blockscout/pull/2613) - fix getminedblocks rpc endpoint - [#2613](https://github.com/poanetwork/blockscout/pull/2613) - fix getminedblocks rpc endpoint
- [#2592](https://github.com/poanetwork/blockscout/pull/2592) - process new metadata format for whisper - [#2592](https://github.com/poanetwork/blockscout/pull/2592) - process new metadata format for whisper
- [#2572](https://github.com/poanetwork/blockscout/pull/2572) - Ease non-critical css - [#2572](https://github.com/poanetwork/blockscout/pull/2572) - Ease non-critical css

@ -2967,6 +2967,13 @@ defmodule Explorer.Chain do
|> CoinBalance.fetch_coin_balances(paging_options) |> CoinBalance.fetch_coin_balances(paging_options)
|> page_coin_balances(paging_options) |> page_coin_balances(paging_options)
|> Repo.all() |> Repo.all()
|> Enum.dedup_by(fn record ->
if record.delta == Decimal.new(0) do
:dup
else
System.unique_integer()
end
end)
end end
def get_coin_balance(address_hash, block_number) do def get_coin_balance(address_hash, block_number) do

@ -4159,4 +4159,30 @@ defmodule Explorer.ChainTest do
assert Chain.staking_pools_count(:inactive) == 1 assert Chain.staking_pools_count(:inactive) == 1
end end
end end
describe "address_to_coin_balances/2" do
test "deduplicates records by zero delta" do
address = insert(:address)
1..5
|> Enum.each(fn block_number ->
insert(:block, number: block_number)
insert(:fetched_balance, value: 1, block_number: block_number, address_hash: address.hash)
end)
insert(:block, number: 6)
insert(:fetched_balance, value: 2, block_number: 6, address_hash: address.hash)
assert [first, second, third] = Chain.address_to_coin_balances(address.hash, [])
assert first.block_number == 6
assert first.delta == Decimal.new(1)
assert second.block_number == 5
assert second.delta == Decimal.new(0)
assert third.block_number == 1
assert third.delta == Decimal.new(1)
end
end
end end

Loading…
Cancel
Save