Skip to content

Commit

Permalink
review feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
tenmoves committed Jan 27, 2023
1 parent 8e1a216 commit 3836a48
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
8 changes: 0 additions & 8 deletions lib/archethic/contracts/interpreter/condition.ex
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,6 @@ defmodule Archethic.Contracts.ConditionInterpreter do
{node, acc}
end

# Whitelist the get_token_id/1 function in the condition
defp prewalk(
node = {{:atom, "get_token_id"}, _, [_search]},
acc = {:ok, %{scope: {:condition, _, _}}}
) do
{node, acc}
end

# Whitelist the hash/0 function in the condition
defp prewalk(
node = {{:atom, "hash"}, _, []},
Expand Down
7 changes: 3 additions & 4 deletions lib/archethic/contracts/interpreter/library.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ defmodule Archethic.Contracts.Interpreter.Library do
Contracts.Interpreter.Utils
}

alias Archethic.Utils

require Logger

@doc """
Expand Down Expand Up @@ -237,12 +235,13 @@ defmodule Archethic.Contracts.Interpreter.Library do
"""
@spec get_token_id(binary()) :: {:error, binary()} | {:ok, binary()}
def get_token_id(address) do
address = Utils.maybe_decode_hex(address)
t1 = Task.async(fn -> Archethic.fetch_genesis_address_remotely(address) end)
t2 = Task.async(fn -> Utils.get_transaction_content(address) end)
t2 = Task.async(fn -> Archethic.Utils.get_transaction_content(address) end)

with {:ok, {:ok, genesis_address}} <- Task.yield(t1),
{:ok, {:ok, definition}} <- Task.yield(t2) do
Utils.get_token_id(genesis_address, definition)
Archethic.Utils.get_token_id(genesis_address, definition)
else
{:ok, {:error, :network_issue}} ->
{:error, "Network issue"}
Expand Down
2 changes: 1 addition & 1 deletion lib/archethic/contracts/interpreter/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ defmodule Archethic.Contracts.Interpreter.Utils do
{node, acc}
end

# Whitelist the get_token_id/0 function
# Whitelist the get_token_id/1 function
def prewalk(
node = {{:atom, "get_token_id"}, _, [_address]},
acc = {:ok, %{scope: scope}}
Expand Down
6 changes: 3 additions & 3 deletions test/archethic/contracts/interpreter/library_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ defmodule Archethic.Contracts.Interpreter.LibraryTest do

alias Archethic.Contracts.Interpreter.Library

alias P2P.Message.GetFirstTransactionAddress
alias P2P.Message.FirstTransactionAddress
alias Archethic.P2P.Message.GetFirstTransactionAddress
alias Archethic.P2P.Message.FirstTransactionAddress

alias Archethic.TransactionChain.Transaction
alias Archethic.TransactionChain.TransactionData
Expand Down Expand Up @@ -53,7 +53,7 @@ defmodule Archethic.Contracts.Interpreter.LibraryTest do
|> Jason.decode!()

MockDB
|> stub(:get_transaction, fn _, _ -> {:ok, tx} end)
|> stub(:get_transaction, fn _, _, _ -> {:ok, tx} end)
|> stub(:get_genesis_address, fn _ -> genesis_address end)

assert Utils.get_token_id(genesis_address, transaction_content) ==
Expand Down

0 comments on commit 3836a48

Please sign in to comment.