|
|
@ -91,13 +91,17 @@ defmodule Explorer.Chain do |
|
|
|
* `:necessity_by_association` - use to load `t:association/0` as `:required` or `:optional`. If an association is |
|
|
|
* `:necessity_by_association` - use to load `t:association/0` as `:required` or `:optional`. If an association is |
|
|
|
`:required`, and the `t:Explorer.Chain.InternalTransaction.t/0` has no associated record for that association, |
|
|
|
`:required`, and the `t:Explorer.Chain.InternalTransaction.t/0` has no associated record for that association, |
|
|
|
then the `t:Explorer.Chain.InternalTransaction.t/0` will not be included in the page `entries`. |
|
|
|
then the `t:Explorer.Chain.InternalTransaction.t/0` will not be included in the page `entries`. |
|
|
|
* `:pagination` - pagination params to pass to scrivener. |
|
|
|
* `:paging_options` - a `t:Explorer.PagingOptions.t/0` used to specify the `:page_size` and |
|
|
|
|
|
|
|
`:key` (a tuple of the lowest/oldest {block_number, transaction_index, index}) and. Results will be the internal |
|
|
|
|
|
|
|
transactions older than the block number, transaction index, and index that are passed. |
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
|
""" |
|
|
|
|
|
|
|
@spec address_to_internal_transactions(Address.t(), [paging_options | necessity_by_association_option]) :: |
|
|
|
|
|
|
|
InternalTransaction.t() |
|
|
|
def address_to_internal_transactions(%Address{hash: hash}, options \\ []) do |
|
|
|
def address_to_internal_transactions(%Address{hash: hash}, options \\ []) do |
|
|
|
necessity_by_association = Keyword.get(options, :necessity_by_association, %{}) |
|
|
|
necessity_by_association = Keyword.get(options, :necessity_by_association, %{}) |
|
|
|
direction = Keyword.get(options, :direction) |
|
|
|
direction = Keyword.get(options, :direction) |
|
|
|
pagination = Keyword.get(options, :pagination, %{}) |
|
|
|
paging_options = Keyword.get(options, :paging_options, %PagingOptions{page_size: 50}) |
|
|
|
|
|
|
|
|
|
|
|
InternalTransaction |
|
|
|
InternalTransaction |
|
|
|
|> join( |
|
|
|
|> join( |
|
|
@ -108,6 +112,8 @@ defmodule Explorer.Chain do |
|
|
|
|> join(:left, [internal_transaction, transaction], block in assoc(transaction, :block)) |
|
|
|
|> join(:left, [internal_transaction, transaction], block in assoc(transaction, :block)) |
|
|
|
|> where_address_fields_match(hash, direction) |
|
|
|
|> where_address_fields_match(hash, direction) |
|
|
|
|> where_transaction_has_multiple_internal_transactions() |
|
|
|
|> where_transaction_has_multiple_internal_transactions() |
|
|
|
|
|
|
|
|> page_internal_transaction(paging_options) |
|
|
|
|
|
|
|
|> limit(^paging_options.page_size) |
|
|
|
|> order_by( |
|
|
|
|> order_by( |
|
|
|
[it, transaction, block], |
|
|
|
[it, transaction, block], |
|
|
|
desc: block.number, |
|
|
|
desc: block.number, |
|
|
@ -116,7 +122,7 @@ defmodule Explorer.Chain do |
|
|
|
) |
|
|
|
) |
|
|
|
|> preload(transaction: :block) |
|
|
|
|> preload(transaction: :block) |
|
|
|
|> join_associations(necessity_by_association) |
|
|
|
|> join_associations(necessity_by_association) |
|
|
|
|> Repo.paginate(pagination) |
|
|
|
|> Repo.all() |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
@ -2525,6 +2531,19 @@ defmodule Explorer.Chain do |
|
|
|
) |
|
|
|
) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp page_internal_transaction(query, %PagingOptions{key: nil}), do: query |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp page_internal_transaction(query, %PagingOptions{key: {block_number, transaction_index, index}}) do |
|
|
|
|
|
|
|
query |
|
|
|
|
|
|
|
|> where( |
|
|
|
|
|
|
|
[internal_transaction, transaction], |
|
|
|
|
|
|
|
transaction.block_number < ^block_number or |
|
|
|
|
|
|
|
(transaction.block_number == ^block_number and transaction.index < ^transaction_index) or |
|
|
|
|
|
|
|
(transaction.block_number == ^block_number and transaction.index == ^transaction_index and |
|
|
|
|
|
|
|
internal_transaction.index < ^index) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp page_transaction(query, %PagingOptions{key: nil}), do: query |
|
|
|
defp page_transaction(query, %PagingOptions{key: nil}), do: query |
|
|
|
|
|
|
|
|
|
|
|
defp page_transaction(query, %PagingOptions{key: {block_number, index}}) do |
|
|
|
defp page_transaction(query, %PagingOptions{key: {block_number, index}}) do |
|
|
|