Added TX Fee

This commit is contained in:
Vamsi Krishna B 2021-07-22 22:27:34 +05:30
parent 1218aa988e
commit 14aec95a40
7 changed files with 192 additions and 183 deletions

View File

@ -30,12 +30,12 @@ config :zcash_explorer, ZcashExplorerWeb.Endpoint,
]
]
config :zcash_explorer, Zcashex,
zcashd_hostname: "localhost",
zcashd_port: "38232",
zcashd_username: "zcashrpc",
zcashd_password: "changeme"
# ## SSL Support
#
# In order to use HTTPS in development, a self-signed

View File

@ -30,6 +30,7 @@ defmodule ZcashExplorerWeb do
def view do
quote do
import Phoenix.LiveView.Helpers
use Phoenix.View,
root: "lib/zcash_explorer_web/templates",
namespace: ZcashExplorerWeb
@ -38,8 +39,6 @@ defmodule ZcashExplorerWeb do
import Phoenix.Controller,
only: [get_flash: 1, get_flash: 2, view_module: 1, view_template: 1]
# Include shared imports and aliases for views
unquote(view_helpers())
end

View File

@ -2,7 +2,7 @@
<div>
<dl class="mt-5 grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-4">
<div class="relative bg-white pt-5 px-4 pb-12 sm:pt-6 sm:px-6 shadow rounded-lg overflow-hidden">
<dt>
<div class="absolute bg-indigo-500 rounded-md p-3">
@ -26,9 +26,9 @@
<p class="ml-16 text-sm font-medium text-gray-500 truncate">Blocks</p>
</dt>
<dd class="ml-16 pb-6 flex items-baseline sm:pb-7">
<%= live_render(@conn, ZcashExplorerWeb.BlockCountLive) %>
<div class="absolute bottom-0 inset-x-0 bg-gray-50 px-4 py-4 sm:px-6">
<div class="text-sm">
<a href="/blocks" class="font-medium text-indigo-600 hover:text-indigo-500"> View blocks<span class="sr-only"> View blocks</span></a>
@ -40,16 +40,16 @@
<div class="relative bg-white pt-5 px-4 pb-12 sm:pt-6 sm:px-6 shadow rounded-lg overflow-hidden">
<dt>
<div class="absolute bg-indigo-500 rounded-md p-3">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z" />
</svg> </div>
<p class="ml-16 text-sm font-medium text-gray-500 truncate">Mempool Transactions</p>
</dt>
<dd class="ml-16 pb-6 flex items-baseline sm:pb-7">
<%= live_render(@conn, ZcashExplorerWeb.MempoolInfoLive) %>
<div class="absolute bottom-0 inset-x-0 bg-gray-50 px-4 py-4 sm:px-6">
<div class="text-sm">
<a href="/mempool" class="font-medium text-indigo-600 hover:text-indigo-500">View mempool transactions<span class="sr-only"> View mempool transactions</span></a>
@ -63,17 +63,17 @@
<div class="relative bg-white pt-5 px-4 pb-12 sm:pt-6 sm:px-6 shadow rounded-lg overflow-hidden">
<dt>
<div class="absolute bg-green-500 rounded-md p-3">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M9 19l3 3m0 0l3-3m-3 3V10" />
</svg>
</svg>
</div>
<p class="ml-16 text-sm font-medium text-gray-500 truncate">Blockchain Size</p>
</dt>
<dd class="ml-16 pb-6 flex items-baseline sm:pb-7">
<%= live_render(@conn, ZcashExplorerWeb.BlockChainSizeLive) %>
<div class="absolute bottom-0 inset-x-0 bg-gray-50 px-4 py-4 sm:px-6">
<div class="text-sm">
<a href="#" class="font-medium text-indigo-600 hover:text-indigo-500">View blockchain info<span class="sr-only"> View blockchain info</span></a>
@ -82,52 +82,6 @@
</dd>
</div>
<div class="relative bg-white pt-5 px-4 pb-12 sm:pt-6 sm:px-6 shadow rounded-lg overflow-hidden">
<dt>
<div class="absolute bg-indigo-500 rounded-md p-3">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z" />
</svg>
</div>
<p class="ml-16 text-sm font-medium text-gray-500 truncate">Difficulty</p>
</dt>
<dd class="ml-16 pb-6 flex items-baseline sm:pb-7">
<%= live_render(@conn, ZcashExplorerWeb.DifficultyLive) %>
<div class="absolute bottom-0 inset-x-0 bg-gray-50 px-4 py-4 sm:px-6">
<div class="text-sm">
<a href="#" class="font-medium text-indigo-600 hover:text-indigo-500">View network info<span class="sr-only"> View network info</span></a>
</div>
</div>
</dd>
</div>
<div class="relative bg-white pt-5 px-4 pb-12 sm:pt-6 sm:px-6 shadow rounded-lg overflow-hidden">
<dt>
<div class="absolute bg-green-500 rounded-md p-3">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
</div>
<p class="ml-16 text-sm font-medium text-gray-500 truncate">Network Sols/Sec</p>
</dt>
<dd class="ml-16 pb-6 flex items-baseline sm:pb-7">
<%= live_render(@conn, ZcashExplorerWeb.NetworkSolpsLive) %>
<div class="absolute bottom-0 inset-x-0 bg-gray-50 px-4 py-4 sm:px-6">
<div class="text-sm">
<a href="#" class="font-medium text-indigo-600 hover:text-indigo-500">View network info<span class="sr-only"> View network info</span></a>
</div>
</div>
</dd>
</div>
</dl>
</div>
@ -149,4 +103,4 @@
</h3>
<%= live_render(@conn, ZcashExplorerWeb.RecentTransactionsLive) %>
</div>
</div>
</div>

