Skip to content

Commit

Permalink
fix: render sext encoded log (#1579)
Browse files Browse the repository at this point in the history
  • Loading branch information
jyeshe authored Sep 6, 2023
1 parent 121cd28 commit 798a523
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/ae_mdw_web/views/logs_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule AeMdwWeb.LogsView do
@type opts :: %{aexn_args: boolean(), custom_args: boolean()}

@spec render_log(State.t(), AeMdw.Contracts.log(), opts()) :: map()
def render_log(state, {create_txi, call_txi, log_idx}, encode_args) do
def render_log(state, {create_txi, call_txi, log_idx} = index, encode_args) do
{contract_tx_hash, ct_pk} =
if create_txi == -1 do
{nil, Origin.pubkey(state, {:contract_call, call_txi})}
Expand All @@ -28,7 +28,7 @@ defmodule AeMdwWeb.LogsView do
Model.block(hash: block_hash) = DBUtil.read_block!(state, {height, micro_index})

Model.contract_log(args: args, data: data, ext_contract: ext_contract, hash: event_hash) =
State.fetch!(state, Model.ContractLog, {create_txi, call_txi, log_idx})
read_log(state, index)

event_name = AexnContracts.event_name(event_hash) || get_custom_event_name(event_hash)

Expand Down Expand Up @@ -155,4 +155,21 @@ defmodule AeMdwWeb.LogsView do
defp get_custom_event_name(event_hash) do
:persistent_term.get({__MODULE__, event_hash}, nil)
end

defp read_log(state, index) do
table = Model.ContractLog

try do
State.fetch!(state, table, index)
rescue
ArgumentError ->
{:ok, value} = AeMdw.Db.RocksDb.get(table, :sext.encode(index))
record_type = Model.record(table)

value
|> :sext.decode()
|> Tuple.insert_at(0, index)
|> Tuple.insert_at(0, record_type)
end
end
end

0 comments on commit 798a523

Please sign in to comment.