diff --git a/apps/block_scout_web/lib/block_scout_web/views/api/v2/smart_contract_view.ex b/apps/block_scout_web/lib/block_scout_web/views/api/v2/smart_contract_view.ex index f62dffc969..08fa9377b0 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/api/v2/smart_contract_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/api/v2/smart_contract_view.ex @@ -257,7 +257,13 @@ defmodule BlockScoutWeb.API.V2.SmartContractView do token = smart_contract.address.token %{ - "address" => Helper.address_with_info(nil, smart_contract.address, smart_contract.address.hash, false), + "address" => + Helper.address_with_info( + nil, + %Address{smart_contract.address | smart_contract: smart_contract}, + smart_contract.address.hash, + false + ), "compiler_version" => smart_contract.compiler_version, "optimization_enabled" => smart_contract.optimization, "tx_count" => smart_contract.address.transactions_count, diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/v2/address_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/v2/address_controller_test.exs index 06013076b2..962be40caf 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/v2/address_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/v2/address_controller_test.exs @@ -1668,6 +1668,17 @@ defmodule BlockScoutWeb.API.V2.AddressControllerTest do compare_item(address, address_json) end + + test "check smart contract preload", %{conn: conn} do + smart_contract = insert(:smart_contract, address_hash: insert(:contract_address, fetched_coin_balance: 1).hash) + + request = get(conn, "/api/v2/addresses") + assert %{"items" => [address]} = json_response(request, 200) + + assert String.downcase(address["hash"]) == to_string(smart_contract.address_hash) + assert address["is_contract"] == true + assert address["is_verified"] == true + end end describe "/addresses/{address_hash}/tabs-counters" do diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/v2/smart_contract_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/v2/smart_contract_controller_test.exs index e93544ea64..9c3a1f6325 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/v2/smart_contract_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/v2/smart_contract_controller_test.exs @@ -2375,6 +2375,8 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do assert %{"items" => [sc], "next_page_params" => nil} = json_response(request, 200) compare_item(smart_contract, sc) + assert sc["address"]["is_verified"] == true + assert sc["address"]["is_contract"] == true end test "check pagination", %{conn: conn} do diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 9e013ec9a7..4bdef66924 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -2062,7 +2062,7 @@ defmodule Explorer.Chain do from(a in Address, where: a.fetched_coin_balance > ^0, order_by: [desc: a.fetched_coin_balance, asc: a.hash], - preload: [:names], + preload: [:names, :smart_contract], select: {a, fragment("coalesce(1 + ?, 0)", a.nonce)} )