parse decimal data from genesis chain spec

pull/2505/head
Ayrat Badykov 5 years ago
parent a89f96944e
commit 4b9ef3dad3
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 18
      apps/explorer/lib/explorer/chain_spec/parity/importer.ex

@ -57,6 +57,8 @@ defmodule Explorer.ChainSpec.Parity.Importer do
parse_accounts(accounts) parse_accounts(accounts)
else else
Logger.warn(fn -> "No accounts are defined in chain spec" end) Logger.warn(fn -> "No accounts are defined in chain spec" end)
[]
end end
end end
@ -69,6 +71,8 @@ defmodule Explorer.ChainSpec.Parity.Importer do
|> format_ranges() |> format_ranges()
else else
Logger.warn(fn -> "No rewards are defined in chain spec" end) Logger.warn(fn -> "No rewards are defined in chain spec" end)
[]
end end
end end
@ -79,7 +83,7 @@ defmodule Explorer.ChainSpec.Parity.Importer do
end) end)
|> Stream.map(fn {address, %{"balance" => value}} -> |> Stream.map(fn {address, %{"balance" => value}} ->
{:ok, address_hash} = AddressHash.cast(address) {:ok, address_hash} = AddressHash.cast(address)
balance = parse_hex_number(value) balance = parse_number(value)
%{address_hash: address_hash, value: balance} %{address_hash: address_hash, value: balance}
end) end)
@ -112,16 +116,22 @@ defmodule Explorer.ChainSpec.Parity.Importer do
defp parse_hex_numbers(rewards) do defp parse_hex_numbers(rewards) do
Enum.map(rewards, fn {hex_block_number, hex_reward} -> Enum.map(rewards, fn {hex_block_number, hex_reward} ->
block_number = parse_hex_number(hex_block_number) block_number = parse_number(hex_block_number)
{:ok, reward} = hex_reward |> parse_hex_number() |> Wei.cast() {:ok, reward} = hex_reward |> parse_number() |> Wei.cast()
{block_number, reward} {block_number, reward}
end) end)
end end
defp parse_hex_number("0x" <> hex_number) do defp parse_number("0x" <> hex_number) do
{number, ""} = Integer.parse(hex_number, 16) {number, ""} = Integer.parse(hex_number, 16)
number number
end end
defp parse_number(string_number) do
{number, ""} = Integer.parse(string_number, 10)
number
end
end end

Loading…
Cancel
Save