Merge pull request #3835 from blockscout/vb-fix-gettoken-holders-pagination

Fix getTokenHolders API endpoint pagination
pull/3870/head
Victor Baranov 4 years ago committed by GitHub
commit f6a6d237c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 4
      apps/explorer/lib/explorer/chain/address/current_token_balance.ex

@ -7,6 +7,7 @@
- [#3750](https://github.com/blockscout/blockscout/pull/3750) - getblocknobytime block module API endpoint
### Fixes
- [#3835](https://github.com/blockscout/blockscout/pull/3835) - Fix getTokenHolders API endpoint pagination
- [#3787](https://github.com/blockscout/blockscout/pull/3787) - Improve tokens list elements display
- [#3785](https://github.com/blockscout/blockscout/pull/3785) - Fix for write contract functionality: false and 0 boolean inputs are parsed as true
- [#3783](https://github.com/blockscout/blockscout/pull/3783) - Fix number of block confirmations

@ -9,7 +9,7 @@ defmodule Explorer.Chain.Address.CurrentTokenBalance do
use Explorer.Schema
import Ecto.Changeset
import Ecto.Query, only: [from: 2, limit: 2, order_by: 3, preload: 2, where: 3]
import Ecto.Query, only: [from: 2, limit: 2, offset: 2, order_by: 3, preload: 2, where: 3]
alias Explorer.{Chain, PagingOptions}
alias Explorer.Chain.{Address, Block, Hash, Token}
@ -85,6 +85,7 @@ defmodule Explorer.Chain.Address.CurrentTokenBalance do
"""
def token_holders_ordered_by_value(token_contract_address_hash, options \\ []) do
paging_options = Keyword.get(options, :paging_options, @default_paging_options)
offset = (max(paging_options.page_number, 1) - 1) * paging_options.page_size
token_contract_address_hash
|> token_holders_query
@ -92,6 +93,7 @@ defmodule Explorer.Chain.Address.CurrentTokenBalance do
|> order_by([tb], desc: :value)
|> page_token_balances(paging_options)
|> limit(^paging_options.page_size)
|> offset(^offset)
end
@doc """

Loading…
Cancel
Save