Terminus v0.1.1 Terminus.Omni View Source
Module for conveniently fetching data from both Bitbus and Bitsocket concurrently.
Terminus.Omni
replicates the functionality of legacy Planaria APIs by allowing
you to query for both confirmed and unconfirmed transactions in one call. HTTP
requests to both APIs occur concurrently and a combined result is returned when
both APIs have yielded a response.
Mempool transactions are intelligently handled. The Bitsocket event database is queried to safely gather enough transactions to cover the time period since the last block, and then cross-referenced with confirmed transactions to ensure there are no duplicates. It just... works!
Examples
Use fetch/2
to query for a combined set of confirmed and unconfimred
transactions.
iex> Terminus.Omni.fetch(%{
...> find: %{ "out.s2" => "1LtyME6b5AnMopQrBPLk4FGN8UBuhxKqrn" },
...> limit: 5
...> }, token: token)
{:ok, %{
c: [...], # 5 confirmed tx
u: [...], # 5 unconfirmed tx
}}
Alterntivly, find/2
allows for a single transaction to be easily found by
it's txid
, irrespective of whether the transaction is
confirmed or in the mempool.
iex> Terminus.Omni.find(txid, token: token)
{:ok, %{
"tx" => %{"h" => "fca7bdd7658613418c54872212811cf4c5b4f8ee16864eaf70cb1393fb0df6ca"},
...
}}
Link to this section Summary
Functions
Crawls Bitbus and Bitsocket for transactions using the given query and returns a map containing both confirmed and mempool transactions.
As fetch/2
but returns the result or raises an exception if it fails.
Query Bitbus and Bitsocket for a single transaction by the given txid
.
As find/2
but returns the result or raises an exception if it fails.
Link to this section Functions
Specs
fetch(Terminus.bitquery(), keyword()) :: {:ok, map()} | {:error, Exception.t()}
Crawls Bitbus and Bitsocket for transactions using the given query and returns a map containing both confirmed and mempool transactions.
Returns the result in an :ok
/ :error
tuple pair.
If no limit is specified in the given bitquery
map, a default limit of 20
is added to the query. This limit is applied to
both sets of results, meaning a maximum of 40 unique transactions may be
returned.
Options
The accepted options are:
token
- Planaria authentication token. Required.host
- The Bitbus host. Defaults to:txo
.
Examples
Get the 5 latest confirmed and unconfirmed WeatherSV transactions.
iex> Terminus.Omni.fetch(%{
...> find: %{ "out.s2" => "1LtyME6b5AnMopQrBPLk4FGN8UBuhxKqrn" },
...> limit: 5
...> }, token: token)
{:ok, %{
c: [...], # 5 confirmed tx
u: [...], # 5 unconfirmed tx
}}
Specs
fetch!(Terminus.bitquery(), keyword()) :: map()
As fetch/2
but returns the result or raises an exception if it fails.
Specs
find(Terminus.txid(), keyword()) :: {:ok, map()} | {:error, Exception.t()}
Query Bitbus and Bitsocket for a single transaction by the given txid
.
Returns the result in an :ok
/ :error
tuple pair.
Options
The accepted options are:
token
- Planaria authentication token. Required.host
- The Bitbus host. Defaults to:txo
.
Examples
iex> Terminus.Omni.find(txid, token: token)
{:ok, %{
"tx" => %{"h" => "fca7bdd7658613418c54872212811cf4c5b4f8ee16864eaf70cb1393fb0df6ca"},
...
}}
Specs
find!(Terminus.txid(), keyword()) :: map()
As find/2
but returns the result or raises an exception if it fails.