add external libaries embeds

pull/2264/head
Ayrat Badykov 5 years ago
parent 575afa806d
commit f89bb918f4
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 6
      apps/explorer/lib/explorer/chain/smart_contract.ex
  2. 8
      apps/explorer/lib/explorer/chain/smart_contract/external_library.ex
  3. 4
      apps/explorer/lib/explorer/smart_contract/publisher.ex
  4. 13
      apps/explorer/priv/repo/migrations/20190709103104_add_external_libraries_to_smart_contracts.exs

@ -13,6 +13,7 @@ defmodule Explorer.Chain.SmartContract do
use Explorer.Schema use Explorer.Schema
alias Explorer.Chain.{Address, ContractMethod, DecompiledSmartContract, Hash} alias Explorer.Chain.{Address, ContractMethod, DecompiledSmartContract, Hash}
alias Explorer.Chain.SmartContract.ExternalLibrary
alias Explorer.Repo alias Explorer.Repo
@typedoc """ @typedoc """
@ -212,7 +213,7 @@ defmodule Explorer.Chain.SmartContract do
field(:constructor_arguments, :string) field(:constructor_arguments, :string)
field(:evm_version, :string) field(:evm_version, :string)
field(:optimization_runs, :integer) field(:optimization_runs, :integer)
field(:external_libraries, :map) embeds_many :external_libraries, ExternalLibrary
field(:abi, {:array, :map}) field(:abi, {:array, :map})
has_many( has_many(
@ -247,8 +248,7 @@ defmodule Explorer.Chain.SmartContract do
:abi, :abi,
:constructor_arguments, :constructor_arguments,
:evm_version, :evm_version,
:optimization_runs, :optimization_runs
:external_libraries
]) ])
|> validate_required([:name, :compiler_version, :optimization, :contract_source_code, :abi, :address_hash]) |> validate_required([:name, :compiler_version, :optimization, :contract_source_code, :abi, :address_hash])
|> unique_constraint(:address_hash) |> unique_constraint(:address_hash)

@ -0,0 +1,8 @@
defmodule Explorer.Chain.SmartContract.ExternalLibrary do
use Ecto.Schema
embedded_schema do
field :name
field :address_hash
end
end

@ -28,10 +28,10 @@ defmodule Explorer.SmartContract.Publisher do
case Verifier.evaluate_authenticity(address_hash, params_with_external_libaries) do case Verifier.evaluate_authenticity(address_hash, params_with_external_libaries) do
{:ok, %{abi: abi}} -> {:ok, %{abi: abi}} ->
publish_smart_contract(address_hash, params, abi) publish_smart_contract(address_hash, params_with_external_libaries, abi)
{:error, error} -> {:error, error} ->
{:error, unverified_smart_contract(address_hash, params, error)} {:error, unverified_smart_contract(address_hash, params_with_external_libaries, error)}
end end
end end

@ -0,0 +1,13 @@
defmodule Explorer.Repo.Migrations.AddExternalLibrariesToSmartContracts do
use Ecto.Migration
def change do
alter table(:smart_contracts) do
remove :external_libraries
end
alter table(:smart_contracts) do
add :external_libraries, {:array, :map}, default: []
end
end
end
Loading…
Cancel
Save