Added TX Fee
This commit is contained in:
parent
1218aa988e
commit
14aec95a40
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -122,6 +122,40 @@
|
|||
</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>
|
||||
|
@ -261,7 +295,7 @@ Shielded transfers
|
|||
<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
|
||||
<%= ZcashExplorerWeb.BlockView.get_joinsplit_count(@tx) %>
|
||||
<% else %>
|
||||
No
|
||||
<% end %>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
defmodule ZcashExplorerWeb.BlockView do
|
||||
use ZcashExplorerWeb, :view
|
||||
|
||||
|
||||
def mined_time(nil) do
|
||||
"Not yet mined"
|
||||
end
|
||||
|
|
|
@ -27,19 +27,16 @@ defmodule ZcashExplorerWeb.TransactionView do
|
|||
# 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
|
||||
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)
|
||||
|
@ -51,25 +48,21 @@ defmodule ZcashExplorerWeb.TransactionView do
|
|||
# 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
|
||||
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
|
||||
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,7 +70,6 @@ defmodule ZcashExplorerWeb.TransactionView do
|
|||
"Transferred from/to shielded pool"
|
||||
end
|
||||
|
||||
|
||||
# 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
|
||||
|
@ -94,116 +86,147 @@ defmodule ZcashExplorerWeb.TransactionView do
|
|||
"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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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(:vout)
|
||||
val =
|
||||
tx
|
||||
|> Map.get(:vjoinsplit)
|
||||
|> List.flatten()
|
||||
|> Enum.reduce(0, fn x, acc -> Map.get(x, :value) + acc end)
|
||||
|> Enum.reduce(0, fn x, acc -> Map.get(x, :vpub_new) + acc end)
|
||||
|> Kernel.+(0.0)
|
||||
|
||||
abs(val)
|
||||
end
|
||||
|
||||
|
||||
|
||||
# 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
|
||||
|
|
Loading…
Reference in New Issue