-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Utility functions for manipulating bitcoin blocks
--   
--   This library provides functionality for parsing, inspecting, hashing
--   and serialization of bitcoin blocks.
@package bitcoin-block
@version 0.13.1

module Data.Bitcoin.Block

-- | Decodes a hex representation of a transaction into a <a>Block</a>
--   object.
decode :: HexString -> Block

-- | Encodes a <a>Block</a> object into a hex representation.
encode :: Block -> HexString

-- | Calculates the transaction id of a <tt>Transaction</tt> as a
--   <a>HexString</a> so it can be used in RPC interfaces.
headerHash :: Block -> HexString

-- | Data type recording information on a <a>Block</a>. The hash of a block
--   is defined as the hash of this data structure. The block mining
--   process involves finding a partial hash collision by varying the nonce
--   in the <a>BlockHeader</a> and/or additional randomness in the
--   <a>Coinbase</a> of this <a>Block</a>. Variations in the
--   <a>Coinbase</a> will result in different merkle roots in the
--   <a>BlockHeader</a>.
data BlockHeader
BlockHeader :: Word32 -> BlockHash -> Word256 -> Word32 -> Word32 -> Word32 -> BlockHeader

-- | Block version information, based on the version of the software
--   creating this block.
[_blockVersion] :: BlockHeader -> Word32

-- | Hash of the previous block (parent) referenced by this block.
[_prevBlock] :: BlockHeader -> BlockHash

-- | Root of the merkle tree of all transactions pertaining to this block.
[_merkleRoot] :: BlockHeader -> Word256

-- | Unix timestamp recording when this block was created
[_blockTimestamp] :: BlockHeader -> Word32

-- | The difficulty target being used for this block
[_blockBits] :: BlockHeader -> Word32

-- | A random nonce used to generate this block. Additional randomness is
--   included in the coinbase transaction of this block.
[_bhNonce] :: BlockHeader -> Word32
prevBlock :: Lens' BlockHeader BlockHash
merkleRoot :: Lens' BlockHeader Word256
blockVersion :: Lens' BlockHeader Word32
blockTimestamp :: Lens' BlockHeader Word32
blockBits :: Lens' BlockHeader Word32
bhNonce :: Lens' BlockHeader Word32

-- | Data type describing a block in the bitcoin protocol.
data Block
Block :: BlockHeader -> Coinbase -> [Transaction] -> Block

-- | Header information for this block.
[_blockHeader] :: Block -> BlockHeader

-- | Coinbase transaction of this block.
[_blockCoinbaseTx] :: Block -> Coinbase

-- | List of transactions pertaining to this block.
[_blockTxns] :: Block -> [Transaction]
blockTxns :: Lens' Block [Transaction]
blockHeader :: Lens' Block BlockHeader
blockCoinbaseTx :: Lens' Block Coinbase
