Fix sushiswap lp tokens custom metadata fetcher

pull/3742/head
Viktor Baranov 4 years ago
parent 645e3efc56
commit 300b7b3866
  1. 1
      CHANGELOG.md
  2. 47
      apps/explorer/lib/explorer/chain.ex
  3. 2
      apps/explorer/lib/explorer/staking/contract_state.ex

@ -14,6 +14,7 @@
- [#3564](https://github.com/poanetwork/blockscout/pull/3564) - Staking welcome message
### Fixes
- [#3742](https://github.com/blockscout/blockscout/pull/3742) - Fix Sushiswap LP tokens custom metadata fetcher: bytes(n) symbol and name support
- [#3741](https://github.com/blockscout/blockscout/pull/3741) - Contract reader fix when there are multiple input params including an array type
- [#3735](https://github.com/blockscout/blockscout/pull/3735) - Token balance on demand fetcher memory leak fix
- [#3732](https://github.com/poanetwork/blockscout/pull/3732) - POSDAO: fix snapshotting and remove temporary code

@ -82,6 +82,7 @@ defmodule Explorer.Chain do
alias Explorer.Market.MarketHistoryCache
alias Explorer.{PagingOptions, Repo}
alias Explorer.SmartContract.Reader
alias Explorer.Staking.ContractState
alias Dataloader.Ecto, as: DataloaderEcto
@ -4232,10 +4233,10 @@ defmodule Explorer.Chain do
symbol_signature
|> Contract.eth_call_request(token1_hash_str, 2, nil, nil)
|> json_rpc(eth_call_foreign_json_rpc_named_arguments) do
token0_name = parse_contract_response(token0_name_encoded, :string)
token1_name = parse_contract_response(token1_name_encoded, :string)
token0_symbol = parse_contract_response(token0_symbol_encoded, :string)
token1_symbol = parse_contract_response(token1_symbol_encoded, :string)
token0_name = parse_contract_response(token0_name_encoded, :string, {:bytes, 32})
token1_name = parse_contract_response(token1_name_encoded, :string, {:bytes, 32})
token0_symbol = parse_contract_response(token0_symbol_encoded, :string, {:bytes, 32})
token1_symbol = parse_contract_response(token1_symbol_encoded, :string, {:bytes, 32})
"#{token0_name}/#{token1_name} (#{token0_symbol}/#{token1_symbol})"
else
@ -4415,19 +4416,47 @@ defmodule Explorer.Chain do
values
end
defp parse_contract_response(abi_encoded_value, type) do
defp parse_contract_response(abi_encoded_value, type, emergency_type \\ nil) do
[value] =
try do
abi_encoded_value
|> Base.decode16!(case: :mixed)
|> TypeDecoder.decode_raw([type])
[res] = decode_contract_response(abi_encoded_value, type)
[convert_binary_to_string(res, type)]
rescue
_ -> [nil]
_ ->
if emergency_type do
try do
[res] = decode_contract_response(abi_encoded_value, emergency_type)
[convert_binary_to_string(res, emergency_type)]
rescue
_ ->
[nil]
end
else
[nil]
end
end
value
end
defp decode_contract_response(abi_encoded_value, type) do
abi_encoded_value
|> Base.decode16!(case: :mixed)
|> TypeDecoder.decode_raw([type])
end
defp convert_binary_to_string(binary, type) do
case type do
{:bytes, _} ->
ContractState.binary_to_string(binary)
_ ->
binary
end
end
defp compose_foreign_json_rpc_named_arguments(json_rpc_named_arguments, foreign_json_rpc)
when foreign_json_rpc != "" do
{_, eth_call_foreign_json_rpc_named_arguments} =

@ -1086,7 +1086,7 @@ defmodule Explorer.Staking.ContractState do
|> Jason.decode!()
end
defp binary_to_string(binary) do
def binary_to_string(binary) do
binary
|> :binary.bin_to_list()
|> Enum.filter(fn x -> x != 0 end)

Loading…
Cancel
Save