Skip to content

Commit

Permalink
adapt playground to version 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bchamagne committed Nov 29, 2023
1 parent e86b602 commit 289e8c4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
24 changes: 13 additions & 11 deletions lib/archethic_playground.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ defmodule ArchethicPlayground do
alias Archethic.Contracts.Contract
alias Archethic.Contracts.Contract.ActionWithTransaction
alias Archethic.Contracts.Contract.ActionWithoutTransaction
alias Archethic.Contracts.Contract.ConditionAccepted
alias Archethic.Contracts.Contract.ConditionRejected
alias Archethic.Contracts.Contract.PublicFunctionValue
alias Archethic.Contracts.Contract.Failure
alias Archethic.Contracts.Contract
alias Archethic.Crypto
Expand Down Expand Up @@ -40,7 +37,12 @@ defmodule ArchethicPlayground do
contract_tx :: PlaygroundTransaction.t(),
function_name :: String.t(),
args_values :: list(any())
) :: Failure.t() | PublicFunctionValue.t()
) ::
{:ok, result :: any()}
| {:error, :function_failure}
| {:error, :function_does_not_exist}
| {:error, :function_is_private}
| {:error, :timeout}
def execute_function(contract_tx, function_name, args_values) do
{:ok, contract} = parse(contract_tx)
Contracts.execute_function(contract, function_name, args_values)
Expand Down Expand Up @@ -96,7 +98,7 @@ defmodule ArchethicPlayground do
ArchethicPlayground.MockFunctions.prepare_mocks(mocks)

with {:ok, contract} <- parse(transaction_contract),
%ConditionAccepted{} <-
true <-
check_valid_precondition(trigger, contract, maybe_tx, maybe_recipient, datetime),
%ActionWithTransaction{
next_tx: next_tx,
Expand All @@ -109,7 +111,7 @@ defmodule ArchethicPlayground do
maybe_recipient,
time_now: datetime
),
%ConditionAccepted{} <-
true <-
check_valid_postcondition(contract, next_tx, datetime),
next_tx <-
PlaygroundTransaction.from_archethic(
Expand All @@ -120,8 +122,8 @@ defmodule ArchethicPlayground do
) do
{:ok, next_tx}
else
%ConditionRejected{subject: subject} ->
{:error, "Condition failed (section: #{subject})"}
false ->
{:error, "Condition failed"}

%ActionWithoutTransaction{} ->
{:ok, nil}
Expand Down Expand Up @@ -156,7 +158,7 @@ defmodule ArchethicPlayground do
nil,
datetime
) do
Contracts.execute_condition(:oracle, contract, tx, nil, datetime)
Contracts.valid_condition?(:oracle, contract, tx, nil, datetime)
end

defp check_valid_precondition(
Expand All @@ -166,7 +168,7 @@ defmodule ArchethicPlayground do
recipient,
datetime
) do
Contracts.execute_condition(condition_type, contract, tx, recipient, datetime)
Contracts.valid_condition?(condition_type, contract, tx, recipient, datetime)
end

defp check_valid_precondition(_, _, _, _, _), do: :ok
Expand All @@ -176,7 +178,7 @@ defmodule ArchethicPlayground do
next_tx = %Transaction{},
datetime
) do
Contracts.execute_condition(:inherit, contract, next_tx, nil, datetime)
Contracts.valid_condition?(:inherit, contract, next_tx, nil, datetime)
end

defp check_valid_postcondition(_, _, _), do: :ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule ArchethicPlaygroundWeb.MockFormComponent.ChainGetTransaction1 do
alias ArchethicPlayground.Transaction
alias ArchethicPlayground.Mock
alias ArchethicPlaygroundWeb.TransactionFormComponent
alias Archethic.Contracts.Constants
alias Archethic.Contracts.ContractConstants, as: Constants

use ArchethicPlaygroundWeb, :live_component

Expand Down
17 changes: 12 additions & 5 deletions lib/archethic_playground_web/live/editor_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ defmodule ArchethicPlaygroundWeb.EditorLive do
alias ArchethicPlaygroundWeb.TriggerComponent

