Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3064 from poanetwork/vb-token-bridge-block-reward
Browse files Browse the repository at this point in the history
Automatically define Block reward contract address in TokenBridge supply module
  • Loading branch information
vbaranov authored Apr 2, 2020
2 parents fcb160c + 3d3cbb5 commit f9be788
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixes

- [#3064](https://github.com/poanetwork/blockscout/pull/3064) - Automatically define Block reward contract address in TokenBridge supply module
- [#3061](https://github.com/poanetwork/blockscout/pull/3061) - Fix verification of contracts with error messages in require in parent contract

### Chore
Expand Down
48 changes: 41 additions & 7 deletions apps/explorer/lib/explorer/chain/supply/token_bridge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ defmodule Explorer.Chain.Supply.TokenBridge do
}
@total_burned_coins_params %{"totalBurntCoins" => []}

@block_reward_contract_address "0x867305d19606aadba405ce534e303d0e225f9556"
@block_reward_contract_abi %{
"type" => "function",
"stateMutability" => "view",
"payable" => false,
"outputs" => [%{"type" => "address", "name" => ""}],
"name" => "blockRewardContract",
"inputs" => [],
"constant" => true
}

@block_reward_contract_params %{"blockRewardContract" => []}

@total_minted_coins_abi %{
"type" => "function",
"stateMutability" => "view",
Expand All @@ -30,6 +41,7 @@ defmodule Explorer.Chain.Supply.TokenBridge do
"inputs" => [],
"constant" => true
}

@total_minted_coins_params %{"mintedTotally" => []}

@ets_table :token_bridge_contract_coin_cache
Expand All @@ -47,16 +59,22 @@ defmodule Explorer.Chain.Supply.TokenBridge do
cached_total_coins(cache_period)
end

defp minted_coins do
address = System.get_env("BLOCK_REWARD_CONTRACT") || @block_reward_contract_address
defp burned_coins do
address = System.get_env("TOKEN_BRIDGE_CONTRACT") || @token_bridge_contract_address

call_contract(address, @total_minted_coins_abi, @total_minted_coins_params)
call_contract(address, @total_burned_coins_abi, @total_burned_coins_params)
end

defp burned_coins do
defp block_reward_contract do
address = System.get_env("TOKEN_BRIDGE_CONTRACT") || @token_bridge_contract_address

call_contract(address, @total_burned_coins_abi, @total_burned_coins_params)
call_contract(address, @block_reward_contract_abi, @block_reward_contract_params)
end

defp minted_coins do
address = block_reward_contract()

call_contract(address, @total_minted_coins_abi, @total_minted_coins_params)
end

defp call_contract(address, abi, params) do
Expand All @@ -73,7 +91,23 @@ defmodule Explorer.Chain.Supply.TokenBridge do
_ -> 0
end

%Wei{value: Decimal.new(value)}
type =
abi
|> Enum.at(0)
|> Map.get("outputs", [])
|> Enum.at(0)
|> Map.get("type", "")

case type do
"address" ->
"0x" <> Base.encode16(value)

"uint256" ->
%Wei{value: Decimal.new(value)}

_ ->
value
end
end

def cached_total_coins(cache_period) do
Expand Down

0 comments on commit f9be788

Please sign in to comment.