pull/6642/head
Никита Поздняков 2 years ago
parent 0d8b713b47
commit 842fa08f48
No known key found for this signature in database
GPG Key ID: F344106F9804FE5F
  1. 14
      apps/block_scout_web/assets/js/lib/smart_contract/functions.js
  2. 3
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/address_controller.ex
  3. 5
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/smart_contract_controller.ex
  4. 2
      apps/block_scout_web/lib/block_scout_web/views/api/v2/smart_contract_view.ex
  5. 43
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/address_controller_test.exs
  6. 10
      apps/explorer/lib/explorer/chain.ex

@ -13,7 +13,7 @@ const loadFunctions = (element, isCustomABI, from) => {
$.get(
url,
{ hash, type, action, is_custom_abi: isCustomABI, from: from },
{ hash, type, action, is_custom_abi: isCustomABI, from },
response => $element.html(response)
)
.done(function () {
@ -97,14 +97,18 @@ const container = $('[data-smart-contract-functions]')
if (container.length) {
getCurrentAccountPromise(window.web3 && window.web3.currentProvider).then((currentAccount) => {
loadFunctions(container, false, currentAccount)}, () => {loadFunctions(container, false, null)
})
loadFunctions(container, false, currentAccount)
}, () => {
loadFunctions(container, false, null)
})
}
const customABIContainer = $('[data-smart-contract-functions-custom]')
if (customABIContainer.length) {
getCurrentAccountPromise(window.web3 && window.web3.currentProvider).then((currentAccount) => {
loadFunctions(container, false, currentAccount)}, () => {loadFunctions(container, true, null)
})
loadFunctions(container, false, currentAccount)
}, () => {
loadFunctions(container, true, null)
})
}

@ -243,8 +243,7 @@ defmodule BlockScoutWeb.API.V2.AddressController do
def coin_balance_history(conn, %{"address_hash" => address_hash_string} = params) do
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)},
{:ok, false} <- AccessHelpers.restricted_access?(address_hash_string, params),
{:not_found, {:ok, _address}, _} <-
{:not_found, Chain.hash_to_address(address_hash), :empty_items_with_next_page_params} do
{:not_found, {:ok, _address}} <- {:not_found, Chain.hash_to_address(address_hash)} do
full_options = paging_options(params)
results_plus_one = Chain.address_to_coin_balances(address_hash, full_options)