alias Archethic.Contracts.Contract
alias Archethic.Contracts.Contract.Failure
alias Archethic.Contracts.Contract.PublicFunctionValue

use ArchethicPlaygroundWeb, :live_view

Expand Down Expand Up @@ -120,11 +118,20 @@ defmodule ArchethicPlaygroundWeb.EditorLive do
function_name,
args_values
) do
%PublicFunctionValue{value: value} ->
{:ok, value} ->
send(self(), {:console, :success, value})

%Failure{user_friendly_error: reason} ->
send(self(), {:console, :error, reason})
{:error, :function_failure} ->
send(self(), {:console, :error, "Function failed"})

{:error, :function_does_not_exist} ->
send(self(), {:console, :error, "Function does not exist"})

{:error, :function_is_private} ->
send(self(), {:console, :error, "Function is private"})

{:error, :timeout} ->
send(self(), {:console, :error, "Function timed-out"})
end

{:noreply, socket}
Expand Down
4 changes: 4 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@
"elixir_make": {:hex, :elixir_make, "0.7.5", "784cc00f5fa24239067cc04d449437dcc5f59353c44eb08f188b2b146568738a", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}], "hexpm", "c3d63e8d5c92fa3880d89ecd41de59473fa2e83eeb68148155e25e8b95aa2887"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"esbuild": {:hex, :esbuild, "0.7.0", "ce3afb13cd2c5fd63e13c0e2d0e0831487a97a7696cfa563707342bb825d122a", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "4ae9f4f237c5ebcb001390b8ada65a12fb2bb04f3fe3d1f1692b7a06fbfe8752"},
"ex_abi": {:hex, :ex_abi, "0.6.1", "b3dfc1f81e88c5927ac7ab18b7b743772323d151be6febc08c2a79372ce58842", [:mix], [{:ex_keccak, "~> 0.7.1", [hex: :ex_keccak, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "23f446e19b81428bb1c56de88a595b6aa45a423a7e4a97952c44bef50a66d921"},
"ex_cldr": {:hex, :ex_cldr, "2.34.1", "b4e32d9fb4f7d49211faa45e8a871afff5c5eb3c2f0763b5dd49e3c7df16a0dd", [:mix], [{:cldr_utils, "~> 2.19", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:gettext, "~> 0.19", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: true]}], "hexpm", "bd635b9e76271baa5db67a7c224be485f31cea8f7c05d6b0daeefa9d04cf76c0"},
"ex_cldr_currencies": {:hex, :ex_cldr_currencies, "2.15.0", "aadd34e91cfac7ef6b03fe8f47f8c6fa8c5daf3f89b5d9fee64ec545ded839cf", [:mix], [{:ex_cldr, "~> 2.34", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "0521316396c66877a2d636219767560bb2397c583341fcb154ecf9f3000e6ff8"},
"ex_cldr_numbers": {:hex, :ex_cldr_numbers, "2.29.0", "ce20899a734ac33cf088c57685035ca1626d5564f50e0ac4d3da24202b112d5a", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:digital_token, "~> 0.3 or ~> 1.0", [hex: :digital_token, repo: "hexpm", optional: false]}, {:ex_cldr, "~> 2.34", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:ex_cldr_currencies, ">= 2.14.2", [hex: :ex_cldr_currencies, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "134e5e82d3894f0e06f096124c24f4ef1f54f1874c35714d52aa7d370a25c306"},
"ex_json_schema": {:hex, :ex_json_schema, "0.9.2", "c9a42e04e70cd70eb11a8903a22e8ec344df16edef4cb8e6ec84ed0caffc9f0f", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "4854329cb352b6c01c4c4b8dbfb3be14dc5bea19ea13e0eafade4ff22ba55224"},
"ex_keccak": {:hex, :ex_keccak, "0.7.1", "0169f4b0c5073c5df61581d6282b12f1a1b764dcfcda4eeb1c819b5194c9ced0", [:mix], [{:rustler, ">= 0.0.0", [hex: :rustler, repo: "hexpm", optional: true]}, {:rustler_precompiled, "~> 0.6.1", [hex: :rustler_precompiled, repo: "hexpm", optional: false]}], "hexpm", "c18c19f66b6545b4b46b0c71c0cc0079de84e30b26365a92961e91697e8724ed"},
"ex_secp256k1": {:hex, :ex_secp256k1, "0.7.2", "33398c172813b90fab9ab75c12b98d16cfab472c6dcbde832b13c45ce1c01947", [:mix], [{:rustler, ">= 0.0.0", [hex: :rustler, repo: "hexpm", optional: true]}, {:rustler_precompiled, "~> 0.6", [hex: :rustler_precompiled, repo: "hexpm", optional: false]}], "hexpm", "f3b1bf56e6992e28b9d86e3bf741a4aca3e641052eb47d13ae4f5f4d4944bdaf"},
"exjsonpath": {:hex, :exjsonpath, "0.9.0", "87e593eb0deb53aa0688ca9f9edc9fb3456aca83c82245f83201ea04d696feba", [:mix], [], "hexpm", "8d7a8e9ba784e1f7a67c6f1074a3ac91a3a79a45969514ee5d95cea5bf749627"},
"exla": {:hex, :exla, "0.5.3", "f9496980a447ec2564b1646f89ee64379faef608c4a3ab6059f6a55117235e63", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:nx, "~> 0.5.1", [hex: :nx, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:xla, "~> 0.4.4", [hex: :xla, repo: "hexpm", optional: false]}], "hexpm", "41c0523217e9ed4007c005be08ec5692b76f509f0103a2c4f6b2ed016213a48e"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
Expand Down Expand Up @@ -73,6 +76,7 @@
"recase": {:hex, :recase, "0.7.0", "3f2f719f0886c7a3b7fe469058ec539cb7bbe0023604ae3bce920e186305e5ae", [:mix], [], "hexpm", "36f5756a9f552f4a94b54a695870e32f4e72d5fad9c25e61bc4a3151c08a4e0c"},
"recon": {:hex, :recon, "2.5.3", "739107b9050ea683c30e96de050bc59248fd27ec147696f79a8797ff9fa17153", [:mix, :rebar3], [], "hexpm", "6c6683f46fd4a1dfd98404b9f78dcabc7fcd8826613a89dcb984727a8c3099d7"},
"retry": {:hex, :retry, "0.17.0", "2582b6371155b6c1abdb95e5d35e82c0a3947be61ae8eb72085f1582ef47b652", [:mix], [], "hexpm", "27ab3fd96fc58c05b0a411abb6d150de8b6fe97a8327519171597498a6694024"},
"rustler_precompiled": {:hex, :rustler_precompiled, "0.6.3", "f838d94bc35e1844973ee7266127b156fdc962e9e8b7ff666c8fb4fed7964d23", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "e18ecca3669a7454b3a2be75ae6c3ef01d550bc9a8cf5fbddcfff843b881d7c6"},
"sizeable": {:hex, :sizeable, "1.0.2", "625fe06a5dad188b52121a140286f1a6ae1adf350a942cf419499ecd8a11ee29", [:mix], [], "hexpm", "4bab548e6dfba777b400ca50830a9e3a4128e73df77ab1582540cf5860601762"},
"sobelow": {:hex, :sobelow, "0.12.2", "45f4d500e09f95fdb5a7b94c2838d6b26625828751d9f1127174055a78542cf5", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "2f0b617dce551db651145662b84c8da4f158e7abe049a76daaaae2282df01c5d"},
"statistex": {:hex, :statistex, "1.0.0", "f3dc93f3c0c6c92e5f291704cf62b99b553253d7969e9a5fa713e5481cd858a5", [:mix], [], "hexpm", "ff9d8bee7035028ab4742ff52fc80a2aa35cece833cf5319009b52f1b5a86c27"},
Expand Down

0 comments on commit 289e8c4

Please sign in to comment.