Merge pull request #1554 from poanetwork/ab-encode-integers-for-abi

encode integer parameters when calling smart contract functions
pull/1560/head
Victor Baranov 6 years ago committed by GitHub
commit d4e0685c19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      apps/explorer/lib/explorer/smart_contract/reader.ex
  2. 4
      apps/explorer/test/explorer/smart_contract/reader_test.exs

@ -254,8 +254,16 @@ defmodule Explorer.SmartContract.Reader do
response = Integer.parse(item)
case response do
{integer, remainder_of_binary} when remainder_of_binary == "" -> integer
_ -> item
{integer, ""} ->
hex_encoding =
integer
|> :binary.encode_unsigned()
|> Base.encode16(case: :lower)
"0x" <> hex_encoding
_ ->
item
end
end

@ -214,10 +214,12 @@ defmodule Explorer.SmartContract.ReaderTest do
describe "normalize_args/1" do
test "converts argument when is a number" do
assert [0] = Reader.normalize_args(["0"])
assert ["0x00"] = Reader.normalize_args(["0"])
assert ["0x798465571ae21a184a272f044f991ad1d5f87a3f"] =
Reader.normalize_args(["0x798465571ae21a184a272f044f991ad1d5f87a3f"])
assert ["0x7b"] = Reader.normalize_args(["123"])
end
test "converts argument when is a boolean" do

Loading…
Cancel
Save