handle metadata in token uri

pull/2755/head
Ayrat Badykov 5 years ago
parent faab55ed82
commit 57abb0047c
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 29
      apps/explorer/lib/explorer/token/instance_metadata_retriever.ex

@ -50,7 +50,30 @@ defmodule Explorer.Token.InstanceMetadataRetriever do
{:error, :no_uri} {:error, :no_uri}
end end
defp fetch_json(%{"tokenURI" => {:ok, [token_uri]}}) do defp fetch_json(%{"tokenURI" => {:ok, ["http://" <> _ = token_uri]}}) do
fetch_metadata(token_uri)
end
defp fetch_json(%{"tokenURI" => {:ok, ["https://" <> _ = token_uri]}}) do
fetch_metadata(token_uri)
end
defp fetch_json(%{"tokenURI" => {:ok, [json]}}) do
Jason.decode(json)
rescue
e ->
Logger.error(fn -> ["Unknown metadata format #{inspect(json)}. error #{inspect(e)}"] end)
{:error, json}
end
defp fetch_json(result) do
Logger.error(fn -> ["Unknown metadata format #{result}."] end)
{:error, result}
end
defp fetch_metadata(token_uri) do
case HTTPoison.get(token_uri) do case HTTPoison.get(token_uri) do
{:ok, %Response{body: body, status_code: 200}} -> {:ok, %Response{body: body, status_code: 200}} ->
Jason.decode(body) Jason.decode(body)
@ -67,8 +90,4 @@ defmodule Explorer.Token.InstanceMetadataRetriever do
{:error, :request_error} {:error, :request_error}
end end
defp fetch_json(result) do
{:error, result}
end
end end

Loading…
Cancel
Save