View Source Numscriptex (numscriptex v0.2.5)

NumscriptEx is a library that allows its users to check and run Numscripts via Elixir.

Want to check if your script is valid and ready to go? Use the check/1 function. Already checked the script and want to execute him? Use the run/2 function.

Summary

Functions

To use check/1 you just need to pass your numscript as its argument. Ex

To use run/2 your first argument must be your script, and the second must be a %Numscriptex.Run{} (go to Numscriptex.Run module to see more) struct. Ex

version/0 simply shows a map with both Numscript-WASM and NumscriptEx versions. Ex

Types

check_result()

@type check_result() :: %{
  :script => binary(),
  optional(:hints) => [Numscriptex.CheckLog.t()],
  optional(:infos) => [Numscriptex.CheckLog.t()],
  optional(:warnings) => [Numscriptex.CheckLog.t()]
}

errors()

@type errors() :: %{
  :reason => [Numscriptex.CheckLog.t()] | any(),
  optional(:details) => any()
}

run_result()

@type run_result() :: %{
  balances: [Numscriptex.Balance.t()],
  postings: [Numscriptex.Posting.t()],
  accountsMeta: map(),
  txMeta: map()
}

Functions

check(input)

@spec check(binary()) :: {:ok, check_result()} | {:error, errors()}

To use check/1 you just need to pass your numscript as its argument. Ex:

iex> script = "send [USD/2 100] (source = @foo destination = @bar)"
iex> Numscriptex.check(script)
{:ok, %{script: script}}

It could also return some warnings, infos or hints inside the map

run(numscript, run_struct)

@spec run(binary(), Numscriptex.Run.t()) :: {:ok, run_result()} | {:error, errors()}

To use run/2 your first argument must be your script, and the second must be a %Numscriptex.Run{} (go to Numscriptex.Run module to see more) struct. Ex:

iex> script = "send [USD/2 100] (source = @foo destination = @bar)"
...> balances = %{"foo" => %{"USD/2" => 500, "EUR/2" => 300}}
...>
...> struct =
...> Numscriptex.Run.new()
...> |> Numscriptex.Run.put!(:balances, balances)
...> |> Numscriptex.Run.put!(:metadata, %{})
...> |> Numscriptex.Run.put!(:variables, %{})
...>
...> Numscriptex.run(script, struct)

version()

@spec version() :: %{numscriptex: binary(), numscript_wasm: binary()}

version/0 simply shows a map with both Numscript-WASM and NumscriptEx versions. Ex:

iex> Numscriptex.version()
%{numscriptex: "v0.2.5", numscript_wasm: "v0.0.2"}