BSV.MerkleProof (BSV v2.1.0) View Source

The MerkleProof module implements the BSV TCS Merkle proof standard.

Merkle proofs are fundamental to the Simplified Payment Verification (SPV) model that underpins bitcoin scaling. Assuming we have stored block headers from the blockchain, given a transaction and BSV.MerkleProof.t/0, we can verify the transaction is contained in a block without downloading the entire block.

The TSC Merkle proof standard describes a way of serialising a Merkle proof in a binary or json format, so network participants can share the proofs in a standardised format.

Link to this section Summary

Types

t()

Merkle proof struct

Functions

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

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

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

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

Link to this section Types

Specs

t() :: %BSV.MerkleProof{
  flags: integer(),
  index: non_neg_integer(),
  nodes: [BSV.Tx.hash()],
  subject: BSV.Tx.t() | BSV.Tx.hash(),
  target: BSV.BlockHeader.t() | binary()
}

Merkle proof struct

Link to this section Functions

Link to this function

calc_merkle_root(merkle_proof)

View Source

Specs

calc_merkle_root(t()) :: binary()

Calculates and returns the result of hashing all of the transaction hashes contained in the Merkle proof 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.MerkleProof.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.MerkleProof.t/0.

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

Link to this macro

is_txid?(flags)

View Source (macro)
Link to this macro

targets_block_hash?(flags)

View Source (macro)
Link to this macro

targets_block_header?(flags)

View Source (macro)
Link to this macro

targets_merkle_root?(flags)

View Source (macro)
Link to this function

to_binary(merkle_proof, opts \\ [])

View Source

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

Options

The accepted options are:

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