View File

@ -36,7 +36,7 @@
</dd>
</div>
<div class="sm:col-span-1">
<dt class="text-sm font-medium text-gray-500">
Tx Type
@ -122,16 +122,50 @@
</dt>
<dd class="mt-1 text-sm text-gray-900">
<%= @tx.locktime %>
</dd>
</div>
<div class="sm:col-span-1">
<dt class="text-sm font-medium text-gray-500">
Transaction fee
</dt>
<dd class="mt-1 text-sm text-gray-900">
<%= if ZcashExplorerWeb.BlockView.tx_type(@tx) == "coinbase" do %>
0.0 ZEC
<% end %>
<%= if ZcashExplorerWeb.BlockView.tx_type(@tx) == "transparent" do %>
<%= transparent_tx_fee(@tx) %>
<% end %>
<%= if ZcashExplorerWeb.BlockView.tx_type(@tx) == "shielded" do %>
<%= format_zec(get_shielded_pool_value(@tx)) %>
<% end %>
<%= if ZcashExplorerWeb.BlockView.tx_type(@tx) == "shielding" do %>
<%= shielding_tx_fee(@tx) %>
<% end %>
<%= if ZcashExplorerWeb.BlockView.tx_type(@tx) == "deshielding" do %>
<%= deshielding_tx_fees(@tx) %>
<% end %>
<%= if ZcashExplorerWeb.BlockView.tx_type(@tx) == "mixed" do %>
<%= mixed_tx_fees(@tx) %>
<% end %>
</dd>
</div>
</dl>
</div>
</div>
</section>
<h4 class="font-medium text-gray-900">
Public transfers
</h4>
</h4>
<div class="grid md:grid-cols-2 gap-4 sm:grid-cols-1 lg:grid-cols-9">
<div class="sm:col-span-9 md:col-span-9 lg:col-span-4">
Inputs (<%= vin_count(@tx.vin) %>)
@ -141,7 +175,7 @@ Inputs (<%= vin_count(@tx.vin) %>)
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 py-2">
<ul class="border border-gray-200 rounded-md divide-y divide-gray-200">
<%= for input <- @tx.vin do %>
<li class="pl-3 pr-4 py-3 flex items-center justify-between text-sm">
<div class="w-0 flex-1 flex items-center">
<a href='/address/<%= input.address %>'>
@ -154,7 +188,7 @@ Inputs (<%= vin_count(@tx.vin) %>)
<%= format_zec input.value %>
</div>
</li>
<% end %>
</ul>
</dd>
@ -179,7 +213,7 @@ Inputs (<%= vin_count(@tx.vin) %>)
</div>
</div>
<div class="lg:col-span-1 justify-self-center py-4">
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="arrow-right" class="h-5 w-5" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
<path fill="currentColor" d="M190.5 66.9l22.2-22.2c9.4-9.4 24.6-9.4 33.9 0L441 239c9.4 9.4 9.4 24.6 0 33.9L246.6 467.3c-9.4 9.4-24.6 9.4-33.9 0l-22.2-22.2c-9.5-9.5-9.3-25 .4-34.3L311.4 296H24c-13.3 0-24-10.7-24-24v-32c0-13.3 10.7-24 24-24h287.4L190.9 101.2c-9.8-9.3-10-24.8-.4-34.3z"></path></svg>
@ -195,7 +229,7 @@ Outputs (<%= vout_count(@tx.vout) %>)
<ul class="border border-gray-200 rounded-md divide-y divide-gray-200">
<%= for op <- @tx.vout do %>
<%= for address <- op.scriptPubKey.addresses do %>
<li class="pl-2 pr-4 py-3 flex items-center justify-between text-sm">
<a href='/address/<%= address %>'>
<div class="w-0 flex-1 flex items-center">
@ -208,7 +242,7 @@ Outputs (<%= vout_count(@tx.vout) %>)
<%= format_zec op.value %>
</div>
</li>
<% end %>
<% end %>
</ul>
@ -240,7 +274,7 @@ Shielded transfers
<div class="bg-white p-6">
<div class="sm:flex sm:items-center sm:justify-between">
<div class="sm:flex sm:space-x-5">
<dl class="grid grid-cols-3 gap-x-4 gap-y-8 sm:grid-cols-6">
@ -260,8 +294,8 @@ Shielded transfers
</dt>
<dd class="mt-1 text-sm text-gray-900 break-words">
<%= if ZcashExplorerWeb.BlockView.contains_sprout(@tx) do %>
Yes -
<%= ZcashExplorerWeb.BlockView.get_joinsplit_count(@tx) %> JoinSplits
Yes -
<%= ZcashExplorerWeb.BlockView.get_joinsplit_count(@tx) %>
<% else %>
No
<% end %>
@ -288,4 +322,4 @@ Shielded transfers
</div>
</div>
</main>
</main>

