Fixed TX type label and fees for V5
This commit is contained in:
parent
283c034ea6
commit
aea6d78f32
|
@ -4,7 +4,7 @@ defmodule ZcashExplorerWeb.TransactionController do
|
||||||
def get_transaction(conn, %{"txid" => txid}) do
|
def get_transaction(conn, %{"txid" => txid}) do
|
||||||
{:ok, tx} = Zcashex.getrawtransaction(txid, 1)
|
{:ok, tx} = Zcashex.getrawtransaction(txid, 1)
|
||||||
tx_data = Zcashex.Transaction.from_map(tx)
|
tx_data = Zcashex.Transaction.from_map(tx)
|
||||||
IO.inspect(tx_data |> Map.delete(:hex))
|
# IO.inspect(tx_data |> Map.delete(:hex))
|
||||||
render(conn, "tx.html", tx: tx_data, page_title: "Zcash Transaction #{txid}")
|
render(conn, "tx.html", tx: tx_data, page_title: "Zcash Transaction #{txid}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
defmodule ZcashExplorerWeb.BlockView do
|
defmodule ZcashExplorerWeb.BlockView do
|
||||||
|
alias ZcashExplorerWeb.TransactionView
|
||||||
use ZcashExplorerWeb, :view
|
use ZcashExplorerWeb, :view
|
||||||
|
|
||||||
def mined_time(nil) do
|
def mined_time(nil) do
|
||||||
|
@ -106,6 +107,10 @@ defmodule ZcashExplorerWeb.BlockView do
|
||||||
length(tx.vjoinsplit) > 0
|
length(tx.vjoinsplit) > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def contains_orchard(tx) do
|
||||||
|
TransactionView.orchard_actions(tx) > 0
|
||||||
|
end
|
||||||
|
|
||||||
def get_joinsplit_count(tx) do
|
def get_joinsplit_count(tx) do
|
||||||
length(tx.vjoinsplit)
|
length(tx.vjoinsplit)
|
||||||
end
|
end
|
||||||
|
@ -118,7 +123,8 @@ defmodule ZcashExplorerWeb.BlockView do
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_shielded_tx?(tx) do
|
def is_shielded_tx?(tx) do
|
||||||
!transparent_in_and_out(tx) and (contains_sprout(tx) or contains_sapling(tx))
|
!transparent_in_and_out(tx) and
|
||||||
|
(contains_sprout(tx) or contains_sapling(tx) or contains_orchard(tx))
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_transparent_tx?(tx) do
|
def is_transparent_tx?(tx) do
|
||||||
|
@ -132,20 +138,22 @@ defmodule ZcashExplorerWeb.BlockView do
|
||||||
|
|
||||||
def is_mixed_tx?(tx) do
|
def is_mixed_tx?(tx) do
|
||||||
t_in_or_out = length(tx.vin) > 0 or length(tx.vout) > 0
|
t_in_or_out = length(tx.vin) > 0 or length(tx.vout) > 0
|
||||||
t_in_or_out and (contains_sprout(tx) || contains_sapling(tx))
|
t_in_or_out and (contains_sprout(tx) || contains_sapling(tx) || contains_orchard(tx))
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_shielding(tx) do
|
def is_shielding(tx) do
|
||||||
tin_and_zout = length(tx.vin) > 0 and length(tx.vout) == 0
|
tin_and_zout = length(tx.vin) > 0 and length(tx.vout) == 0
|
||||||
tin_and_zout and (contains_sprout(tx) || contains_sapling(tx))
|
tin_and_zout and (contains_sprout(tx) || contains_sapling(tx) || contains_orchard(tx))
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_deshielding(tx) do
|
def is_deshielding(tx) do
|
||||||
zin_and_tout = length(tx.vin) == 0 and length(tx.vout) > 0
|
zin_and_tout = length(tx.vin) == 0 and length(tx.vout) > 0
|
||||||
zin_and_tout and (contains_sprout(tx) || contains_sapling(tx))
|
zin_and_tout and (contains_sprout(tx) || contains_sapling(tx) || contains_orchard(tx))
|
||||||
end
|
end
|
||||||
|
|
||||||
def tx_type(tx) do
|
def tx_type(tx) do
|
||||||
|
IO.inspect(tx)
|
||||||
|
|
||||||
cond do
|
cond do
|
||||||
is_coinbase_tx?(tx) ->
|
is_coinbase_tx?(tx) ->
|
||||||
"coinbase"
|
"coinbase"
|
||||||
|
@ -167,5 +175,4 @@ defmodule ZcashExplorerWeb.BlockView do
|
||||||
"unknown"
|
"unknown"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,27 +15,20 @@ defmodule ZcashExplorerWeb.TransactionView do
|
||||||
length(vout)
|
length(vout)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def format_zec(value) when value == nil do
|
||||||
|
""
|
||||||
|
end
|
||||||
|
|
||||||
def format_zec(value) when value != nil do
|
def format_zec(value) when value != nil do
|
||||||
float_value = (value + 0.0) |> :erlang.float_to_binary([:compact, {:decimals, 10}])
|
float_value = (value + 0.0) |> :erlang.float_to_binary([:compact, {:decimals, 10}])
|
||||||
float_value <> " " <> "ZEC"
|
float_value <> " " <> "ZEC"
|
||||||
end
|
end
|
||||||
|
|
||||||
def orchard_actions(tx)
|
|
||||||
when tx.orchard.actions == nil do
|
|
||||||
0
|
|
||||||
end
|
|
||||||
|
|
||||||
def orchard_actions(tx)
|
|
||||||
when tx.orchard.actions != nil do
|
|
||||||
length(tx.orchard.actions)
|
|
||||||
end
|
|
||||||
|
|
||||||
def orchard_actions(tx) do
|
def orchard_actions(tx) do
|
||||||
0
|
case tx do
|
||||||
|
%{orchard: %{actions: actions}} when is_list(actions) -> length(actions)
|
||||||
|
_ -> 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_zec(value) when value == nil do
|
|
||||||
""
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_shielded_pool_label(tx)
|
def get_shielded_pool_label(tx)
|
||||||
|
@ -335,21 +328,35 @@ defmodule ZcashExplorerWeb.TransactionView do
|
||||||
fee |> format_zec()
|
fee |> format_zec()
|
||||||
end
|
end
|
||||||
|
|
||||||
def shielding_tx_fee(tx) when is_map(tx) and length(tx.vjoinsplit) == 0 do
|
def shielding_tx_fee(tx) when is_map(tx) and length(tx.vjoinsplit) == 0 and tx.version <= 4 do
|
||||||
fee = tx_in_total(tx) - abs(tx.valueBalance)
|
fee = tx_in_total(tx) - abs(tx.valueBalance)
|
||||||
fee |> format_zec()
|
fee |> format_zec()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# c7eb2ac6252fd266a74f5266ed9c1e585571ae941901480053f7886330829dea
|
||||||
|
def shielding_tx_fee(tx) when is_map(tx) and length(tx.vjoinsplit) == 0 and tx.version == 5 do
|
||||||
|
fee = tx_in_total(tx) - abs(tx.orchard.valueBalance)
|
||||||
|
fee |> format_zec()
|
||||||
|
end
|
||||||
|
|
||||||
def deshielding_tx_fees(tx) when is_map(tx) and length(tx.vjoinsplit) > 0 do
|
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 = vjoinsplit_vpub_new_total(tx) - tx_out_total(tx)
|
||||||
fee |> format_zec()
|
fee |> format_zec()
|
||||||
end
|
end
|
||||||
|
|
||||||
def deshielding_tx_fees(tx) when is_map(tx) and length(tx.vjoinsplit) == 0 do
|
def deshielding_tx_fees(tx)
|
||||||
|
when is_map(tx) and length(tx.vjoinsplit) == 0 and tx.version <= 4 do
|
||||||
fee = tx.valueBalance - tx_out_total(tx)
|
fee = tx.valueBalance - tx_out_total(tx)
|
||||||
fee |> format_zec()
|
fee |> format_zec()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 2e6b1180f806af3b4e0b51604a4b846f881db3801a410486269bfda5cb39c716
|
||||||
|
def deshielding_tx_fees(tx)
|
||||||
|
when is_map(tx) and length(tx.vjoinsplit) == 0 and tx.version == 5 do
|
||||||
|
fee = tx.orchard.valueBalance - tx_out_total(tx)
|
||||||
|
fee |> format_zec()
|
||||||
|
end
|
||||||
|
|
||||||
# e145617c5d7d1646674da1d36540faff8e548738c0f500857e3230b35e85ca5f
|
# e145617c5d7d1646674da1d36540faff8e548738c0f500857e3230b35e85ca5f
|
||||||
def unknown_tx_fees(tx)
|
def unknown_tx_fees(tx)
|
||||||
when tx.vjoinsplit != nil and
|
when tx.vjoinsplit != nil and
|
||||||
|
|
Loading…
Reference in New Issue