View Source Numscriptex.Run (numscriptex v0.2.6)
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
Lists all available feature flags.
Creates a new Numscriptex.Run{} struct.
Normalizes the Numscriptex.Run struct to a map.
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 t() :: %Numscriptex.Run{ balances: map(), feature_flags: list(), metadata: map(), variables: map() }
Type that represents Numscriptex.Run struct.
Fields
:balancesa map with account's assets balances:metadatametadata variables:variablesvariables:feature_flagsa list of feature flags used to enable experimental features
Functions
@spec list_available_feature_flags() :: [atom()]
Lists all available feature flags.
iex> Numscriptex.Run.list_available_feature_flags()
[
:experimental_overdraft_function,
:experimental_get_asset_function,
:experimental_get_amount_function,
:experimental_oneof,
:experimental_account_interpolation,
:experimental_mid_script_function_call,
:experimental_asset_colors
]
@spec new() :: t()
Creates a new Numscriptex.Run{} struct.
iex> Numscriptex.Run.new()
%Numscriptex.Run{
variables: %{},
balances: %{},
metadata: %{},
feature_flags: []
}
Normalizes the Numscriptex.Run struct to a map.
iex> struct =
...> Numscriptex.Run.put!(Numscriptex.Run.new(), :feature_flags, [:experimental_overdraft_function])
...>
...> Numscriptex.Run.normalize_to_map(struct)
%{
balances: %{},
metadata: %{},
variables: %{},
featureFlags: %{"experimental-overdraft-function" => %{}}
}
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: %{},
feature_flags: []
}
}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` for field `balances` must be a map.