Add verification link to unverified smart contracts and check to verified ones

pull/182/head
Amanda Sposito 7 years ago
parent 3ba22fdb83
commit a9f3e2b0d1
  1. 16
      apps/explorer/lib/explorer/chain.ex
  2. 2
      apps/explorer/lib/explorer/chain/address.ex
  3. 2
      apps/explorer/test/explorer/chain_test.exs
  4. 2
      apps/explorer_web/lib/explorer_web/controllers/address_contract_verification_controller.ex
  5. 11
      apps/explorer_web/lib/explorer_web/templates/address_contract/index.html.eex
  6. 5
      apps/explorer_web/lib/explorer_web/views/address_contract_view.ex
  7. 12
      apps/explorer_web/priv/gettext/default.pot
  8. 12
      apps/explorer_web/priv/gettext/en/LC_MESSAGES/default.po
  9. 2
      apps/explorer_web/test/explorer_web/controllers/address_contract_controller_test.exs

@ -18,8 +18,7 @@ defmodule Explorer.Chain do
Log, Log,
Transaction, Transaction,
Wei, Wei,
SmartContract, SmartContract
Data
} }
alias Explorer.Chain.Block.Reward alias Explorer.Chain.Block.Reward
@ -504,14 +503,15 @@ defmodule Explorer.Chain do
end end
def find_contract_address(%Hash{byte_count: unquote(Hash.Truncated.byte_count())} = hash) do def find_contract_address(%Hash{byte_count: unquote(Hash.Truncated.byte_count())} = hash) do
address = query =
Repo.one( from(
from( address in Address,
address in Address, preload: [:smart_contract],
where: address.hash == ^hash and not is_nil(address.contract_code) where: address.hash == ^hash and not is_nil(address.contract_code)
)
) )
address = Repo.one(query)
if address do if address do
{:ok, address} {:ok, address}
else else

@ -39,7 +39,7 @@ defmodule Explorer.Chain.Address do
field(:balance_fetched_at, :utc_datetime) field(:balance_fetched_at, :utc_datetime)
field(:contract_code, Data) field(:contract_code, Data)
has_one :smart_contract, SmartContract has_one(:smart_contract, SmartContract)
timestamps() timestamps()
end end

@ -822,7 +822,7 @@ defmodule Explorer.ChainTest do
end end
test "finds an contract address" do test "finds an contract address" do
address = insert(:address, contract_code: Factory.data("contract_code")) address = insert(:address, contract_code: Factory.data("contract_code"), smart_contract: nil)
response = Chain.find_contract_address(address.hash) response = Chain.find_contract_address(address.hash)

@ -23,7 +23,7 @@ defmodule ExplorerWeb.AddressContractVerificationController do
}) do }) do
case Publisher.publish(address_hash_string, smart_contract) do case Publisher.publish(address_hash_string, smart_contract) do
{:ok, _smart_contract} -> {:ok, _smart_contract} ->
redirect(conn, to: address_transaction_path(conn, :index, locale, address_hash_string)) redirect(conn, to: address_contract_path(conn, :index, locale, address_hash_string))
{:error, changeset} -> {:error, changeset} ->
{:ok, compiler_versions} = CompilerVersion.fetch_versions() {:ok, compiler_versions} = CompilerVersion.fetch_versions()

@ -37,6 +37,17 @@
<div class="card-body"> <div class="card-body">
<h2 class="card-title"><%= gettext "Contract bytecode" %></h2> <h2 class="card-title"><%= gettext "Contract bytecode" %></h2>
<%= if !smart_contract_verified?(@address) do %>
<p>
<%= link(
to: address_verify_contract_path(@conn, :new, @conn.assigns.locale, @conn.params["address_id"])
) do %>
<i class="fas fa-info-circle"></i>
<%= gettext("Verify and Publish") %>
<% end %>
</p>
<% end %>
<pre class="pre-wrap p-2 bg-light mb-0"> <pre class="pre-wrap p-2 bg-light mb-0">
<code><%= @address.contract_code %></code> <code><%= @address.contract_code %></code>
</pre> </pre>

