@ -134,7 +134,7 @@ defmodule BlockScoutWeb.AddressContractVerificationController do
def get_metadata_and_publish ( address_hash_string , nil ) do
case Sourcify . get_metadata ( address_hash_string ) do
{ :ok , verification_metadata } ->
proccess_metadata_ad d_publish ( address_hash_string , verification_metadata , false )
process_metadata_an d_publish ( address_hash_string , verification_metadata , false )
{ :error , %{ " error " = > error } } ->
{ :error , error : error }
@ -144,7 +144,7 @@ defmodule BlockScoutWeb.AddressContractVerificationController do
def get_metadata_and_publish ( address_hash_string , conn ) do
case Sourcify . get_metadata ( address_hash_string ) do
{ :ok , verification_metadata } ->
proccess_metadata_ad d_publish ( address_hash_string , verification_metadata , false , conn )
process_metadata_an d_publish ( address_hash_string , verification_metadata , false , conn )
{ :error , %{ " error " = > error } } ->
EventsPublisher . broadcast (
@ -154,7 +154,7 @@ defmodule BlockScoutWeb.AddressContractVerificationController do
end
end
defp proccess_metadata_ad d_publish ( address_hash_string , verification_metadata , is_partial , conn \\ nil ) do
defp process_metadata_an d_publish ( address_hash_string , verification_metadata , is_partial , conn \\ nil ) do
%{ " params_to_publish " = > params_to_publish , " abi " = > abi , " secondary_sources " = > secondary_sources } =
parse_params_from_sourcify ( address_hash_string , verification_metadata )
@ -187,10 +187,9 @@ defmodule BlockScoutWeb.AddressContractVerificationController do
end
def parse_params_from_sourcify ( address_hash_string , verification_metadata ) do
verification_metadata_json =
[ verification_metadata_json ] =
verification_metadata
|> Enum . filter ( fn %{ " name " = > name , " content " = > _content } -> name =~ " .json " end )
|> Enum . at ( 0 )
|> Enum . filter ( & ( Map . get ( &1 , " name " ) == " metadata.json " ) )
full_params_initial = parse_json_from_sourcify_for_insertion ( verification_metadata_json )
@ -198,34 +197,31 @@ defmodule BlockScoutWeb.AddressContractVerificationController do
verification_metadata
|> Enum . filter ( fn %{ " name " = > name , " content " = > _content } -> name =~ " .sol " end )
full_params =
verification_metadata_sol
|> Enum . reduce ( full_params_initial , fn %{ " name " = > name , " content " = > content , " path " = > _path } = param ,
full_params_acc ->
compilation_target_file_name = Map . get ( full_params_acc , " compilation_target_file_name " )
if String . downcase ( name ) == String . downcase ( compilation_target_file_name ) do
%{
" params_to_publish " = > extract_primary_source_code ( content , Map . get ( full_params_acc , " params_to_publish " ) ) ,
" abi " = > Map . get ( full_params_acc , " abi " ) ,
" secondary_sources " = > Map . get ( full_params_acc , " secondary_sources " ) ,
" compilation_target_file_name " = > Map . get ( full_params_acc , " compilation_target_file_name " )
}
else
secondary_sources = [
prepare_additional_source ( address_hash_string , param ) | Map . get ( full_params_acc , " secondary_sources " )
]
%{
" params_to_publish " = > Map . get ( full_params_acc , " params_to_publish " ) ,
" abi " = > Map . get ( full_params_acc , " abi " ) ,
" secondary_sources " = > secondary_sources ,
" compilation_target_file_name " = > Map . get ( full_params_acc , " compilation_target_file_name " )
}
end
end )
verification_metadata_sol
|> Enum . reduce ( full_params_initial , fn %{ " name " = > name , " content " = > content , " path " = > _path } = param ,
full_params_acc ->
compilation_target_file_name = Map . get ( full_params_acc , " compilation_target_file_name " )
full_params
if String . downcase ( name ) == String . downcase ( compilation_target_file_name ) do
%{
" params_to_publish " = > extract_primary_source_code ( content , Map . get ( full_params_acc , " params_to_publish " ) ) ,
" abi " = > Map . get ( full_params_acc , " abi " ) ,
" secondary_sources " = > Map . get ( full_params_acc , " secondary_sources " ) ,
" compilation_target_file_name " = > Map . get ( full_params_acc , " compilation_target_file_name " )
}
else
secondary_sources = [
prepare_additional_source ( address_hash_string , param ) | Map . get ( full_params_acc , " secondary_sources " )
]
%{
" params_to_publish " = > Map . get ( full_params_acc , " params_to_publish " ) ,
" abi " = > Map . get ( full_params_acc , " abi " ) ,
" secondary_sources " = > secondary_sources ,
" compilation_target_file_name " = > Map . get ( full_params_acc , " compilation_target_file_name " )
}
end
end )
end
defp prepare_additional_source ( address_hash_string , %{ " name " = > name , " content " = > content , " path " = > _path } ) do
@ -293,10 +289,10 @@ defmodule BlockScoutWeb.AddressContractVerificationController do
else
case Sourcify . check_by_address_any ( address_hash_string ) do
{ :ok , " full " , metadata } ->
proccess_metadata_ad d_publish ( address_hash_string , metadata , false )
process_metadata_an d_publish ( address_hash_string , metadata , false )
{ :ok , " partial " , metadata } ->
proccess_metadata_ad d_publish ( address_hash_string , metadata , true )
process_metadata_an d_publish ( address_hash_string , metadata , true )
_ ->
{ :error , :not_verified }