BSV.Tx (BSV v2.0.0) View Source

A Tx is a data structure representing a Bitcoin transaction.

A Tx consists of a version number, a list of inputs, list of outputs, and a locktime value.

A Bitcoin transaction is used to transfer custody of Bitcoins. It can also be used for smart contracts, recording and timestamping data, and many other functionalities.

The Tx module is used for parsing and serialising transaction data. Use the BSV.TxBuilder module for building transactions.

Link to this section Summary

Types

Tx hash

t()

Tx struct

TXID

Functions

Adds the given BSV.TxIn.t/0 to the transaction.

Adds the given BSV.TxOut.t/0 to the transaction.

Parses the given binary into a BSV.Tx.t/0.

Parses the given binary into a BSV.Tx.t/0.

Returns the BSV.Tx.hash/0 of the given transaction.

Returns the number of bytes of the given BSV.Tx.t/0.

Returns the BSV.Tx.txid/0 of the given transaction.

Returns true if the given BSV.Tx.t/0 is a coinbase transaction (the first transaction in a block, containing the miner block reward).

Serialises the given BSV.TxIn.t/0 into a binary.

Link to this section Types

Specs

hash() :: <<_::256>>

Tx hash

Result of hashing the transaction data through the SHA-256 algorithm twice.

Specs

t() :: %BSV.Tx{
  inputs: [BSV.TxIn.t()],
  lock_time: non_neg_integer(),
  outputs: [BSV.TxOut.t()],
  version: non_neg_integer()
}

Tx struct

Specs

txid() :: String.t()

TXID

Result of reversing and hex-encoding the BSV.Tx.hash/0.

Link to this section Functions

Specs

add_input(t(), BSV.TxIn.t()) :: t()

Adds the given BSV.TxIn.t/0 to the transaction.

Specs

add_output(t(), BSV.TxOut.t()) :: t()

Adds the given BSV.TxOut.t/0 to the transaction.

Link to this function

from_binary(data, opts \\ [])

View Source

Specs

from_binary(binary(), keyword()) :: {:ok, t()} | {:error, term()}

Parses the given binary into a BSV.Tx.t/0.

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

Options

The accepted options are:

  • :encoding - Optionally decode the binary with either the :base64 or :hex encoding scheme.
Link to this function

from_binary!(data, opts \\ [])

View Source

Specs

from_binary!(binary(), keyword()) :: t()

Parses the given binary into a BSV.Tx.t/0.

As from_binary/2 but returns the result or raises an exception.

Specs

get_hash(t()) :: hash()

Returns the BSV.Tx.hash/0 of the given transaction.

Specs

get_size(t()) :: non_neg_integer()

Returns the number of bytes of the given BSV.Tx.t/0.

Specs

get_txid(t()) :: txid()

Returns the BSV.Tx.txid/0 of the given transaction.

Specs

is_coinbase?(t()) :: boolean()

Returns true if the given BSV.Tx.t/0 is a coinbase transaction (the first transaction in a block, containing the miner block reward).

Link to this function

to_binary(tx, opts \\ [])

View Source

Serialises the given BSV.TxIn.t/0 into a binary.

Options

The accepted options are:

  • :encoding - Optionally encode the binary with either the :base64 or :hex encoding scheme.