Add transaction_tags to all tx controllers

account
Oleg Sovetnik 3 years ago committed by Viktor Baranov
parent afb1c8cccf
commit dfd4de1aa2
  1. 13
      apps/block_scout_web/lib/block_scout_web/controllers/transaction_internal_transaction_controller.ex
  2. 9
      apps/block_scout_web/lib/block_scout_web/controllers/transaction_log_controller.ex
  3. 10
      apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex
  4. 13
      apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex
  5. 17
      apps/block_scout_web/lib/block_scout_web/models/get_transaction_tags.ex
  6. 6
      apps/explorer/lib/explorer/accounts/notify.ex

@ -3,6 +3,7 @@ defmodule BlockScoutWeb.TransactionInternalTransactionController do
import BlockScoutWeb.Account.AuthController, only: [current_user: 1]
import BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1]
import GetTransactionTags, only: [get_transaction_tags: 2]
alias BlockScoutWeb.{AccessHelpers, Controller, InternalTransactionView, TransactionController}
alias Explorer.Accounts.TagTransaction
@ -106,7 +107,11 @@ defmodule BlockScoutWeb.TransactionInternalTransactionController do
block_height: Chain.block_height(),
show_token_transfers: Chain.transaction_has_token_transfers?(transaction_hash),
transaction: transaction,
personal_tx_tag: get_tag(conn, transaction_hash)
personal_tx_tag:
get_transaction_tags(
transaction_hash,
current_user(conn)
)
)
else
{:restricted_access, _} ->
@ -119,10 +124,4 @@ defmodule BlockScoutWeb.TransactionInternalTransactionController do
TransactionController.set_not_found_view(conn, transaction_hash_string)
end
end
defp get_tag(conn, transaction_hash) do
if user = current_user(conn) do
Repo.get_by(TagTransaction, tx_hash: transaction_hash, identity_id: user.id)
end
end
end

@ -1,7 +1,9 @@
defmodule BlockScoutWeb.TransactionLogController do
use BlockScoutWeb, :controller
import BlockScoutWeb.Account.AuthController, only: [current_user: 1]
import BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1]
import GetTransactionTags, only: [get_transaction_tags: 2]
alias BlockScoutWeb.{AccessHelpers, Controller, TransactionController, TransactionLogView}
alias Explorer.{Chain, Market}
@ -96,7 +98,12 @@ defmodule BlockScoutWeb.TransactionLogController do
show_token_transfers: Chain.transaction_has_token_transfers?(transaction_hash),
current_path: Controller.current_full_path(conn),
transaction: transaction,
exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null()
exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(),
personal_tx_tag:
get_transaction_tags(
transaction_hash,
current_user(conn)
)
)
else
{:restricted_access, _} ->

@ -1,6 +1,9 @@
defmodule BlockScoutWeb.TransactionRawTraceController do
use BlockScoutWeb, :controller
import BlockScoutWeb.Account.AuthController, only: [current_user: 1]
import GetTransactionTags, only: [get_transaction_tags: 2]
alias BlockScoutWeb.{AccessHelpers, TransactionController}
alias EthereumJSONRPC
alias Explorer.{Chain, Market}
@ -93,7 +96,12 @@ defmodule BlockScoutWeb.TransactionRawTraceController do
internal_transactions: internal_transactions,
block_height: Chain.block_height(),
show_token_transfers: Chain.transaction_has_token_transfers?(hash),
transaction: transaction
transaction: transaction,
personal_tx_tag:
get_transaction_tags(
transaction.hash,
current_user(conn)
)
)
end
end

@ -3,6 +3,7 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do
import BlockScoutWeb.Account.AuthController, only: [current_user: 1]
import BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1]
import GetTransactionTags, only: [get_transaction_tags: 2]
alias BlockScoutWeb.{AccessHelpers, Controller, TransactionController, TransactionTokenTransferView}
alias Explorer.Accounts.TagTransaction
@ -110,7 +111,11 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do
current_path: Controller.current_full_path(conn),
show_token_transfers: true,
transaction: transaction,
personal_tx_tag: get_tag(conn, transaction_hash)
personal_tx_tag:
get_transaction_tags(
transaction_hash,
current_user(conn)
)
)
else
:not_found ->
@ -126,10 +131,4 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do
TransactionController.set_not_found_view(conn, transaction_hash_string)
end
end
defp get_tag(conn, transaction_hash) do
if user = current_user(conn) do
Repo.get_by(TagTransaction, tx_hash: transaction_hash, identity_id: user.id)
end
end
end

@ -0,0 +1,17 @@
defmodule GetTransactionTags do
@moduledoc """
Get various types of tags associated with the transaction
"""
# import Ecto.Query, only: [from: 2]
alias Explorer.Accounts.TagTransaction
alias Explorer.Chain.Hash
alias Explorer.Repo
def get_transaction_tags(transaction_hash, %{id: identity_id}) do
Repo.get_by(TagTransaction, tx_hash: transaction_hash, identity_id: identity_id)
end
def get_transaction_tags(_, _), do: nil
end

@ -1,4 +1,8 @@
defmodule Explorer.Accounts.Notify do
@moduledoc """
Interface for notifier, for import and call from other modules
"""
alias Explorer.Accounts.Notifier.Notify
require Logger
@ -8,7 +12,6 @@ defmodule Explorer.Accounts.Notify do
end
defp process(transactions) do
try do
Notify.call(transactions)
rescue
err ->
@ -16,4 +19,3 @@ defmodule Explorer.Accounts.Notify do
Logger.info(err, fetcher: :account)
end
end
end

Loading…
Cancel
Save