@ -1,3 +1,8 @@
defmodule ExplorerWeb.AddressContractView do defmodule ExplorerWeb.AddressContractView do
use ExplorerWeb, :view use ExplorerWeb, :view
alias Explorer.Chain.{Address, SmartContract}
def smart_contract_verified?(%Address{smart_contract: nil}), do: false
def smart_contract_verified?(%Address{smart_contract: %SmartContract{}}), do: true
end end

@ -490,7 +490,6 @@ msgstr ""
msgid "TX Fee" msgid "TX Fee"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address_contract/index.html.eex:25
#: lib/explorer_web/templates/address_internal_transaction/index.html.eex:27 #: lib/explorer_web/templates/address_internal_transaction/index.html.eex:27
#: lib/explorer_web/templates/address_transaction/index.html.eex:27 #: lib/explorer_web/templates/address_transaction/index.html.eex:27
msgid "Contract" msgid "Contract"
@ -500,7 +499,7 @@ msgstr ""
msgid "Contract Address" msgid "Contract Address"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address_contract/index.html.eex:34 #: lib/explorer_web/templates/address_contract/index.html.eex:38
msgid "Contract bytecode" msgid "Contract bytecode"
msgstr "" msgstr ""
@ -513,5 +512,14 @@ msgid "Older"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address_verify_contract/new.html.eex:9 #: lib/explorer_web/templates/address_verify_contract/new.html.eex:9
#: lib/explorer_web/templates/address_contract_verification/new.html.eex:9
msgid "Contract Source Code" msgid "Contract Source Code"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address_contract/index.html.eex:46
msgid "Verify and Publish"
msgstr ""
#: lib/explorer_web/templates/address_contract/index.html.eex:27
msgid "Code"
msgstr ""

@ -502,7 +502,6 @@ msgstr ""
msgid "TX Fee" msgid "TX Fee"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address_contract/index.html.eex:25
#: lib/explorer_web/templates/address_internal_transaction/index.html.eex:27 #: lib/explorer_web/templates/address_internal_transaction/index.html.eex:27
#: lib/explorer_web/templates/address_transaction/index.html.eex:27 #: lib/explorer_web/templates/address_transaction/index.html.eex:27
msgid "Contract" msgid "Contract"
@ -512,7 +511,7 @@ msgstr ""
msgid "Contract Address" msgid "Contract Address"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address_contract/index.html.eex:34 #: lib/explorer_web/templates/address_contract/index.html.eex:38
msgid "Contract bytecode" msgid "Contract bytecode"
msgstr "" msgstr ""
@ -525,5 +524,14 @@ msgid "Older"
msgstr "" msgstr ""
#: lib/explorer_web/templates/address_verify_contract/new.html.eex:9 #: lib/explorer_web/templates/address_verify_contract/new.html.eex:9
#: lib/explorer_web/templates/address_contract_verification/new.html.eex:9
msgid "Contract Source Code" msgid "Contract Source Code"
msgstr "Contract Source Code" msgstr "Contract Source Code"
#: lib/explorer_web/templates/address_contract/index.html.eex:46
msgid "Verify and Publish"
msgstr ""
#: lib/explorer_web/templates/address_contract/index.html.eex:27
msgid "Code"
msgstr ""

@ -33,7 +33,7 @@ defmodule ExplorerWeb.AddressContractControllerTest do
end end
test "suscefully renders the page", %{conn: conn} do test "suscefully renders the page", %{conn: conn} do
address = insert(:address, contract_code: Factory.data("contract_code")) address = insert(:address, contract_code: Factory.data("contract_code"), smart_contract: nil)
conn = get(conn, address_contract_path(ExplorerWeb.Endpoint, :index, :en, address)) conn = get(conn, address_contract_path(ExplorerWeb.Endpoint, :index, :en, address))

Loading…
Cancel
Save