BSV.BlockHeader (bsv_sdk v2.0.0)

Copy Markdown View Source

An 80-byte block header providing a summary of a Bitcoin block.

Contains the version, previous block hash, merkle root, timestamp, difficulty target (bits), and nonce. The block hash is the double-SHA256 of the serialized 80-byte header.

Summary

Types

t()

Block header

Functions

Parse a block header from a binary.

Parse a block header from a hex-encoded string.

Compute the block hash (double SHA-256 of the 80-byte header), returned as a 32-byte binary in internal byte order (little-endian, as used in Bitcoin's wire protocol).

Compute the block hash as a hex string in display byte order (reversed, as shown in block explorers).

Return the size in bytes of a serialized block header (always 80).

Serialize a block header to its 80-byte binary representation.

Serialize a block header to a hex-encoded string.

Types

t()

@type t() :: %BSV.BlockHeader{
  bits: non_neg_integer(),
  merkle_root: <<_::256>>,
  nonce: non_neg_integer(),
  prev_hash: <<_::256>>,
  time: non_neg_integer(),
  version: non_neg_integer()
}

Block header

Functions

from_binary(arg1)

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

Parse a block header from a binary.

Returns {:ok, header, rest} or {:error, reason}.

from_hex(hex)

@spec from_hex(String.t()) :: {:ok, t()} | {:error, term()}

Parse a block header from a hex-encoded string.

hash(h)

@spec hash(t()) :: <<_::256>>

Compute the block hash (double SHA-256 of the 80-byte header), returned as a 32-byte binary in internal byte order (little-endian, as used in Bitcoin's wire protocol).

hash_hex(h)

@spec hash_hex(t()) :: String.t()

Compute the block hash as a hex string in display byte order (reversed, as shown in block explorers).

size()

@spec size() :: 80

Return the size in bytes of a serialized block header (always 80).

to_binary(h)

@spec to_binary(t()) :: binary()

Serialize a block header to its 80-byte binary representation.

to_hex(h)

@spec to_hex(t()) :: String.t()

Serialize a block header to a hex-encoded string.