View Source Numscriptex.Run (numscriptex v0.2.1)
A Numscript needs some other data aside from the script itself to run correctly,
and Numscriptex.Run
solves this problem. If you want to know what exactly these
additional fields are, you can learn more on Numscript Playground and the Numscript Docs.
Summary
Types
Type that represents Numscriptex.Run
struct.
Functions
Creates a new Numscriptex.Run{}
struct.
Puts the chosen value under the field key on the Numscriptex.Run
struct as
long both are valid.
Same as put/3
, but raises an exception if any argument is invalid.
Types
Type that represents Numscriptex.Run
struct.
Fields
:balances
a map with account's assets balances:metadata
metada variables:variables
variables used inside the script
Functions
@spec new() :: t()
Creates a new Numscriptex.Run{}
struct.
iex> Numscriptex.Run.new()
%Numscriptex.Run{
variables: %{},
balances: %{},
metadata: %{}
}
Puts the chosen value under the field key on the Numscriptex.Run
struct as
long both are valid.
iex> struct = Numscriptex.Run.new()
...> balances = %{"foo" => %{"USD/2" => 500, "EUR/2" => 300}}
...>
...> Numscriptex.Run.put(struct, :balances, balances)
{:ok,
%Numscriptex.Run{
balances: %{"foo" => %{"USD/2" => 500, "EUR/2" => 300}},
variables: %{},
metadata: %{}
}
}
If the value or the field key are invalid, put/3
will return a 3 element
error tuple. Ex:
iex> struct = Numscriptex.Run.new()
...>
...> Numscriptex.Run.put(struct, :invalid_field, %{})
{:error, :invalid_field, %{details: "The field 'invalid_field' does not exists."}}
Same as put/3
, but raises an exception if any argument is invalid.
iex> struct = Numscriptex.Run.new()
...> balances = [%{"foo" => %{"USD/2" => 500, "EUR/2" => 300}}]
...>
...> Numscriptex.Run.put!(struct, :balances, balances)
** (ArgumentError) Argument `value` must be a map.