View Source Numscriptex.Builder (numscriptex v0.2.6)

Numscriptex.Builder makes it possible to build Numscripts dynamically within your application.

Summary

Functions

Receives a map with the metadata necessary to build your numscript.

Types

fixed_split()

@type fixed_split() :: %{
  type: :fixed | :percent,
  amount: pos_integer(),
  account: bitstring(),
  asset: bitstring()
}

metadata()

@type metadata() :: %{
  :splits => [fixed_split()] | [percent_split()],
  optional(:remaining_to) => bitstring(),
  optional(:percent_asset) => bitstring()
}

percent_split()

@type percent_split() :: %{
  :type => :fixed | :percent,
  :amount => pos_integer(),
  optional(:account) => bitstring(),
  optional(:splits) => [percent_split()],
  optional(:remaining_to) => bitstring()
}

Functions

build(metadata)

@spec build(metadata()) :: {:ok, %{script: bitstring()}} | {:error, bitstring()}

Receives a map with the metadata necessary to build your numscript.

iex> metadata = %{
...>   splits: [
...>     %{
...>       type: :fixed,
...>       amount: 500,
...>       asset: "BRL/2",
...>       account: "some:destination"
...>     }
...>   ]
...> }
...>
...> Numscriptex.Builder.build(metadata)
{:ok, %{script: "send [BRL/2 500] (
  source = @user
  destination = @some:destination
)
"}}

If you want to learn more about this feature you can check its guide here