From 4b9ef3dad3580fe529b60a01be716ab7a9d2476f Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 28 Aug 2019 11:18:19 +0300 Subject: [PATCH] parse decimal data from genesis chain spec --- .../lib/explorer/chain_spec/parity/importer.ex | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/explorer/lib/explorer/chain_spec/parity/importer.ex b/apps/explorer/lib/explorer/chain_spec/parity/importer.ex index a1f620ec6c..fa16ee0739 100644 --- a/apps/explorer/lib/explorer/chain_spec/parity/importer.ex +++ b/apps/explorer/lib/explorer/chain_spec/parity/importer.ex @@ -57,6 +57,8 @@ defmodule Explorer.ChainSpec.Parity.Importer do parse_accounts(accounts) else Logger.warn(fn -> "No accounts are defined in chain spec" end) + + [] end end @@ -69,6 +71,8 @@ defmodule Explorer.ChainSpec.Parity.Importer do |> format_ranges() else Logger.warn(fn -> "No rewards are defined in chain spec" end) + + [] end end @@ -79,7 +83,7 @@ defmodule Explorer.ChainSpec.Parity.Importer do end) |> Stream.map(fn {address, %{"balance" => value}} -> {:ok, address_hash} = AddressHash.cast(address) - balance = parse_hex_number(value) + balance = parse_number(value) %{address_hash: address_hash, value: balance} end) @@ -112,16 +116,22 @@ defmodule Explorer.ChainSpec.Parity.Importer do defp parse_hex_numbers(rewards) do Enum.map(rewards, fn {hex_block_number, hex_reward} -> - block_number = parse_hex_number(hex_block_number) - {:ok, reward} = hex_reward |> parse_hex_number() |> Wei.cast() + block_number = parse_number(hex_block_number) + {:ok, reward} = hex_reward |> parse_number() |> Wei.cast() {block_number, reward} end) end - defp parse_hex_number("0x" <> hex_number) do + defp parse_number("0x" <> hex_number) do {number, ""} = Integer.parse(hex_number, 16) number end + + defp parse_number(string_number) do + {number, ""} = Integer.parse(string_number, 10) + + number + end end