Manic.TX (Manic v0.1.0) View Source

Send transactions directly to miners and query the status of any transaction.

By giving a transaction directly to a miner (instead of broadcasting it to the Bitcoin peer network), you are pushing the transaction directly to the centre of the network. As the miner will have already provided the correct fees to ensure the transaction is relayed and mined, you can confidently accept the transaction on a "zero confirmation" basis.

This module allows developers to push transactions directly to miners and query the status of any transaction. As each payload from the Merchant API includes and is signed by the miner's Miner ID, the response can be treated as a legally binding signed message backed by the miner's own proof of work.

Link to this section Summary

Types

Hex-encoded transaction ID.

Functions

Sends the given transaction directly to a miner.

As push/3 but returns the result or raises an exception if it fails.

Query the status of a transaction by its txid, from the given miner.

As status/3 but returns the result or raises an exception if it fails.

Link to this section Types

Specs

txid() :: String.t()

Hex-encoded transaction ID.

Link to this section Functions

Link to this function

push(miner, tx, options \\ [])

View Source

Specs

Sends the given transaction directly to a miner.

Returns the result in an :ok / :error tuple pair.

The transaction can be passed as either a BSV.Tx.t/0 or as a hex encoded binary.

Options

The :as option can be used to speficy how to recieve the fees. The accepted values are:

Examples

To push a transaction to the minder.

iex> Manic.TX.push(miner, tx)
{:ok, %{
  "api_version" => "0.1.0",
  "current_highest_block_hash" => "00000000000000000397a5a37c1f9b409b4b58e76fd6bcac06db1a3004cccb38",
  "current_highest_block_height" => 631603,
  "miner_id" => "03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270",
  "result_description" => "",
  "return_result" => "success",
  "timestamp" => "2020-04-21T14:04:39.563Z",
  "tx_second_mempool_expiry" => 0,
  "txid" => "9c8c5cf37f4ad1a82891ff647b13ec968f3ccb44af2d9deaa205b03ab70a81fa",
  "verified" => true
}}

Using the :as option to return the JSON envolope.

iex> Manic.TX.push(miner, tx, as: :envelope)
{:ok, %Manic.JSONEnvelope{
  encoding: "UTF-8",
  mimetype: "application/json",
  payload: "{\"apiVersion\":\"0.1.0\",\"timestamp\":\"2020-04-21T14:04:39.563Z\",\"txid\":\"\"9c8c5cf37f4ad1a82891ff647b13ec968f3ccb44af2d9deaa205b03ab70a81fa\"\",\"returnResult\":\"success\",\"resultDescription\":\"\",\"minerId\":\"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270\",\"currentHighestBlockHash\":\"00000000000000000397a5a37c1f9b409b4b58e76fd6bcac06db1a3004cccb38\",\"currentHighestBlockHeight\":631603,\"txSecondMempoolExpiry\":0}",
  public_key: "03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270",
  signature: "3045022100a490e469426f34fcf62d0f095c10039cf5a1d535c042172786c364d41de65b3a0220654273ca42b5e955179d617ea8252e64ddf74657aa0caebda7372b40a0f07a53",
  verified: true
}}
Link to this function

push!(miner, tx, options \\ [])

View Source

Specs

As push/3 but returns the result or raises an exception if it fails.

Link to this function

status(miner, txid, options \\ [])

View Source

Specs

Query the status of a transaction by its txid, from the given miner.

Returns the result in an :ok / :error tuple pair.

Options

The :as option can be used to speficy how to recieve the fees. The accepted values are:

Examples

To get the status of a transaction/

iex> Manic.TX.boradcast(miner, "e4763d71925c2ac11a4de0b971164b099dbdb67221f03756fc79708d53b8800e")
{:ok, %{
  "api_version" => "0.1.0",
  "block_hash" => "000000000000000000983dee680071d63939f4690a8a797c022eddadc88f925e",
  "block_height" => 630712,
  "confirmations" => 765,
  "miner_id" => "03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270",
  "result_description" => "",
  "return_result" => "success",
  "timestamp" => "2020-04-20T21:45:38.808Z",
  "tx_second_mempool_expiry" => 0,
  "verified" => true
}}

Using the :as option to return the JSON envolope.

iex> Manic.TX.boradcast(miner, tx, as: :envelope)
{:ok, %Manic.JSONEnvelope{
  encoding: "UTF-8",
  mimetype: "application/json",
  payload: "{\"apiVersion\":\"0.1.0\",\"timestamp\":\"2020-04-20T21:45:38.808Z\",\"returnResult\":\"success\",\"resultDescription\":\"\",\"blockHash\":\"000000000000000000983dee680071d63939f4690a8a797c022eddadc88f925e\",\"blockHeight\":630712,\"confirmations\":765,\"minerId\":\"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270\",\"txSecondMempoolExpiry\":0}",
  public_key: "03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270",
  signature: "304502210092b822497cfe065136522b33b0fbec790c77f62818bd252583a615efd35697af022059c4ca7e97c90960860ed9d7b0ff4a1601cfe207b638c672c60a44027aed1f2d",
  verified: true
}}
Link to this function

status!(miner, txid, options \\ [])

View Source

Specs

As status/3 but returns the result or raises an exception if it fails.