From f9676bc04833c735df3558b422a657fdf7821d23 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Mon, 19 Aug 2019 15:13:34 +0300 Subject: [PATCH] integrate poa emission rewards to supervision tree --- apps/explorer/config/config.exs | 6 +++++- .../lib/explorer/chain_spec/parity/importer.ex | 18 ++++++++++++++---- .../lib/explorer/chain_spec/poa/importer.ex | 9 ++++++--- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/apps/explorer/config/config.exs b/apps/explorer/config/config.exs index 95c80ba445..e4ba8ef577 100644 --- a/apps/explorer/config/config.exs +++ b/apps/explorer/config/config.exs @@ -27,7 +27,11 @@ config :explorer, Explorer.Counters.AverageBlockTime, enabled: true, period: average_block_period -config :explorer, Explorer.ChainSpec.GenesisData, enabled: true, chain_spec_path: System.get_env("CHAIN_SPEC_PATH") +config :explorer, Explorer.ChainSpec.GenesisData, + enabled: true, + chain_spec_path: System.get_env("CHAIN_SPEC_PATH"), + emission_format: System.get_env("EMISSION_FORMAT", "DEFAULT"), + rewards_contract_address: System.get_env("REWARDS_CONTRACT_ADDRESS", "0xeca443e8e1ab29971a45a9c57a6a9875701698a5") config :explorer, Explorer.Chain.Cache.BlockNumber, enabled: true diff --git a/apps/explorer/lib/explorer/chain_spec/parity/importer.ex b/apps/explorer/lib/explorer/chain_spec/parity/importer.ex index 6b560bf530..620acfb934 100644 --- a/apps/explorer/lib/explorer/chain_spec/parity/importer.ex +++ b/apps/explorer/lib/explorer/chain_spec/parity/importer.ex @@ -7,14 +7,17 @@ defmodule Explorer.ChainSpec.Parity.Importer do alias Explorer.Chain.Block.{EmissionReward, Range} alias Explorer.Chain.Hash.Address, as: AddressHash alias Explorer.Chain.Wei + alias Explorer.ChainSpec.GenesisData + alias Explorer.ChainSpec.POA.Importer, as: PoaEmissionImporter @max_block_number :infinity def import_emission_rewards(chain_spec) do - rewards = emission_rewards(chain_spec) - - {_, nil} = Repo.delete_all(EmissionReward) - {_, nil} = Repo.insert_all(EmissionReward, rewards) + if Application.get_env(:explorer, GenesisData)[:emission_format] == "POA" do + PoaEmissionImporter.import_emission_rewards() + else + import_rewards_from_chain_spec(chain_spec) + end end def import_genesis_coin_balances(chain_spec) do @@ -38,6 +41,13 @@ defmodule Explorer.ChainSpec.Parity.Importer do Chain.import(params) end + defp import_rewards_from_chain_spec(chain_spec) do + rewards = emission_rewards(chain_spec) + + {_, nil} = Repo.delete_all(EmissionReward) + {_, nil} = Repo.insert_all(EmissionReward, rewards) + end + def genesis_coin_balances(chain_spec) do accounts = chain_spec["accounts"] diff --git a/apps/explorer/lib/explorer/chain_spec/poa/importer.ex b/apps/explorer/lib/explorer/chain_spec/poa/importer.ex index 45e18e6d1c..80d2c23696 100644 --- a/apps/explorer/lib/explorer/chain_spec/poa/importer.ex +++ b/apps/explorer/lib/explorer/chain_spec/poa/importer.ex @@ -8,7 +8,6 @@ defmodule Explorer.ChainSpec.POA.Importer do alias Explorer.SmartContract.Reader alias Explorer.Chain.Block.{EmissionReward, Range} - @reward_by_block_contract_address "0xeca443e8e1ab29971a45a9c57a6a9875701698a5" @block_reward_amount_abi %{ "type" => "function", "stateMutability" => "view", @@ -51,11 +50,15 @@ defmodule Explorer.ChainSpec.POA.Importer do end def block_reward_amount do - call_contract(@reward_by_block_contract_address, @block_reward_amount_abi, @block_reward_amount_params) + call_contract(rewards_contract_address(), @block_reward_amount_abi, @block_reward_amount_params) end def emission_funds_amount do - call_contract(@reward_by_block_contract_address, @emission_funds_amount_abi, @emission_funds_amount_params) + call_contract(rewards_contract_address(), @emission_funds_amount_abi, @emission_funds_amount_params) + end + + defp rewards_contract_address do + Application.get_env(:explorer, GenesisData)[:rewards_contract_address] end defp call_contract(address, abi, params) do