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

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

@ -822,7 +822,7 @@ defmodule Explorer.ChainTest do
end
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)

@ -23,7 +23,7 @@ defmodule ExplorerWeb.AddressContractVerificationController do
}) do
case Publisher.publish(address_hash_string, smart_contract) do
{: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} ->
{:ok, compiler_versions} = CompilerVersion.fetch_versions()

@ -37,6 +37,17 @@
<div class="card-body">
<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">
<code><%= @address.contract_code %></code>
</pre>

@ -1,3 +1,8 @@
defmodule ExplorerWeb.AddressContractView do
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

@ -490,7 +490,6 @@ msgstr ""
msgid "TX Fee"
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_transaction/index.html.eex:27
msgid "Contract"
@ -500,7 +499,7 @@ msgstr ""
msgid "Contract Address"
msgstr ""
#: lib/explorer_web/templates/address_contract/index.html.eex:34
#: lib/explorer_web/templates/address_contract/index.html.eex:38
msgid "Contract bytecode"
msgstr ""
@ -513,5 +512,14 @@ msgid "Older"
msgstr ""
#: 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"
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"
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_transaction/index.html.eex:27
msgid "Contract"
@ -512,7 +511,7 @@ msgstr ""
msgid "Contract Address"
msgstr ""
#: lib/explorer_web/templates/address_contract/index.html.eex:34
#: lib/explorer_web/templates/address_contract/index.html.eex:38
msgid "Contract bytecode"
msgstr ""
@ -525,5 +524,14 @@ msgid "Older"
msgstr ""
#: 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"
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
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))

Loading…
Cancel
Save