integrate poa emission rewards to supervision tree

pull/2505/head
Ayrat Badykov 5 years ago
parent 57374668c0
commit f9676bc048
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 6
      apps/explorer/config/config.exs
  2. 18
      apps/explorer/lib/explorer/chain_spec/parity/importer.ex
  3. 9
      apps/explorer/lib/explorer/chain_spec/poa/importer.ex

@ -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

@ -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"]

@ -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

Loading…
Cancel
Save