@@ -35,7 +35,7 @@ defmodule Explorer.MicroserviceInterfaces.BENS do
3535 | Withdrawal . t ( )
3636
3737 @ doc """
38- Batch request for ENS names via {{baseUrl}}/api/v1/:chainId/addresses:batch-resolve-names
38+ Batch request for ENS names via POST {{baseUrl}}/api/v1/:chainId/addresses:batch-resolve-names
3939 """
4040 @ spec ens_names_batch_request ( [ binary ( ) ] ) :: { :error , :disabled | binary ( ) | Jason.DecodeError . t ( ) } | { :ok , any }
4141 def ens_names_batch_request ( addresses ) do
@@ -49,37 +49,37 @@ defmodule Explorer.MicroserviceInterfaces.BENS do
4949 end
5050
5151 @ doc """
52- Request for ENS name via {{baseUrl}}/api/v1/:chainId/addresses:lookup
52+ Request for ENS name via GET {{baseUrl}}/api/v1/:chainId/addresses:lookup
5353 """
5454 @ spec address_lookup ( binary ( ) ) :: { :error , :disabled | binary ( ) | Jason.DecodeError . t ( ) } | { :ok , any }
5555 def address_lookup ( address ) do
5656 with :ok <- Microservice . check_enabled ( __MODULE__ ) do
57- body = % {
57+ query_params = % {
5858 "address" => to_string ( address ) ,
59- "resolvedTo " => true ,
60- "ownedBy " => false ,
61- "onlyActive " => true ,
59+ "resolved_to " => true ,
60+ "owned_by " => false ,
61+ "only_active " => true ,
6262 "order" => "ASC"
6363 }
6464
65- http_post_request ( address_lookup_url ( ) , body )
65+ http_get_request ( address_lookup_url ( ) , query_params )
6666 end
6767 end
6868
6969 @ doc """
70- Lookup for ENS domain name via {{baseUrl}}/api/v1/:chainId/domains:lookup
70+ Lookup for ENS domain name via GET {{baseUrl}}/api/v1/:chainId/domains:lookup
7171 """
7272 @ spec ens_domain_lookup ( binary ( ) ) :: { :error , :disabled | binary ( ) | Jason.DecodeError . t ( ) } | { :ok , any }
7373 def ens_domain_lookup ( domain ) do
7474 with :ok <- Microservice . check_enabled ( __MODULE__ ) do
75- body = % {
75+ query_params = % {
7676 "name" => domain ,
77- "onlyActive " => true ,
77+ "only_active " => true ,
7878 "sort" => "registration_date" ,
7979 "order" => "DESC"
8080 }
8181
82- http_post_request ( domain_lookup_url ( ) , body )
82+ http_get_request ( domain_lookup_url ( ) , query_params )
8383 end
8484 end
8585
@@ -106,6 +106,27 @@ defmodule Explorer.MicroserviceInterfaces.BENS do
106106 end
107107 end
108108
109+ defp http_get_request ( url , query_params ) do
110+ case HTTPoison . get ( url , [ ] , params: query_params ) do
111+ { :ok , % Response { body: body , status_code: 200 } } ->
112+ Jason . decode ( body )
113+
114+ { _ , error } ->
115+ old_truncate = Application . get_env ( :logger , :truncate )
116+ Logger . configure ( truncate: :infinity )
117+
118+ Logger . error ( fn ->
119+ [
120+ "Error while sending request to BENS microservice url: #{ url } : " ,
121+ inspect ( error , limit: :infinity , printable_limit: :infinity )
122+ ]
123+ end )
124+
125+ Logger . configure ( truncate: old_truncate )
126+ { :error , @ request_error_msg }
127+ end
128+ end
129+
109130 @ spec enabled? ( ) :: boolean
110131 def enabled? , do: Application . get_env ( :explorer , __MODULE__ ) [ :enabled ]
111132
@@ -221,7 +242,7 @@ defmodule Explorer.MicroserviceInterfaces.BENS do
221242 % {
222243 "items" =>
223244 [
224- % { "name" => name , "expiryDate " => expiry_date , "resolvedAddress " => % { "hash" => address_hash_string } }
245+ % { "name" => name , "expiry_date " => expiry_date , "resolved_address " => % { "hash" => address_hash_string } }
225246 | _other
226247 ] = items
227248 } }
@@ -249,9 +270,19 @@ defmodule Explorer.MicroserviceInterfaces.BENS do
249270 defp item_to_address_hash_strings ( % Transaction {
250271 to_address_hash: to_address_hash ,
251272 created_contract_address_hash: nil ,
252- from_address_hash: from_address_hash
273+ from_address_hash: from_address_hash ,
274+ token_transfers: token_transfers
253275 } ) do
254- [ to_string ( to_address_hash ) , to_string ( from_address_hash ) ]
276+ token_transfers_addresses =
277+ case token_transfers do
278+ token_transfers_list when is_list ( token_transfers_list ) ->
279+ List . flatten ( Enum . map ( token_transfers_list , & item_to_address_hash_strings / 1 ) )
280+
281+ _ ->
282+ [ ]
283+ end
284+
285+ [ to_string ( to_address_hash ) , to_string ( from_address_hash ) ] ++ token_transfers_addresses
255286 end
256287
257288 defp item_to_address_hash_strings ( % TokenTransfer {
@@ -304,11 +335,21 @@ defmodule Explorer.MicroserviceInterfaces.BENS do
304335 } = tx ,
305336 names
306337 ) do
338+ token_transfers =
339+ case tx . token_transfers do
340+ token_transfers_list when is_list ( token_transfers_list ) ->
341+ Enum . map ( token_transfers_list , & put_ens_name_to_item ( & 1 , names ) )
342+
343+ other ->
344+ other
345+ end
346+
307347 % Transaction {
308348 tx
309349 | to_address: alter_address ( tx . to_address , to_address_hash , names ) ,
310350 created_contract_address: alter_address ( tx . created_contract_address , created_contract_address_hash , names ) ,
311- from_address: alter_address ( tx . from_address , from_address_hash , names )
351+ from_address: alter_address ( tx . from_address , from_address_hash , names ) ,
352+ token_transfers: token_transfers
312353 }
313354 end
314355
0 commit comments