Fetch token during ContractState initialization

This prevents situations when the token is missing during startup.
staking
Paul Tsupikoff 5 years ago committed by Victor Baranov
parent 888e56c13d
commit ad73dabd3e
  1. 14
      apps/explorer/lib/explorer/staking/contract_state.ex
  2. 9
      apps/explorer/test/explorer/staking/contract_state_test.exs

@ -65,8 +65,14 @@ defmodule Explorer.Staking.ContractState do
staking_contract_address = Application.get_env(:explorer, __MODULE__)[:staking_contract_address]
%{"validatorSetContract" => {:ok, [validator_set_contract_address]}} =
Reader.query_contract(staking_contract_address, staking_abi, %{"validatorSetContract" => []})
%{
"validatorSetContract" => {:ok, [validator_set_contract_address]},
"erc20TokenContract" => {:ok, [token_contract_address]}
} =
Reader.query_contract(staking_contract_address, staking_abi, %{
"validatorSetContract" => [],
"erc20TokenContract" => []
})
%{"blockRewardContract" => {:ok, [block_reward_contract_address]}} =
Reader.query_contract(validator_set_contract_address, validator_set_abi, %{"blockRewardContract" => []})
@ -84,7 +90,9 @@ defmodule Explorer.Staking.ContractState do
:ets.insert(@table_name,
staking_contract: %{abi: staking_abi, address: staking_contract_address},
validator_set_contract: %{abi: validator_set_abi, address: validator_set_contract_address},
block_reward_contract: %{abi: block_reward_abi, address: block_reward_contract_address}
block_reward_contract: %{abi: block_reward_abi, address: block_reward_contract_address},
token_contract_address: token_contract_address,
token: get_token(token_contract_address)
)
{:ok, state, {:continue, []}}

@ -56,8 +56,13 @@ defmodule Explorer.Staking.ContractStateTest do
EthereumJSONRPC.Mox,
:json_rpc,
fn requests, _opts ->
assert length(requests) == 1
{:ok, format_responses(["0x0000000000000000000000001000000000000000000000000000000000000001"])}
assert length(requests) == 2
{:ok,
format_responses([
"0x0000000000000000000000001000000000000000000000000000000000000001",
"0x0000000000000000000000006f7a73c96bd56f8b0debc795511eda135e105ea3"
])}
end
)

Loading…
Cancel
Save