View Source BitcoinLib.Block.Header (BitcoinLib v0.4.3)

Represents a Bitcoin block header

Based on https://en.bitcoin.it/wiki/Block_hashing_algorithm

Link to this section Summary

Functions

Converts a hex binary into a %Header{}

Link to this section Functions

@spec decode(<<_::640>>) ::
  {:ok,
   %BitcoinLib.Block.Header{
     bits: term(),
     merkle_root_hash: term(),
     nonce: term(),
     previous_block_hash: term(),
     time: term(),
     version: term()
   }}
  | {:error, binary()}

Converts a hex binary into a %Header{}

examples

Examples

Parse the genesis block's header

iex> "0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c"
...> |> Binary.from_hex()
...> |> BitcoinLib.Block.Header.decode()
{
  :ok,
  %BitcoinLib.Block.Header{
    version: 1,
    previous_block_hash: <<0::256>>,
    merkle_root_hash: <<0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b::256>>,
    time: ~U[2009-01-03 18:15:05Z],
    bits: 486604799,
    nonce: 2083236893
  }
}