From f89bb918f412aedb3d5b54c1183b1b37bb5da759 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 9 Jul 2019 14:03:46 +0300 Subject: [PATCH] add external libaries embeds --- apps/explorer/lib/explorer/chain/smart_contract.ex | 6 +++--- .../chain/smart_contract/external_library.ex | 8 ++++++++ .../lib/explorer/smart_contract/publisher.ex | 4 ++-- ...04_add_external_libraries_to_smart_contracts.exs | 13 +++++++++++++ 4 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 apps/explorer/lib/explorer/chain/smart_contract/external_library.ex create mode 100644 apps/explorer/priv/repo/migrations/20190709103104_add_external_libraries_to_smart_contracts.exs diff --git a/apps/explorer/lib/explorer/chain/smart_contract.ex b/apps/explorer/lib/explorer/chain/smart_contract.ex index 9dee6b147e..9911dc1143 100644 --- a/apps/explorer/lib/explorer/chain/smart_contract.ex +++ b/apps/explorer/lib/explorer/chain/smart_contract.ex @@ -13,6 +13,7 @@ defmodule Explorer.Chain.SmartContract do use Explorer.Schema alias Explorer.Chain.{Address, ContractMethod, DecompiledSmartContract, Hash} + alias Explorer.Chain.SmartContract.ExternalLibrary alias Explorer.Repo @typedoc """ @@ -212,7 +213,7 @@ defmodule Explorer.Chain.SmartContract do field(:constructor_arguments, :string) field(:evm_version, :string) field(:optimization_runs, :integer) - field(:external_libraries, :map) + embeds_many :external_libraries, ExternalLibrary field(:abi, {:array, :map}) has_many( @@ -247,8 +248,7 @@ defmodule Explorer.Chain.SmartContract do :abi, :constructor_arguments, :evm_version, - :optimization_runs, - :external_libraries + :optimization_runs ]) |> validate_required([:name, :compiler_version, :optimization, :contract_source_code, :abi, :address_hash]) |> unique_constraint(:address_hash) diff --git a/apps/explorer/lib/explorer/chain/smart_contract/external_library.ex b/apps/explorer/lib/explorer/chain/smart_contract/external_library.ex new file mode 100644 index 0000000000..807df7bd94 --- /dev/null +++ b/apps/explorer/lib/explorer/chain/smart_contract/external_library.ex @@ -0,0 +1,8 @@ +defmodule Explorer.Chain.SmartContract.ExternalLibrary do + use Ecto.Schema + + embedded_schema do + field :name + field :address_hash + end +end diff --git a/apps/explorer/lib/explorer/smart_contract/publisher.ex b/apps/explorer/lib/explorer/smart_contract/publisher.ex index 702b45976d..42ce646fb1 100644 --- a/apps/explorer/lib/explorer/smart_contract/publisher.ex +++ b/apps/explorer/lib/explorer/smart_contract/publisher.ex @@ -28,10 +28,10 @@ defmodule Explorer.SmartContract.Publisher do case Verifier.evaluate_authenticity(address_hash, params_with_external_libaries) do {:ok, %{abi: abi}} -> - publish_smart_contract(address_hash, params, abi) + publish_smart_contract(address_hash, params_with_external_libaries, abi) {:error, error} -> - {:error, unverified_smart_contract(address_hash, params, error)} + {:error, unverified_smart_contract(address_hash, params_with_external_libaries, error)} end end diff --git a/apps/explorer/priv/repo/migrations/20190709103104_add_external_libraries_to_smart_contracts.exs b/apps/explorer/priv/repo/migrations/20190709103104_add_external_libraries_to_smart_contracts.exs new file mode 100644 index 0000000000..b122dfdd54 --- /dev/null +++ b/apps/explorer/priv/repo/migrations/20190709103104_add_external_libraries_to_smart_contracts.exs @@ -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