bitcoin-elixir v0.0.1 Bitcoin.Protocol.Messages.Block

The block message is sent in response to a getdata message which requests transaction information from a block hash.

The SHA256 hash that identifies each block (and which must have a run of 0 bits) is calculated from the first 6 fields of this structure (version, prev_block, merkle_root, timestamp, bits, nonce, and standard SHA256 padding, making two 64-byte chunks in all) and not from the complete block. To calculate the hash, only two chunks need to be processed by the SHA256 algorithm. Since the nonce field is in the second chunk, the first chunk stays constant during mining and therefore only the second chunk needs to be processed. However, a Bitcoin hash is the hash of the hash, so two SHA256 rounds are needed for each mining iteration. See Block hashing algorithm https://en.bitcoin.it/wiki/Block_hashing_algorithm for details and an example.

https://en.bitcoin.it/wiki/Protocol_documentation#block

Summary

Types

t()
t() :: %Bitcoin.Protocol.Messages.Block{bits: non_neg_integer, merkle_root: Bitcoin.t_hash, nonce: non_neg_integer, previous_block: Bitcoin.Block.t_hash, timestamp: non_neg_integer, transactions: [Bitcoin.Protocol.Messages.Tx], version: integer}

Functions

header(block)
parse(data)
parse(binary) :: t
serialize(s)
serialize(t) :: binary
serialize_header(s)