@ -3,12 +3,11 @@ defmodule BlockScoutWeb.API.V2.SmartContractController do
import Explorer.SmartContract.Solidity.Verifier, only: [parse_boolean: 1]
alias BlockScoutWeb.AccessHelpers
alias BlockScoutWeb.{AccessHelpers, AddressView}
alias BlockScoutWeb.AddressContractVerificationController, as: VerificationController
alias BlockScoutWeb.AddressView
alias Explorer.SmartContract.{Reader, Writer}
alias Explorer.Chain
alias Explorer.Chain.SmartContract
alias Explorer.SmartContract.{Reader, Writer}
@smart_contract_address_options [
necessity_by_association: %{

@ -2,12 +2,12 @@ defmodule BlockScoutWeb.API.V2.SmartContractView do
use BlockScoutWeb, :view
alias ABI.FunctionSelector
alias Explorer.Visualize.Sol2uml
alias BlockScoutWeb.API.V2.TransactionView
alias BlockScoutWeb.SmartContractView
alias BlockScoutWeb.{ABIEncodedValueView, AddressContractView, AddressView}
alias Explorer.Chain
alias Explorer.Chain.Address
alias Explorer.Visualize.Sol2uml
def render("smart_contract.json", %{address: address}) do
prepare_smart_contract(address)

@ -50,7 +50,18 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do
"exchange_rate" => nil,
"implementation_name" => nil,
"implementation_address" => nil,
"block_number_balance_updated_at" => nil
"block_number_balance_updated_at" => nil,
"has_custom_methods_read" => false,
"has_custom_methods_write" => false,
"has_methods_read" => false,
"has_methods_write" => false,
"has_methods_read_proxy" => false,
"has_methods_write_proxy" => false,
"has_decompiled_code" => false,
"has_validated_blocks" => false,
"has_logs" => false,
"has_tokens" => false,
"has_token_transfers" => false
}
request = get(conn, "/api/v2/addresses/#{Address.checksum(address.hash)}")
@ -135,9 +146,7 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do
request = get(conn, "/api/v2/addresses/#{address.hash}/transactions")
assert response = json_response(request, 200)
assert response["items"] == []
assert response["next_page_params"] == nil
assert %{"message" => "Not found"} = json_response(request, 404)
end
test "get 422 on invalid address", %{conn: conn} do
@ -336,9 +345,7 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do
request = get(conn, "/api/v2/addresses/#{address.hash}/token-transfers")
assert response = json_response(request, 200)
assert response["items"] == []
assert response["next_page_params"] == nil
assert %{"message" => "Not found"} = json_response(request, 404)
end
test "get 422 on invalid address", %{conn: conn} do
@ -717,9 +724,7 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do
request = get(conn, "/api/v2/addresses/#{address.hash}/internal-transactions")
assert response = json_response(request, 200)
assert response["items"] == []
assert response["next_page_params"] == nil
assert %{"message" => "Not found"} = json_response(request, 404)
end
test "get 422 on invalid address", %{conn: conn} do
@ -864,9 +869,7 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do
request = get(conn, "/api/v2/addresses/#{address.hash}/blocks-validated")
assert response = json_response(request, 200)
assert response["items"] == []
assert response["next_page_params"] == nil
assert %{"message" => "Not found"} = json_response(request, 404)
end
test "get 422 on invalid address", %{conn: conn} do
@ -910,8 +913,7 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do
request = get(conn, "/api/v2/addresses/#{address.hash}/token-balances")
assert response = json_response(request, 200)
assert response == []
assert %{"message" => "Not found"} = json_response(request, 404)
end
test "get 422 on invalid address", %{conn: conn} do
@ -945,9 +947,7 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do
request = get(conn, "/api/v2/addresses/#{address.hash}/coin-balance-history")
assert response = json_response(request, 200)
assert response["items"] == []
assert response["next_page_params"] == nil
assert %{"message" => "Not found"} = json_response(request, 404)
end
test "get 422 on invalid address", %{conn: conn} do
@ -994,8 +994,7 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do
request = get(conn, "/api/v2/addresses/#{address.hash}/coin-balance-history-by-day")
assert response = json_response(request, 200)
assert response == []
assert %{"message" => "Not found"} = json_response(request, 404)
end
test "get 422 on invalid address", %{conn: conn} do
@ -1032,9 +1031,7 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do
request = get(conn, "/api/v2/addresses/#{address.hash}/logs")
assert response = json_response(request, 200)
assert response["items"] == []
assert response["next_page_params"] == nil
assert %{"message" => "Not found"} = json_response(request, 404)
end
test "get 422 on invalid address", %{conn: conn} do

@ -1895,11 +1895,7 @@ defmodule Explorer.Chain do
case address_result do
%{smart_contract: smart_contract} ->
if smart_contract do
if match?(%NotLoaded{}, smart_contract) do
address_result
else
check_bytecode_matching(address_result)
end
check_bytecode_matching(address_result, smart_contract)
else
address_verified_twin_contract =
Chain.get_minimal_proxy_template(hash) ||
@ -1932,7 +1928,9 @@ defmodule Explorer.Chain do
end
end
defp check_bytecode_matching(address) do
defp check_bytecode_matching(address, %NotLoaded{}), do: address
defp check_bytecode_matching(address, _) do
now = DateTime.utc_now()
json_rpc_named_arguments = Application.get_env(:explorer, :json_rpc_named_arguments)

Loading…
Cancel
Save