View Source Numscriptex.Balance (numscriptex v0.2.6)

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

Types

t()

Type that represents Numscriptex.Balance struct.

Functions

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

Types

t()

@type t() :: %Numscriptex.Balance{
  account: bitstring(),
  asset: bitstring(),
  decimal_final_balance: float(),
  decimal_initial_balance: float(),
  final_balance: integer(),
  initial_balance: integer()
}

Type that represents Numscriptex.Balance struct.

Fields

  • :account the account name
  • :asset the asset were the transaction was made
  • :final_balance balance after the transactions (integer)
  • :decimal_final_balance balance after the transactions, but as float
  • :initial_balance balance before the transactions (integer)
  • :decimal_initial_balance balance after the transactions, but as float

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.Balance.put(account_assets, postings)
[
  %Numscriptex.Balance{
    account: "foo",
    asset: "EUR/2",
    final_balance: 300,
    decimal_final_balance: 3.0,
    initial_balance: 300,
    decimal_initial_balance: 3.0
  },
  %Numscriptex.Balance{
    account: "foo",
    asset: "USD/2",
    final_balance: 400,
    decimal_final_balance: 4.0,
    initial_balance: 500,
    decimal_initial_balance: 5.0
  },
  %Numscriptex.Balance{
    account: "bar",
    asset: "USD/2",
    final_balance: 100,
    decimal_final_balance: 1.0,
    initial_balance: 0,
    decimal_initial_balance: 0.0
  }
]