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