From c70da764a68d6beec0bbdcb2e5da52471d7a4c21 Mon Sep 17 00:00:00 2001 From: Imnik11 Date: Tue, 12 Apr 2022 13:56:26 +0530 Subject: [PATCH] Fix formatting --- .iex.exs | 41 +++++++++++++ config/dev.exs | 2 +- lib/archethic/contracts/interpreter.ex | 2 +- .../contracts/interpreter/library.ex | 3 +- lib/archethic/p2p/geo_patch.ex | 60 ++++++++++++------- 5 files changed, 85 insertions(+), 23 deletions(-) diff --git a/.iex.exs b/.iex.exs index 5e431646b..ace96f2e8 100644 --- a/.iex.exs +++ b/.iex.exs @@ -13,3 +13,44 @@ alias ArchEthic.TransactionChain alias ArchEthic.TransactionChain.Transaction alias ArchEthic.TransactionChain.TransactionData alias ArchEthic.BeaconChain +alias ArchEthic.Contracts.Interpreter +x = fn -> """ + + condition inherit: [ + + content: get_genesis_address(\"000000008CBF3D1FCE5D2E270738F3DF62D4A220E3C8D74964625BB219AD1936AD3A579B\"), + + origin_family: biometric + + ] + + actions triggered_by: datetime, at: 1601039923 do + + set_type hosting + + set_content \"Mr.X: 10, Mr.Y: 8\" + + end + +""" |> Contracts.parse!() end + +y = fn -> + +Interpreter.execute({{:., [line: 2], +[ + {:__aliases__, [alias: ArchEthic.Contracts.Interpreter.Library], + [:Library]}, + :get_genesis_address + ]}, [line: 2], +[{:get_in, [line: 2], [{:scope, [line: 2], nil}, ["content"]]}]}, %{ "content" => "000000008CBF3D1FCE5D2E270738F3DF62D4A220E3C8D74964625BB219AD1936AD3A579B" }) +end +z = fn -> + +Interpreter.execute({{:., [line: 2], +[ + {:__aliases__, [alias: ArchEthic.Contracts.Interpreter.Library], + [:Library]}, + :get_genesis_address + ]}, [line: 2], +[{:get_in, [line: 2], [{:scope, [line: 2], nil}, ["content"]]}]}, %{ "content" => "000000008CBF3D1FCE5D2E270738F3DF62D4A220E3C8D74964625BB219AD1936AD3A579B" }) +end diff --git a/config/dev.exs b/config/dev.exs index 5a04c68d5..b2d4958e6 100755 --- a/config/dev.exs +++ b/config/dev.exs @@ -1,6 +1,6 @@ import Config -config :logger, level: System.get_env("ARCHETHIC_LOGGER_LEVEL", "debug") |> String.to_atom() +config :logger, level: System.get_env("ARCHETHIC_LOGGER_LEVEL", "error") |> String.to_atom() config :archethic, :mut_dir, diff --git a/lib/archethic/contracts/interpreter.ex b/lib/archethic/contracts/interpreter.ex index 605fe6f5e..4b6043ae0 100644 --- a/lib/archethic/contracts/interpreter.ex +++ b/lib/archethic/contracts/interpreter.ex @@ -646,7 +646,7 @@ defmodule ArchEthic.Contracts.Interpreter do ) do {node, acc} end - + # Whitelist the used of functions in the actions defp prewalk(node = {{:atom, fun_name}, _, _}, {:ok, acc = %{scope: :actions}}) when fun_name in @transaction_statements_functions_names, diff --git a/lib/archethic/contracts/interpreter/library.ex b/lib/archethic/contracts/interpreter/library.ex index d3903843a..e844a81ae 100644 --- a/lib/archethic/contracts/interpreter/library.ex +++ b/lib/archethic/contracts/interpreter/library.ex @@ -170,7 +170,8 @@ defmodule ArchEthic.Contracts.Interpreter.Library do else [] -> {:error, :network_issue} -# TODO NotFound is not a valid behaviour of P2P GetFirstPublicKey need to address this issue after P2P GetFirstPublicKey + + # TODO NotFound is not a valid behaviour of P2P GetFirstPublicKey need to address this issue after P2P GetFirstPublicKey {:ok, %NotFound{}} -> address end diff --git a/lib/archethic/p2p/geo_patch.ex b/lib/archethic/p2p/geo_patch.ex index 1f02673b1..a737becf7 100755 --- a/lib/archethic/p2p/geo_patch.ex +++ b/lib/archethic/p2p/geo_patch.ex @@ -28,7 +28,21 @@ defmodule ArchEthic.P2P.GeoPatch do Enum.take_random(list_char, 3) |> List.to_string() end - defp compute_patch(lat, lon) do + def list_of_coordinates() do + l = for lat <- 0..90, do: for(lon <- 0..180, do: {lat, lon}) + + l = List.flatten(l) |> Enum.uniq() + + patches = + Enum.map(l, fn {x, y} -> + compute_patch(y, x) + end) + + patches |> Enum.to_list() |> Enum.uniq() + IO.inspect(patches) + end + + def compute_patch(lat, lon) do lat_sign = sign(lat) lon_sign = sign(lon) @@ -56,25 +70,31 @@ defmodule ArchEthic.P2P.GeoPatch do patch end - defp index_patch([f_i, s_i]) when f_i > 0.5 and f_i <= 1 and s_i < -0.5 and s_i >= -1, do: '0' - defp index_patch([f_i, s_i]) when f_i > 0.5 and f_i <= 1 and s_i < 0 and s_i >= -0.5, do: '1' - defp index_patch([f_i, s_i]) when f_i > 0.5 and f_i <= 1 and s_i < 0.5 and s_i >= 0, do: '2' - defp index_patch([f_i, s_i]) when f_i > 0.5 and f_i <= 1 and s_i < 1 and s_i >= 0.5, do: '3' - - defp index_patch([f_i, s_i]) when f_i > 0 and f_i <= 0.5 and s_i < -0.5 and s_i >= -1, do: '4' - defp index_patch([f_i, s_i]) when f_i > 0 and f_i <= 0.5 and s_i < 0 and s_i >= -0.5, do: '5' - defp index_patch([f_i, s_i]) when f_i > 0 and f_i <= 0.5 and s_i < 0.5 and s_i >= 0, do: '6' - defp index_patch([f_i, s_i]) when f_i > 0 and f_i <= 0.5 and s_i < 1 and s_i >= 0.5, do: '7' - - defp index_patch([f_i, s_i]) when f_i > -0.5 and f_i <= 0 and s_i < -0.5 and s_i >= -1, do: '8' - defp index_patch([f_i, s_i]) when f_i > -0.5 and f_i <= 0 and s_i < 0 and s_i >= -0.5, do: '9' - defp index_patch([f_i, s_i]) when f_i > -0.5 and f_i <= 0 and s_i < 0.5 and s_i >= 0, do: 'A' - defp index_patch([f_i, s_i]) when f_i > -0.5 and f_i <= 0 and s_i < 1 and s_i >= 0.5, do: 'B' - - defp index_patch([f_i, s_i]) when f_i > -1 and f_i <= -0.5 and s_i < -0.5 and s_i >= -1, do: 'C' - defp index_patch([f_i, s_i]) when f_i > -1 and f_i <= -0.5 and s_i < 0 and s_i >= -0.5, do: 'D' - defp index_patch([f_i, s_i]) when f_i > -1 and f_i <= -0.5 and s_i < 0.5 and s_i >= 0, do: 'E' - defp index_patch([f_i, s_i]) when f_i > -1 and f_i <= -0.5 and s_i < 1 and s_i >= 0.5, do: 'F' + defp index_patch([f_i, s_i]) when f_i >= 0.5 and f_i <= 1 and s_i <= -0.5 and s_i >= -1, do: '0' + defp index_patch([f_i, s_i]) when f_i >= 0.5 and f_i <= 1 and s_i <= 0 and s_i >= -0.5, do: '1' + defp index_patch([f_i, s_i]) when f_i >= 0.5 and f_i <= 1 and s_i <= 0.5 and s_i >= 0, do: '2' + defp index_patch([f_i, s_i]) when f_i >= 0.5 and f_i <= 1 and s_i <= 1 and s_i >= 0.5, do: '3' + + defp index_patch([f_i, s_i]) when f_i >= 0 and f_i <= 0.5 and s_i <= -0.5 and s_i >= -1, do: '4' + defp index_patch([f_i, s_i]) when f_i >= 0 and f_i <= 0.5 and s_i <= 0 and s_i >= -0.5, do: '5' + defp index_patch([f_i, s_i]) when f_i >= 0 and f_i <= 0.5 and s_i <= 0.5 and s_i >= 0, do: '6' + defp index_patch([f_i, s_i]) when f_i >= 0 and f_i <= 0.5 and s_i <= 1 and s_i >= 0.5, do: '7' + + defp index_patch([f_i, s_i]) when f_i >= -0.5 and f_i <= 0 and s_i <= -0.5 and s_i >= -1, + do: '8' + + defp index_patch([f_i, s_i]) when f_i >= -0.5 and f_i <= 0 and s_i <= 0 and s_i >= -0.5, do: '9' + defp index_patch([f_i, s_i]) when f_i >= -0.5 and f_i <= 0 and s_i <= 0.5 and s_i >= 0, do: 'A' + defp index_patch([f_i, s_i]) when f_i >= -0.5 and f_i <= 0 and s_i <= 1 and s_i >= 0.5, do: 'B' + + defp index_patch([f_i, s_i]) when f_i >= -1 and f_i <= -0.5 and s_i <= -0.5 and s_i >= -1, + do: 'C' + + defp index_patch([f_i, s_i]) when f_i >= -1 and f_i <= -0.5 and s_i <= 0 and s_i >= -0.5, + do: 'D' + + defp index_patch([f_i, s_i]) when f_i >= -1 and f_i <= -0.5 and s_i <= 0.5 and s_i >= 0, do: 'E' + defp index_patch([f_i, s_i]) when f_i >= -1 and f_i <= -0.5 and s_i <= 1 and s_i >= 0.5, do: 'F' defp sign(number) when number < 0, do: -1 defp sign(number) when number >= 0, do: 1