Txbox v0.1.0 Txbox.Transactions View Source

Collection of functions for composing Ecto queries.

The functions in this module can be broadly split into two types, expressions and queries.

Expressions

Expression functions can be used to compose queries following the Elixir pipeline syntax.

iex> Tx
...> |> Transactions.confirmed(true)
...> |> Transactions.tagged(["space", "photos"])
%Ecto.Query{}

Queries

Query functions interface with the repo and either create or return records from the repo.

iex> Transactions.list_tx()
[%Tx{}, ...]

Link to this section Summary

Expressions

Query by the given channel name.

Query by the transaction confirmation status.

Query by the given query map.

Search by the given term.

Query by the given tag or list of tags.

Queries

Creates a transaction from the given params.

Deletes the given transaction from the repo.

Get a transaction by it's internal ID or TXID.

Returns a list of transactions that have not yet been confirmed by mAPI.

Returns a list of transactions.

Returns a list of transactions filtered by the given search term.

Updates the given transaction's status, with the specified params.

Functions

Returns the application's configured Repo.

Link to this section Expressions

Specs

Query by the given channel name.

Link to this function

confirmed(tx, conf \\ true)

View Source

Specs

Query by the transaction confirmation status.

Specs

Query by the given query map.

Specs

Search by the given term.

Specs

Query by the given tag or list of tags.

Optionally tags can be specified as a comma seperated string

Link to this section Queries

Specs

create_tx(map()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}

Creates a transaction from the given params.

Returns an :ok / :error tuple response.

Examples

iex> {:ok, tx} = Transactions.create_tx(%{
...>   txid: "6dfccf46359e033053ab1975c1e008ddc98560f591e8ed1c8bd051050992c110",
...>   channel: "mychannel"
...> })

Specs

delete_tx(Ecto.Schema.t()) ::
  {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}

Deletes the given transaction from the repo.

Returns an :ok / :error tuple response.

Examples

iex> {:ok, tx} = Transactions.get_tx("6dfccf46359e033053ab1975c1e008ddc98560f591e8ed1c8bd051050992c110")
...> |> Transactions.delete_tx

Specs

get_tx(Ecto.Queryable.t(), binary()) :: Ecto.Schema.t() | nil

Get a transaction by it's internal ID or TXID.

Can optionally pass a Ecto.Queryable.t as the first argument to compose queries.

Examples

# Find a tx by it's Txbox uuid
iex> tx = Transactions.find_tx "e9d356cf-47e9-47c3-bfc8-c12673877302"

# Composed query, found by txid
iex> tx = Transactions.channel("mychannel)
...> |> Transactions.confirmed(true)
...> |> Transactions.find_tx("6dfccf46359e033053ab1975c1e008ddc98560f591e8ed1c8bd051050992c110")
Link to this function

list_pending_tx_for_mapi_check()

View Source

Specs

list_pending_tx_for_mapi_check() :: [Ecto.Schema.t()]

Returns a list of transactions that have not yet been confirmed by mAPI.

This is used internally by Txbox.MapiStatus.Queue to fetch transactions for automatic processing.

Link to this function

list_tx(tx \\ Tx, params)

View Source

Specs

list_tx(Ecto.Queryable.t(), map()) :: [Ecto.Schema.t()]

Returns a list of transactions.

Can optionally pass a Ecto.Queryable.t as the first argument to compose queries. If a map of query options is given as a secndon argument, the query is filtered by those arguments.

Examples

iex> txns = Transactions.channel("mychannel)
...> |> Transactions.confirmed(true)
...> |> Transactions.list_tx
Link to this function

search_tx(tx \\ Tx, term)

View Source

Specs

search_tx(Ecto.Queryable.t(), String.t()) :: [Ecto.Schema.t()]

Returns a list of transactions filtered by the given search term.

Performs a full text search on the transactions' metadata. Can optionally pass a Ecto.Queryable.t as the first argument to compose queries.

Examples

iex> {:ok, txns} = Transactions.search_tx("unwriter bitpic")
Link to this function

update_tx_status(tx, attrs \\ %{})

View Source

Specs

update_tx_status(Ecto.Schema.t(), map() | nil) ::
  {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}

Updates the given transaction's status, with the specified params.

Returns an :ok / :error tuple response.

Examples

iex> {:ok, tx} = Transactions.update_tx_status(%{
...>   payload: %{...},
...>   public_key: "03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270",
...>   signature: "3045022100a490e469426f34fcf62d0f095c10039cf5a1d535c042172786c364d41de65b3a0220654273ca42b5e955179d617ea8252e64ddf74657aa0caebda7372b40a0f07a53"
...> })

Link to this section Functions

Specs

repo() :: module()

Returns the application's configured Repo.

Ensure your application's Repo is configured in config.exs:

config :txbox, repo: MyApp.Repo