Merge pull request #3601 from poanetwork/vb-contract-reader-fix

Fix contract reader
pull/3569/head
Victor Baranov 4 years ago committed by GitHub
commit 8efa2588c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 20
      apps/block_scout_web/lib/block_scout_web/views/smart_contract_view.ex
  3. 11
      apps/block_scout_web/test/block_scout_web/views/tokens/smart_contract_view_test.exs

@ -6,7 +6,7 @@
### Fixes ### Fixes
- [#3600](https://github.com/poanetwork/blockscout/pull/3600) - Prevent update validator metadata with empty name from contract - [#3600](https://github.com/poanetwork/blockscout/pull/3600) - Prevent update validator metadata with empty name from contract
- [#3592](https://github.com/poanetwork/blockscout/pull/3592) - Contract interaction: fix nested tuples in the output view, add formatting - [#3592](https://github.com/poanetwork/blockscout/pull/3592), [#3601](https://github.com/poanetwork/blockscout/pull/3601) - Contract interaction: fix nested tuples in the output view, add formatting
- [#3583](https://github.com/poanetwork/blockscout/pull/3583) - Reduce RPC requests and DB changes by Staking DApp - [#3583](https://github.com/poanetwork/blockscout/pull/3583) - Reduce RPC requests and DB changes by Staking DApp
### Chore ### Chore

@ -93,7 +93,7 @@ defmodule BlockScoutWeb.SmartContractView do
render_type_value(type, values) render_type_value(type, values)
end end
def values_with_type(value, type, _components) when type in ["address", "address payable"] do def values_with_type(value, type, _components) when type in [:address, "address", "address payable"] do
{:ok, address} = Address.cast(value) {:ok, address} = Address.cast(value)
render_type_value("address", to_string(address)) render_type_value("address", to_string(address))
end end
@ -102,7 +102,13 @@ defmodule BlockScoutWeb.SmartContractView do
def values_with_type(value, "bool", _components), do: render_type_value("bool", to_string(value)) def values_with_type(value, "bool", _components), do: render_type_value("bool", to_string(value))
def values_with_type(value, type, _components), do: render_type_value(type, binary_to_utf_string(value)) def values_with_type(value, type, _components) do
if String.starts_with?(type, "uint") do
render_type_value(type, to_string(value))
else
render_type_value(type, binary_to_utf_string(value))
end
end
def values_only(value, type, components) when is_list(value) do def values_only(value, type, components) when is_list(value) do
cond do cond do
@ -153,7 +159,7 @@ defmodule BlockScoutWeb.SmartContractView do
values values
end end
def values_only(value, type, _components) when type in ["address", "address payable"] do def values_only(value, type, _components) when type in [:address, "address", "address payable"] do
{:ok, address} = Address.cast(value) {:ok, address} = Address.cast(value)
to_string(address) to_string(address)
end end
@ -162,7 +168,13 @@ defmodule BlockScoutWeb.SmartContractView do
def values_only(value, "bool", _components), do: to_string(value) def values_only(value, "bool", _components), do: to_string(value)
def values_only(value, _type, _components), do: binary_to_utf_string(value) def values_only(value, type, _components) do
if String.starts_with?(type, "uint") do
to_string(value)
else
binary_to_utf_string(value)
end
end
defp tuple_array_to_array(value, type) do defp tuple_array_to_array(value, type) do
value value

@ -252,6 +252,11 @@ defmodule BlockScoutWeb.SmartContractViewTest do
assert SmartContractView.values_only(value, "address", nil) == "0x5f26097334b6a32b7951df61fd0c5803ec5d8354" assert SmartContractView.values_only(value, "address", nil) == "0x5f26097334b6a32b7951df61fd0c5803ec5d8354"
end end
test "convert the value to string receiving a value and the :address type" do
value = <<95, 38, 9, 115, 52, 182, 163, 43, 121, 81, 223, 97, 253, 12, 88, 3, 236, 93, 131, 84>>
assert SmartContractView.values_only(value, :address, nil) == "0x5f26097334b6a32b7951df61fd0c5803ec5d8354"
end
test "convert the value to string receiving a value and the 'address payable' type" do test "convert the value to string receiving a value and the 'address payable' type" do
value = <<95, 38, 9, 115, 52, 182, 163, 43, 121, 81, 223, 97, 253, 12, 88, 3, 236, 93, 131, 84>> value = <<95, 38, 9, 115, 52, 182, 163, 43, 121, 81, 223, 97, 253, 12, 88, 3, 236, 93, 131, 84>>
@ -295,5 +300,11 @@ defmodule BlockScoutWeb.SmartContractViewTest do
assert SmartContractView.values_only(value, "bytes32", nil) == assert SmartContractView.values_only(value, "bytes32", nil) ==
"0x9cd14677f9aa5569b3bbb351fcd67d1115aa563ae1624276d3d4e67fb3d6f926" "0x9cd14677f9aa5569b3bbb351fcd67d1115aa563ae1624276d3d4e67fb3d6f926"
end end
test "returns the value when the type is uint(n) and value is 0" do
value = "0"
assert SmartContractView.values_only(value, "uint64", nil) == "0"
end
end end
end end

Loading…
Cancel
Save