From 15558c60b591b7edfe04471f7a1fc9de6868246f Mon Sep 17 00:00:00 2001 From: Rogerio Pontual Date: Tue, 5 Sep 2023 10:10:45 +0200 Subject: [PATCH] chore: add allowance and approval events --- lib/ae_mdw/node.ex | 44 ++++++++++++------- lib/ae_mdw_web/views/logs_view.ex | 14 ++++++ test/ae_mdw_web/views/logs_view_test.exs | 6 +++ .../ae_mdw/node/aexn_event_fixtures.ex | 44 +++++++++++-------- 4 files changed, 73 insertions(+), 35 deletions(-) diff --git a/lib/ae_mdw/node.ex b/lib/ae_mdw/node.ex index 88fc2ade6..775a2784e 100644 --- a/lib/ae_mdw/node.ex +++ b/lib/ae_mdw/node.ex @@ -47,7 +47,10 @@ defmodule AeMdw.Node do @opaque aect_call :: tuple() @type aexn_event_type :: - :burn + :allowance + | :approval + | :approval_for_all + | :burn | :mint | :swap | :edition_limit @@ -84,21 +87,30 @@ defmodule AeMdw.Node do @spec aexn_event_hash_types() :: %{Contracts.event_hash() => aexn_event_type()} def aexn_event_hash_types() do - %{ - :aec_hash.blake2b_256_hash("Burn") => :burn, - :aec_hash.blake2b_256_hash("Mint") => :mint, - :aec_hash.blake2b_256_hash("Swap") => :swap, - :aec_hash.blake2b_256_hash("EditionLimit") => :edition_limit, - :aec_hash.blake2b_256_hash("EditionLimitDecrease") => :edition_limit_decrease, - :aec_hash.blake2b_256_hash("TemplateCreation") => :template_creation, - :aec_hash.blake2b_256_hash("TemplateDeletion") => :template_deletion, - :aec_hash.blake2b_256_hash("TemplateMint") => :template_mint, - :aec_hash.blake2b_256_hash("TemplateLimit") => :template_limit, - :aec_hash.blake2b_256_hash("TemplateLimitDecrease") => :template_limit_decrease, - :aec_hash.blake2b_256_hash("TokenLimit") => :token_limit, - :aec_hash.blake2b_256_hash("TokenLimitDecrease") => :token_limit_decrease, - :aec_hash.blake2b_256_hash("Transfer") => :transfer - } + Map.new( + [ + :allowance, + :approval, + :approval_for_all, + :burn, + :mint, + :swap, + :edition_limit, + :edition_limit_decrease, + :template_creation, + :template_deletion, + :template_mint, + :template_limit, + :template_limit_decrease, + :token_limit, + :token_limit_decrease, + :transfer + ], + fn event_type -> + event_name = event_type |> to_string() |> Macro.camelize() + {:aec_hash.blake2b_256_hash(event_name), event_type} + end + ) end @spec aexn_event_names() :: %{Contracts.event_hash() => AexnContracts.event_name()} diff --git a/lib/ae_mdw_web/views/logs_view.ex b/lib/ae_mdw_web/views/logs_view.ex index e8dd26992..10f0ffd31 100644 --- a/lib/ae_mdw_web/views/logs_view.ex +++ b/lib/ae_mdw_web/views/logs_view.ex @@ -86,6 +86,20 @@ defmodule AeMdwWeb.LogsView do if String.valid?(data), do: data, else: Base.encode64(data) end + defp format_args("Allowance", [account1, account2, <>], %{aexn_args: true}) do + [encode_account(account1), encode_account(account2), amount] + end + + defp format_args("Approval", [account1, account2, <>, enable], %{aexn_args: true}) + when enable in ["true", "false"] do + [encode_account(account1), encode_account(account2), token_id, enable] + end + + defp format_args("ApprovalForAll", [account1, account2, enable], %{aexn_args: true}) + when enable in ["true", "false"] do + [encode_account(account1), encode_account(account2), enable] + end + defp format_args(event_name, [account, <>], %{aexn_args: true}) when event_name in ["Burn", "Mint", "Swap"] do [encode_account(account), token_id] diff --git a/test/ae_mdw_web/views/logs_view_test.exs b/test/ae_mdw_web/views/logs_view_test.exs index a2ffb7079..93a2ddb92 100644 --- a/test/ae_mdw_web/views/logs_view_test.exs +++ b/test/ae_mdw_web/views/logs_view_test.exs @@ -29,6 +29,9 @@ defmodule AeMdwWeb.LogsViewTest do account2_pk = :crypto.strong_rand_bytes(32) tokens = %{ + "Allowance" => Enum.random(100..999), + "Approval" => Enum.random(100..999), + "ApprovalForAll" => Enum.random(100..999), "Burn" => Enum.random(100..999), "Mint" => Enum.random(100..999), "Swap" => Enum.random(100..999), @@ -37,6 +40,7 @@ defmodule AeMdwWeb.LogsViewTest do } aex9_event_args = %{ + allowance: [account1_pk, account2_pk, <>], burn: [account1_pk, <>], mint: [account1_pk, <>], swap: [account1_pk, <>], @@ -57,6 +61,8 @@ defmodule AeMdwWeb.LogsViewTest do } aex141_event_args = %{ + approval: [account1_pk, account2_pk, <>, "true"], + approval_for_all: [account1_pk, account2_pk, "true"], burn: [account1_pk, <>], mint: [account1_pk, <>], transfer: [account1_pk, account2_pk, <>], diff --git a/test/support/ae_mdw/node/aexn_event_fixtures.ex b/test/support/ae_mdw/node/aexn_event_fixtures.ex index b3c018750..9d1917bd0 100644 --- a/test/support/ae_mdw/node/aexn_event_fixtures.ex +++ b/test/support/ae_mdw/node/aexn_event_fixtures.ex @@ -4,24 +4,30 @@ defmodule AeMdw.Node.AexnEventFixtures do @type aexn_event_type :: AeMdw.Node.aexn_event_type() @type event_hash :: AeMdw.Node.event_hash() - @spec aexn_event_hash(aexn_event_type()) :: [event_hash()] - def aexn_event_hash(:burn), do: :aec_hash.blake2b_256_hash("Burn") - def aexn_event_hash(:edition_limit), do: :aec_hash.blake2b_256_hash("EditionLimit") - - def aexn_event_hash(:edition_limit_decrease), - do: :aec_hash.blake2b_256_hash("EditionLimitDecrease") - - def aexn_event_hash(:mint), do: :aec_hash.blake2b_256_hash("Mint") - def aexn_event_hash(:swap), do: :aec_hash.blake2b_256_hash("Swap") - def aexn_event_hash(:transfer), do: :aec_hash.blake2b_256_hash("Transfer") - def aexn_event_hash(:template_creation), do: :aec_hash.blake2b_256_hash("TemplateCreation") - def aexn_event_hash(:template_deletion), do: :aec_hash.blake2b_256_hash("TemplateDeletion") - def aexn_event_hash(:template_mint), do: :aec_hash.blake2b_256_hash("TemplateMint") - def aexn_event_hash(:template_limit), do: :aec_hash.blake2b_256_hash("TemplateLimit") + @event_types [ + :allowance, + :approval, + :approval_for_all, + :burn, + :mint, + :swap, + :edition_limit, + :edition_limit_decrease, + :template_creation, + :template_deletion, + :template_mint, + :template_limit, + :template_limit_decrease, + :token_limit, + :token_limit_decrease, + :transfer + ] - def aexn_event_hash(:template_limit_decrease), - do: :aec_hash.blake2b_256_hash("TemplateLimitDecrease") - - def aexn_event_hash(:token_limit), do: :aec_hash.blake2b_256_hash("TokenLimit") - def aexn_event_hash(:token_limit_decrease), do: :aec_hash.blake2b_256_hash("TokenLimitDecrease") + @spec aexn_event_hash(aexn_event_type()) :: [event_hash()] + def aexn_event_hash(event_type) when event_type in @event_types do + event_type + |> to_string() + |> Macro.camelize() + |> :aec_hash.blake2b_256_hash() + end end