From aea6d78f32a446a1685cc8b4f957eef1c5808196 Mon Sep 17 00:00:00 2001 From: Vamsi Krishna B Date: Tue, 28 Mar 2023 11:43:23 +0530 Subject: [PATCH] Fixed TX type label and fees for V5 --- .../controllers/transaction_controller.ex | 2 +- lib/zcash_explorer_web/views/block_view.ex | 19 +++++--- .../views/transaction_view.ex | 45 +++++++++++-------- 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/lib/zcash_explorer_web/controllers/transaction_controller.ex b/lib/zcash_explorer_web/controllers/transaction_controller.ex index a894cc2..7c1ccdf 100644 --- a/lib/zcash_explorer_web/controllers/transaction_controller.ex +++ b/lib/zcash_explorer_web/controllers/transaction_controller.ex @@ -4,7 +4,7 @@ defmodule ZcashExplorerWeb.TransactionController do def get_transaction(conn, %{"txid" => txid}) do {:ok, tx} = Zcashex.getrawtransaction(txid, 1) 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}") end diff --git a/lib/zcash_explorer_web/views/block_view.ex b/lib/zcash_explorer_web/views/block_view.ex index e19c993..c007469 100644 --- a/lib/zcash_explorer_web/views/block_view.ex +++ b/lib/zcash_explorer_web/views/block_view.ex @@ -1,4 +1,5 @@ defmodule ZcashExplorerWeb.BlockView do + alias ZcashExplorerWeb.TransactionView use ZcashExplorerWeb, :view def mined_time(nil) do @@ -97,7 +98,7 @@ defmodule ZcashExplorerWeb.BlockView do end # detect if a transaction is Public - # https://z.cash/technology/ + # https://z.cash/technology/ def transparent_in_and_out(tx) do length(tx.vin) > 0 and length(tx.vout) > 0 end @@ -106,6 +107,10 @@ defmodule ZcashExplorerWeb.BlockView do length(tx.vjoinsplit) > 0 end + def contains_orchard(tx) do + TransactionView.orchard_actions(tx) > 0 + end + def get_joinsplit_count(tx) do length(tx.vjoinsplit) end @@ -118,7 +123,8 @@ defmodule ZcashExplorerWeb.BlockView do end 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 def is_transparent_tx?(tx) do @@ -132,20 +138,22 @@ defmodule ZcashExplorerWeb.BlockView do def is_mixed_tx?(tx) do 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 def is_shielding(tx) do 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 def is_deshielding(tx) do 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 def tx_type(tx) do + IO.inspect(tx) + cond do is_coinbase_tx?(tx) -> "coinbase" @@ -167,5 +175,4 @@ defmodule ZcashExplorerWeb.BlockView do "unknown" end end - end diff --git a/lib/zcash_explorer_web/views/transaction_view.ex b/lib/zcash_explorer_web/views/transaction_view.ex index 4e1fb0d..718e7c0 100644 --- a/lib/zcash_explorer_web/views/transaction_view.ex +++ b/lib/zcash_explorer_web/views/transaction_view.ex @@ -15,27 +15,20 @@ defmodule ZcashExplorerWeb.TransactionView do length(vout) end + def format_zec(value) when value == nil do + "" + end + def format_zec(value) when value != nil do float_value = (value + 0.0) |> :erlang.float_to_binary([:compact, {:decimals, 10}]) float_value <> " " <> "ZEC" 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 - 0 - end - - def format_zec(value) when value == nil do - "" + case tx do + %{orchard: %{actions: actions}} when is_list(actions) -> length(actions) + _ -> 0 + end end def get_shielded_pool_label(tx) @@ -184,7 +177,7 @@ defmodule ZcashExplorerWeb.TransactionView do tx.orchard.valueBalance end - # + # def get_shielded_pool_value(tx) when tx.vjoinsplit != nil and length(tx.vjoinsplit) == 0 and @@ -197,7 +190,7 @@ defmodule ZcashExplorerWeb.TransactionView do 0 end - # + # def get_shielded_pool_value(tx) when tx.vjoinsplit != nil and length(tx.vjoinsplit) == 0 and @@ -335,21 +328,35 @@ defmodule ZcashExplorerWeb.TransactionView do fee |> format_zec() 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 |> format_zec() 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 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 + 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 |> format_zec() 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 def unknown_tx_fees(tx) when tx.vjoinsplit != nil and