Decode Coinbase hex
This commit is contained in:
parent
aea6d78f32
commit
b63ae583e9
|
@ -263,10 +263,22 @@
|
||||||
</dd>
|
</dd>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= if ZcashExplorerWeb.BlockView.tx_type(@tx) == "coinbase" do %>
|
<%= if ZcashExplorerWeb.BlockView.tx_type(@tx) == "coinbase" do %>
|
||||||
|
|
||||||
<div class="py-4">
|
<div class="py-4">
|
||||||
|
|
||||||
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-s font-medium bg-yellow-400 text-gray-900 capitalize">
|
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-s font-medium bg-yellow-400 text-gray-900 capitalize">
|
||||||
💰 Coinbase
|
💰 Coinbase
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
<%= if String.length(ZcashExplorerWeb.BlockView.get_coinbase_hex(@tx)) > 5 do %>
|
||||||
|
<span class="inline-block bg-sky-100 px-2.5 font-bold text-sm text-slate-900 font-mono rounded dark:bg-slate-600 dark:text-slate-200 br">
|
||||||
|
<%= ZcashExplorerWeb.BlockView.get_coinbase_hex(@tx) %>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= if ZcashExplorerWeb.BlockView.tx_type(@tx) == "deshielding" do %>
|
<%= if ZcashExplorerWeb.BlockView.tx_type(@tx) == "deshielding" do %>
|
||||||
|
|
|
@ -46,6 +46,27 @@ defmodule ZcashExplorerWeb.BlockView do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_coinbase_hex(tx) do
|
||||||
|
tx
|
||||||
|
|> Map.get(:vin)
|
||||||
|
|> List.first()
|
||||||
|
|> Map.get(:coinbase)
|
||||||
|
|> decode_coinbase_tx_hex()
|
||||||
|
|
||||||
|
# |> String.normalize(:nfkc)
|
||||||
|
end
|
||||||
|
|
||||||
|
def decode_coinbase_tx_hex(coinbase_hex)
|
||||||
|
when is_binary(coinbase_hex) do
|
||||||
|
try do
|
||||||
|
coinbase_binary = Base.decode16!(coinbase_hex, case: :mixed)
|
||||||
|
coinbase_list = :erlang.binary_to_list(coinbase_binary)
|
||||||
|
List.to_string(coinbase_list) |> IO.inspect(charlists: :as_charlists)
|
||||||
|
rescue
|
||||||
|
_e in ArgumentError -> "unable to decode coinbase hex"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def mined_by(txs) do
|
def mined_by(txs) do
|
||||||
first_trx = txs |> List.first()
|
first_trx = txs |> List.first()
|
||||||
|
|
||||||
|
@ -152,8 +173,6 @@ defmodule ZcashExplorerWeb.BlockView do
|
||||||
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"
|
||||||
|
|
Loading…
Reference in New Issue