fix: invalid metadata requests (#11210)

* fix: prevent empty requests to metadata service

* fix: remove empty hashes from request parameters

* Small fix

* Add docs

---------

Co-authored-by: Leonid Tyurin <lenyatyurin162586@gmail.com>
production-optimism
nikitosing 23 hours ago committed by GitHub
parent b7458900c7
commit b899b64d43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      apps/explorer/lib/explorer/chain/address/metadata_preloader.ex
  2. 24
      apps/explorer/lib/explorer/microservice_interfaces/metadata.ex

@ -86,9 +86,8 @@ defmodule Explorer.Chain.Address.MetadataPreloader do
def preload_metadata_to_list(items) do
address_hash_strings =
items
|> Enum.reduce([], fn item, acc ->
item_to_address_hash_strings(item) ++ acc
end)
|> Enum.flat_map(&item_to_address_hash_strings/1)
|> Enum.filter(&(&1 != ""))
|> Enum.uniq()
case Metadata.get_addresses_tags(address_hash_strings) do

@ -18,16 +18,34 @@ defmodule Explorer.MicroserviceInterfaces.Metadata do
@page_size 50
@request_error_msg "Error while sending request to Metadata microservice"
@spec get_addresses_tags([String.t()]) :: {:error, :disabled | <<_::416>> | Jason.DecodeError.t()} | {:ok, any()}
@doc """
Retrieves tags for a list of addresses.
## Parameters
- `addresses`: A list of addresses for which tags need to be fetched.
## Returns
- A map with metadata tags from microservice. Returns `:ignore` when the input list is empty.
## Examples
iex> get_addresses_tags([])
:ignore
"""
@spec get_addresses_tags([String.t()]) ::
{:error, :disabled | <<_::416>> | Jason.DecodeError.t()} | {:ok, any()} | :ignore
def get_addresses_tags([]), do: :ignore
def get_addresses_tags(addresses) do
with :ok <- Microservice.check_enabled(__MODULE__) do
body = %{
params = %{
addresses: Enum.join(addresses, ","),
tags_limit: @tags_per_address_limit,
chain_id: Application.get_env(:block_scout_web, :chain_id)
}
http_get_request(addresses_metadata_url(), body)
http_get_request(addresses_metadata_url(), params)
end
end

Loading…
Cancel
Save