View File

@ -1,7 +1,6 @@
defmodule ZcashExplorerWeb.BlockView do
use ZcashExplorerWeb, :view
def mined_time(nil) do
"Not yet mined"
end

View File

@ -2,7 +2,7 @@ defmodule ZcashExplorerWeb.PageView do
use ZcashExplorerWeb, :view
def price() do
{:ok, price } = Cachex.get(:price_cache, "price")
price
{:ok, price} = Cachex.get(:price_cache, "price")
price
end
end

View File

@ -24,22 +24,19 @@ defmodule ZcashExplorerWeb.TransactionView do
""
end
# functions to get the label for
# functions to get the label for
# shielding tx without vjoinsplit
def get_shielded_pool_label(tx)
when
tx.vjoinsplit != nil
and length(tx.vjoinsplit) == 0
and length(tx.vin) > 0
and length(tx.vout) == 0
and length(tx.vShieldedOutput) > 0
and (tx.valueBalance) < 0.0
do
IO.inspect("38")
when tx.vjoinsplit != nil and
length(tx.vjoinsplit) == 0 and
length(tx.vin) > 0 and
length(tx.vout) == 0 and
length(tx.vShieldedOutput) > 0 and
tx.valueBalance < 0.0 do
IO.inspect("38")
"Transferred to shielded pool"
end
# handle when vjoinsplit is present ( indicated legacy transaction)
# 1
def get_shielded_pool_label(tx)
@ -48,28 +45,24 @@ defmodule ZcashExplorerWeb.TransactionView do
"Transferred to shielded pool"
end
# handle when and vjoinsplit is present and vin == 0 ..
# handle when and vjoinsplit is present and vin == 0 ..
def get_shielded_pool_label(tx)
when tx.vjoinsplit != nil and length(tx.vjoinsplit) > 0 and length(tx.vin) == 0 do
IO.inspect("54")
IO.inspect("")
"Transferred from shielded pool"
end
# handle mixed tx
# handle mixed tx
def get_shielded_pool_label(tx)
when
tx.vjoinsplit != nil
and length(tx.vjoinsplit) == 0
and length(tx.vin) > 0
and length(tx.vShieldedOutput) > 0
and tx.valueBalance < 0.0
do
IO.inspect("68")
when tx.vjoinsplit != nil and
length(tx.vjoinsplit) == 0 and
length(tx.vin) > 0 and
length(tx.vShieldedOutput) > 0 and
tx.valueBalance < 0.0 do
IO.inspect("68")
"Transferred to shielded pool"
end
# handle public tx
def get_shielded_pool_label(tx)
when tx.vjoinsplit != nil and length(tx.vjoinsplit) == 0 and length(tx.vin) > 0 do
@ -77,8 +70,7 @@ defmodule ZcashExplorerWeb.TransactionView do
"Transferred from/to shielded pool"
end
# 3 with value balance
# 3 with value balance
def get_shielded_pool_label(tx)
when tx.vjoinsplit != nil and length(tx.vjoinsplit) == 0 and length(tx.vin) == 0 and
length(tx.vout) > 0 and tx.valueBalance > 0 do
@ -90,120 +82,151 @@ defmodule ZcashExplorerWeb.TransactionView do
def get_shielded_pool_label(tx)
when tx.vjoinsplit != nil and length(tx.vjoinsplit) == 0 and length(tx.vin) == 0 and
length(tx.vout) == 0 and tx.valueBalance > 0 do
IO.inspect("93")
IO.inspect("93")
"Transferred from shielded pool"
end
# mixed
def get_shielded_pool_value(tx)
when
tx.vjoinsplit != nil
and length(tx.vjoinsplit) == 0
and length(tx.vin) > 0
and length(tx.vShieldedOutput) > 0
and tx.valueBalance < 0.0
do
abs(tx.valueBalance)
# mixed
def get_shielded_pool_value(tx)
when tx.vjoinsplit != nil and
length(tx.vjoinsplit) == 0 and
length(tx.vin) > 0 and
length(tx.vShieldedOutput) > 0 and
tx.valueBalance < 0.0 do
abs(tx.valueBalance)
end
def get_shielded_pool_value(tx)
when
tx.vjoinsplit != nil
and length(tx.vjoinsplit) == 0
and length(tx.vin) > 0
and length(tx.vout) == 0
and length(tx.vShieldedOutput) > 0
and (tx.valueBalance) < 0.0
do
abs(tx.valueBalance)
def get_shielded_pool_value(tx)
when tx.vjoinsplit != nil and
length(tx.vjoinsplit) == 0 and
length(tx.vin) > 0 and
length(tx.vout) == 0 and
length(tx.vShieldedOutput) > 0 and
tx.valueBalance < 0.0 do
abs(tx.valueBalance)
end
# 1
def get_shielded_pool_value(tx)
when
tx.vjoinsplit != nil
and length(tx.vjoinsplit) > 0
and length(tx.vin) > 0 do
when tx.vjoinsplit != nil and
length(tx.vjoinsplit) > 0 and
length(tx.vin) > 0 do
Map.get(tx, :vjoinsplit) |> Enum.reduce(0, fn x, acc -> Map.get(x, :vpub_old) + acc end)
end
# 3
# 3
def get_shielded_pool_value(tx)
when
tx.vjoinsplit != nil
and length(tx.vjoinsplit) == 0
and length(tx.vin) == 0
and length(tx.vout) > 0
and tx.valueBalance > 0 do
when tx.vjoinsplit != nil and
length(tx.vjoinsplit) == 0 and
length(tx.vin) == 0 and
length(tx.vout) > 0 and
tx.valueBalance > 0 do
abs(tx.valueBalance)
end
# 4
# 4
def get_shielded_pool_value(tx)
when
tx.vjoinsplit != nil
and length(tx.vjoinsplit) > 0
and length(tx.vin) == 0
and length(tx.vout) == 0
do
val = tx
|> Map.get(:vjoinsplit)
|> List.flatten()
|> Enum.reduce(0, fn x, acc -> Map.get(x, :vpub_new) + acc end)
|> Kernel.+(0.0)
when tx.vjoinsplit != nil and
length(tx.vjoinsplit) > 0 and
length(tx.vin) == 0 and
length(tx.vout) == 0 do
val =
tx
|> Map.get(:vjoinsplit)
|> List.flatten()
|> Enum.reduce(0, fn x, acc -> Map.get(x, :vpub_new) + acc end)
|> Kernel.+(0.0)
abs(val)
end
# 4
# 4 Deshielding legacy
def get_shielded_pool_value(tx)
when
tx.vjoinsplit != nil
and length(tx.vjoinsplit) > 0
and length(tx.vin) == 0
and length(tx.vout) > 0
do
val = tx
|> Map.get(:vout)
|> List.flatten()
|> Enum.reduce(0, fn x, acc -> Map.get(x, :value) + acc end)
|> Kernel.+(0.0)
when tx.vjoinsplit != nil and
length(tx.vjoinsplit) > 0 and
length(tx.vin) == 0 and
length(tx.vout) > 0 do
IO.inspect(177)
val =
tx
|> Map.get(:vjoinsplit)
|> List.flatten()
|> Enum.reduce(0, fn x, acc -> Map.get(x, :vpub_new) + acc end)
|> Kernel.+(0.0)
abs(val)
end
# 4
# 4
def get_shielded_pool_value(tx)
when
tx.vjoinsplit != nil
and length(tx.vjoinsplit) == 0
and length(tx.vin) == 0
and length(tx.vout) == 0
and tx.valueBalance > 0 do
when tx.vjoinsplit != nil and
length(tx.vjoinsplit) == 0 and
length(tx.vin) == 0 and
length(tx.vout) == 0 and
tx.valueBalance > 0 do
abs(tx.valueBalance)
end
# handle public tx
def get_shielded_pool_value(tx)
when
tx.vjoinsplit != nil
and length(tx.vjoinsplit) == 0
and length(tx.vin) > 0 do
when tx.vjoinsplit != nil and
length(tx.vjoinsplit) == 0 and
length(tx.vin) > 0 do
0.00
end
def tx_in_total(tx) when is_map(tx) do
IO.inspect(tx.vin)
tx.vin |> Enum.reduce(0, fn x, acc -> x.value + acc end)
end
def tx_out_total(tx) when is_map(tx) do
tx.vout |> Enum.reduce(0, fn x, acc -> x.value + acc end)
end
def transparent_tx_fee(public_tx) do
fee = tx_in_total(public_tx) - tx_out_total(public_tx)
fee |> format_zec()
end
def vjoinsplit_vpub_old_total(tx) when is_map(tx) do
tx.vjoinsplit |> Enum.reduce(0, fn x, acc -> x.vpub_old + acc end)
end
def vjoinsplit_vpub_new_total(tx) when is_map(tx) do
tx.vjoinsplit |> Enum.reduce(0, fn x, acc -> x.vpub_new + acc end)
end
def shielding_tx_fee(tx) when is_map(tx) and length(tx.vjoinsplit) > 0 do
fee = tx_in_total(tx) - vjoinsplit_vpub_old_total(tx)
fee |> format_zec()
end
def shielding_tx_fee(tx) when is_map(tx) and length(tx.vjoinsplit) == 0 do
fee = tx_in_total(tx) - abs(tx.valueBalance)
fee |> format_zec()
end
def deshielding_tx_fees(tx) when is_map(tx) and length(tx.vjoinsplit) > 0 do
fee = vjoinsplit_vpub_new_total(tx) - tx_out_total(tx)
fee |> format_zec()
end
def deshielding_tx_fees(tx) when is_map(tx) and length(tx.vjoinsplit) == 0 do
fee = tx.valueBalance - tx_out_total(tx)
fee |> format_zec()
end
def mixed_tx_fees(tx)
when is_map(tx) and
length(tx.vjoinsplit) == 0 and
length(tx.vShieldedOutput) > 0 and
length(tx.vShieldedSpend) == 0 and
tx.valueBalance < 0 and
length(tx.vin) > 0 and
length(tx.vout) > 0 do
fee = tx_in_total(tx) - abs(tx.valueBalance) - tx_out_total(tx)
fee |> format_zec()
end
end