Added support for UA

This commit is contained in:
Vamsi Krishna B 2022-05-11 22:32:09 +05:30
parent 1cee6135d4
commit 4497c0f36b
5 changed files with 168 additions and 2 deletions

View File

@ -91,4 +91,30 @@ defmodule ZcashExplorerWeb.AddressController do
page_title: "Zcash Address #{address}"
)
end
def get_ua(conn, %{"address" => ua}) do
{:ok, details} = Zcashex.z_listunifiedreceivers(ua)
IO.inspect(details)
orchard_present = Map.has_key?(details, "orchard")
transparent_present = Map.has_key?(details, "p2pkh")
sapling_present = Map.has_key?(details, "sapling")
if String.starts_with?(ua, ["u"]) do
u_qr =
ua
|> EQRCode.encode()
|> EQRCode.png(width: 150, color: <<0, 0, 0>>, background_color: :transparent)
|> Base.encode64()
render(conn, "u_address.html",
address: ua,
qr: u_qr,
page_title: "Zcash Unified Address",
orchard_present: orchard_present,
transparent_present: transparent_present,
sapling_present: sapling_present,
details: details
)
end
end
end

View File

@ -31,6 +31,11 @@ defmodule ZcashExplorerWeb.SearchController do
{:ok, tadd_resp} = Enum.at(results, 2)
{:ok, zadd_resp} = Enum.at(results, 3)
IO.inspect(block_resp)
IO.inspect(tx_resp)
IO.inspect(tadd_resp)
IO.inspect(zadd_resp)
cond do
is_valid_block?(block_resp) ->
redirect(conn, to: "/blocks/#{qs}")
@ -44,6 +49,9 @@ defmodule ZcashExplorerWeb.SearchController do
is_valid_zaddr?(zadd_resp) ->
redirect(conn, to: "/address/#{qs}")
is_valid_unified_address?(zadd_resp) ->
redirect(conn, to: "/ua/#{qs}")
true ->
conn
|> put_status(:not_found)
@ -80,11 +88,27 @@ defmodule ZcashExplorerWeb.SearchController do
false
end
def is_valid_zaddr?({:ok, %{"isvalid" => true}}) do
def is_valid_zaddr?({:ok, %{"isvalid" => true, "type" => "sprout"}}) do
true
end
def is_valid_zaddr?({:ok, %{"isvalid" => true, "type" => "sapling"}}) do
true
end
def is_valid_zaddr?({:ok, %{"isvalid" => true, "type" => "unified"}}) do
false
end
def is_valid_zaddr?({:ok, %{"isvalid" => false}}) do
false
end
def is_valid_unified_address?({:ok, %{"isvalid" => true, "type" => "unified"}}) do
true
end
def is_valid_unified_address?(resp) do
false
end
end

View File

@ -45,6 +45,7 @@ defmodule ZcashExplorerWeb.Router do
get "/vk", PageController, :vk
post "/vk", PageController, :do_import_vk
get "/blockchain-info", PageController, :blockchain_info
get "/ua/:address", AddressController, :get_ua
end
scope "/", ZcashExplorerWeb do

View File

@ -0,0 +1,115 @@
<main class="py-4">
<div class="grid grid-cols-3 gap-4 px-4">
<div class="col-span-3 md:col-span-1 lg:col-span-1 sm:col-span-3">
<div class="bg-white px-4 py-5 shadow rounded-lg sm:px-6 sticky top-10">
<h2 id="technical-details" class="font-medium text-gray-900">Details for the Zcash Unified Address:
</h2>
<p class="mt-1 text-lg leading-6 max-w-2xl text-gray-500 font-mono break-words select-all">
<%= @address %>
</p>
<div class="px-0">
<img src={'data:image/png;base64, #{ @qr }'} atl={"QR code for the Zcash Unified Address #{ @address }"}/>
</div>
<div>
</div>
</div>
</div>
<div class="col-span-3 md:col-span-2 lg:col-span-2 sm:col-span-3
">
<div class="bg-white px-4 py-5 shadow rounded-lg sm:px-6">
<div class="bg-white lg:min-w-0 lg:flex-1">
<h2 class="text-2xl tracking-tight font-extrabold text-gray-900 sm:text-2xl md:text-2xl">
<span class="block xl:inline">You are viewing the details of a </span>
<!-- space -->
<span class="block text-indigo-600 inline">Zcash Unified Address.</span>
</h2>
</div>
<div class="mt-12">
<ul role="list" class="mt-4 border-t border-b border-gray-200 divide-y divide-gray-200">
<li class="relative py-6 flex space-x-4">
<div class="flex-shrink-0">
<span class="flex items-center justify-center h-12 w-12 rounded-lg bg-indigo-50">
<!-- Heroicon name: outline/book-open -->
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z" />
</svg>
</span>
</div>
<div class="min-w-0 flex-1">
<h3 class="text-gray-900 text-xl">
<span class="rounded-sm focus-within:ring-2 focus-within:ring-offset-2 focus-within:ring-indigo-500">
<span class="inset-0" aria-hidden="true"></span>
Orchard Address
</span>
</h3>
<p class="text-base text-gray-500 font-mono select-all">
<%= if @orchard_present == true do %>
<%= @details["orchard"] %>
<% end %>
</p>
</div>
</li>
<li class="relative py-6 flex items-start space-x-4">
<div class="flex-shrink-0">
<span class="flex items-center justify-center h-12 w-12 rounded-lg bg-indigo-50">
<!-- Heroicon name: outline/book-open -->
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z" />
</svg>
</span>
</div>
<div class="min-w-0 flex-1">
<h3 class="text-gray-900 text-xl">
<span class="inset-0" aria-hidden="true"></span>
Sapling Address
</h3>
<p class="text-gray-500 font-mono py-2">
<a class="text-indigo-600 hover:text-indigo-500" href={'/address/#{@details["sapling"]}'}>
<%= if @sapling_present == true do %>
<%= @details["sapling"] %>
<% end %>
</a>
</p>
</div>
</li>
<li class="relative py-6 flex space-x-4">
<div class="flex-shrink-0">
<span class="flex items-center justify-center h-12 w-12 rounded-lg bg-indigo-50">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
</svg>
</span>
</div>
<div class="min-w-0 flex-1">
<h3 class="text-gray-900 text-xl">
<span class="inset-0" aria-hidden="true"></span>
Transparent Address
</h3>
<p class="text-gray-500 font-mono py-2">
<a class="text-indigo-600 hover:text-indigo-500" href={'/address/#{@details["p2pkh"]}'}>
<%= if @transparent_present == true do %>
<%= @details["p2pkh"] %>
<% end %>
</a>
</p>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
</main>

View File

@ -57,5 +57,5 @@
"tzdata": {:hex, :tzdata, "1.1.1", "20c8043476dfda8504952d00adac41c6eda23912278add38edc140ae0c5bcc46", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "a69cec8352eafcd2e198dea28a34113b60fdc6cb57eb5ad65c10292a6ba89787"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
"unsafe": {:hex, :unsafe, "1.0.1", "a27e1874f72ee49312e0a9ec2e0b27924214a05e3ddac90e91727bc76f8613d8", [:mix], [], "hexpm", "6c7729a2d214806450d29766abc2afaa7a2cbecf415be64f36a6691afebb50e5"},
"zcashex": {:git, "https://github.com/nighthawk-apps/zcashex.git", "dca51cca3df69586016b24277614565514e1b8e2", []},
"zcashex": {:git, "https://github.com/nighthawk-apps/zcashex.git", "5975509b8d6fc8716d7891eb8c9cb7b089ca18d3", []},
}