Merge branch 'master' into ab-smart-contract-constructor-arguments-

pull/1414/head
Ayrat Badykov 6 years ago committed by GitHub
commit 2da0eb48ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      apps/block_scout_web/config/dev.exs
  2. 19
      apps/explorer/lib/explorer/smart_contract/solidity/code_compiler.ex
  3. 4
      apps/explorer/priv/compile_solc.js
  4. 12
      apps/explorer/priv/repo/migrations/20190208113202_add_unique_index_to_rewards.exs
  5. 7
      apps/explorer/priv/repo/migrations/20190208143201_add_index_on_address_hash_block_number_and_token_contract_address_hash_for_current_token_balance.exs
  6. 20
      apps/indexer/lib/indexer/block/reward/fetcher.ex

@ -11,8 +11,8 @@ config :block_scout_web, BlockScoutWeb.Endpoint,
https: [ https: [
port: 4001, port: 4001,
cipher_suite: :strong, cipher_suite: :strong,
certfile: "priv/cert/selfsigned.pem", certfile: System.get_env("CERTFILE") || "priv/cert/selfsigned.pem",
keyfile: "priv/cert/selfsigned_key.pem" keyfile: System.get_env("KEYFILE") || "priv/cert/selfsigned_key.pem"
], ],
debug_errors: true, debug_errors: true,
code_reloader: true, code_reloader: true,

@ -61,6 +61,8 @@ defmodule Explorer.SmartContract.Solidity.CodeCompiler do
} }
""" """
def run(name, compiler_version, code, optimize, external_libs \\ %{}) do def run(name, compiler_version, code, optimize, external_libs \\ %{}) do
external_libs_string = Jason.encode!(external_libs)
{response, _status} = {response, _status} =
System.cmd( System.cmd(
"node", "node",
@ -69,16 +71,15 @@ defmodule Explorer.SmartContract.Solidity.CodeCompiler do
code, code,
compiler_version, compiler_version,
optimize_value(optimize), optimize_value(optimize),
@new_contract_name @new_contract_name,
external_libs_string
] ]
) )
with {:ok, contracts} <- Jason.decode(response), with {:ok, contracts} <- Jason.decode(response),
%{"abi" => abi, "evm" => %{"deployedBytecode" => %{"object" => bytecode}}} <- %{"abi" => abi, "evm" => %{"deployedBytecode" => %{"object" => bytecode}}} <-
get_contract_info(contracts, name) do get_contract_info(contracts, name) do
bytecode_with_libraries = add_library_addresses(bytecode, external_libs) {:ok, %{"abi" => abi, "bytecode" => bytecode, "name" => name}}
{:ok, %{"abi" => abi, "bytecode" => bytecode_with_libraries, "name" => name}}
else else
{:error, %Jason.DecodeError{}} -> {:error, %Jason.DecodeError{}} ->
{:error, :compilation} {:error, :compilation}
@ -105,16 +106,6 @@ defmodule Explorer.SmartContract.Solidity.CodeCompiler do
end end
end end
defp add_library_addresses(bytecode, external_libs) do
Enum.reduce(external_libs, bytecode, fn {library_name, address}, acc ->
placeholder = String.replace(@new_contract_name, ".", "\.") <> ":" <> library_name
regex = Regex.compile!("_+#{placeholder}_+")
address = String.replace(address, "0x", "")
String.replace(acc, regex, address)
end)
end
def parse_error(%{"error" => error}), do: {:error, [error]} def parse_error(%{"error" => error}), do: {:error, [error]}
def parse_error(%{"errors" => errors}), do: {:error, errors} def parse_error(%{"errors" => errors}), do: {:error, errors}
def parse_error({:error, _} = error), do: error def parse_error({:error, _} = error), do: error

@ -6,6 +6,7 @@ var sourceCode = process.argv[2];
var version = process.argv[3]; var version = process.argv[3];
var optimize = process.argv[4]; var optimize = process.argv[4];
var newContractName = process.argv[5]; var newContractName = process.argv[5];
var externalLibraries = JSON.parse(process.argv[6])
var compiled_code = solc.loadRemoteVersion(version, function (err, solcSnapshot) { var compiled_code = solc.loadRemoteVersion(version, function (err, solcSnapshot) {
if (err) { if (err) {
@ -24,6 +25,9 @@ var compiled_code = solc.loadRemoteVersion(version, function (err, solcSnapshot)
enabled: optimize == '1', enabled: optimize == '1',
runs: 200 runs: 200
}, },
libraries: {
[newContractName]: externalLibraries
},
outputSelection: { outputSelection: {
'*': { '*': {
'*': ['*'] '*': ['*']

@ -0,0 +1,12 @@
defmodule Explorer.Repo.Migrations.AddUniqueIndexToRewards do
use Ecto.Migration
def change do
create(
unique_index(
:block_rewards,
[:address_hash, :block_hash, :address_type]
)
)
end
end

@ -0,0 +1,7 @@
defmodule Explorer.Repo.Migrations.AddIndexOnAddressHashBlockNumberAndTokenContractAddressHashForCurrentTokenBalance do
use Ecto.Migration
def change do
create(index(:address_current_token_balances, [:address_hash, :block_number, :token_contract_address_hash]))
end
end

@ -177,14 +177,18 @@ defmodule Indexer.Block.Reward.Fetcher do
|> Enum.map(& &1.block_hash) |> Enum.map(& &1.block_hash)
|> Chain.gas_payment_by_block_hash() |> Chain.gas_payment_by_block_hash()
Enum.map(beneficiaries_params, fn %{block_hash: block_hash} = beneficiary -> Enum.map(beneficiaries_params, fn %{block_hash: block_hash, address_type: address_type} = beneficiary ->
case gas_payment_by_block_hash do if address_type == :validator do
%{^block_hash => gas_payment} -> case gas_payment_by_block_hash do
{:ok, minted} = Wei.cast(beneficiary.reward) %{^block_hash => gas_payment} ->
%{beneficiary | reward: Wei.sum(minted, gas_payment)} {:ok, minted} = Wei.cast(beneficiary.reward)
%{beneficiary | reward: Wei.sum(minted, gas_payment)}
_ ->
beneficiary _ ->
beneficiary
end
else
beneficiary
end end
end) end)
end end

Loading…
Cancel
Save