BSV.Block (BSV v2.1.0) View Source

A block is a data structure consisting of a BSV.BlockHeader.t/0 and a list of transactions.

Transaction data is permanently recorded into blocks. Because each block contains a reference to the previous block, over time blocks form a chain.

Link to this section Summary

Types

Merkle root - the result of hashing all of the transactions contained in the block into a tree-like structure known as a Merkle tree.

t()

Block struct

Functions

Calculates and returns the result of hashing all of the transactions contained in the block into a tree-like structure known as a Merkle tree.

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

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

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

Calculates the BSV.Block.merkle_root/0 of the given block and compares the result to the value contained the BSV.BlockHeader.t/0.

Link to this section Types

Specs

merkle_root() :: <<_::256>>

Merkle root - the result of hashing all of the transactions contained in the block into a tree-like structure known as a Merkle tree.

Specs

t() :: %BSV.Block{header: BSV.BlockHeader.t(), txns: [BSV.Tx.t()]}

Block struct

Link to this section Functions

Specs

calc_merkle_root(t()) :: merkle_root()

Calculates and returns the result of hashing all of the transactions contained in the block into a tree-like structure known as a Merkle tree.

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.Block.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.Block.t/0.

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

Link to this function

to_binary(block, opts \\ [])

View Source

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

Options

The accepted options are:

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

validate_merkle_root(block)

View Source

Specs

validate_merkle_root(t()) :: boolean()

Calculates the BSV.Block.merkle_root/0 of the given block and compares the result to the value contained the BSV.BlockHeader.t/0.