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. 16
      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.Account.AuthController, only: [current_user: 1]
import BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 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 BlockScoutWeb.{AccessHelpers, Controller, InternalTransactionView, TransactionController}
alias Explorer.Accounts.TagTransaction alias Explorer.Accounts.TagTransaction
@ -106,7 +107,11 @@ defmodule BlockScoutWeb.TransactionInternalTransactionController do
block_height: Chain.block_height(), block_height: Chain.block_height(),
show_token_transfers: Chain.transaction_has_token_transfers?(transaction_hash), show_token_transfers: Chain.transaction_has_token_transfers?(transaction_hash),
transaction: transaction, transaction: transaction,
personal_tx_tag: get_tag(conn, transaction_hash) personal_tx_tag:
get_transaction_tags(
transaction_hash,
current_user(conn)
)
) )
else else
{:restricted_access, _} -> {:restricted_access, _} ->
@ -119,10 +124,4 @@ defmodule BlockScoutWeb.TransactionInternalTransactionController do
TransactionController.set_not_found_view(conn, transaction_hash_string) TransactionController.set_not_found_view(conn, transaction_hash_string)
end end
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 end

@ -1,7 +1,9 @@
defmodule BlockScoutWeb.TransactionLogController do defmodule BlockScoutWeb.TransactionLogController do
use BlockScoutWeb, :controller 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 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 BlockScoutWeb.{AccessHelpers, Controller, TransactionController, TransactionLogView}
alias Explorer.{Chain, Market} alias Explorer.{Chain, Market}
@ -96,7 +98,12 @@ defmodule BlockScoutWeb.TransactionLogController do
show_token_transfers: Chain.transaction_has_token_transfers?(transaction_hash), show_token_transfers: Chain.transaction_has_token_transfers?(transaction_hash),
current_path: Controller.current_full_path(conn), current_path: Controller.current_full_path(conn),
transaction: transaction, 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 else
{:restricted_access, _} -> {:restricted_access, _} ->

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

@ -3,6 +3,7 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do
import BlockScoutWeb.Account.AuthController, only: [current_user: 1] 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 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 BlockScoutWeb.{AccessHelpers, Controller, TransactionController, TransactionTokenTransferView}
alias Explorer.Accounts.TagTransaction alias Explorer.Accounts.TagTransaction
@ -110,7 +111,11 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do
current_path: Controller.current_full_path(conn), current_path: Controller.current_full_path(conn),
show_token_transfers: true, show_token_transfers: true,
transaction: transaction, transaction: transaction,
personal_tx_tag: get_tag(conn, transaction_hash) personal_tx_tag:
get_transaction_tags(
transaction_hash,
current_user(conn)
)
) )
else else
:not_found -> :not_found ->
@ -126,10 +131,4 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do
TransactionController.set_not_found_view(conn, transaction_hash_string) TransactionController.set_not_found_view(conn, transaction_hash_string)
end end
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 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 defmodule Explorer.Accounts.Notify do
@moduledoc """
Interface for notifier, for import and call from other modules
"""
alias Explorer.Accounts.Notifier.Notify alias Explorer.Accounts.Notifier.Notify
require Logger require Logger
@ -8,12 +12,10 @@ defmodule Explorer.Accounts.Notify do
end end
defp process(transactions) do defp process(transactions) do
try do Notify.call(transactions)
Notify.call(transactions) rescue
rescue err ->
err -> Logger.info("--- Notifier error", fetcher: :account)
Logger.info("--- Notifier error", fetcher: :account) Logger.info(err, fetcher: :account)
Logger.info(err, fetcher: :account)
end
end end
end end

Loading…
Cancel
Save