View Source Numscriptex.Balances (numscriptex v0.2.1)

Numscriptex.Balances is responsible for building the account's final balance after running your Numscript, so you can see the results of all transactions.

Summary

Functions

Receives the account assets (balance field from %Numscriptex.Run{}), and the postings that are generated after running the numscript transaction.

Functions

put(account_assets, postings)

@spec put(map(), list()) :: [map()]

Receives the account assets (balance field from %Numscriptex.Run{}), and the postings that are generated after running the numscript transaction.

The result will be a map contaning the initial and final balances of each account assets. Ex:

iex> account_assets = %{
...>     "foo" => %{
...>     "USD/2" => 500,
...>     "EUR/2" => 300
...>   }
...> }
...>
...> postings = [
...>   %{
...>     "amount" => 100,
...>     "asset" => "USD/2",
...>     "destination" => "bar",
...>     "source" => "foo"
...>   }
...> ]
...>
...> Numscriptex.Balances.put(account_assets, postings)
[
  %{
    "account" => "foo",
    "asset" => "EUR/2",
    "final_balance" => 300,
    "initial_balance" => 300
  },
  %{
    "account" => "foo",
    "asset" => "USD/2",
    "final_balance" => 400,
    "initial_balance" => 500
  },
  %{
    "account" => "bar",
    "asset" => "USD/2",
    "final_balance" => 100,
    "initial_balance" => 0
  }
]