Copyright | No rights reserved |
---|---|
License | MIT |
Maintainer | jprupp@protonmail.ch |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
Haskoin.Block.Common
Contents
Description
Common data types and functions to handle blocks from the block chain.
Synopsis
- data Block = Block {
- header :: !BlockHeader
- txs :: ![Tx]
- type BlockHeight = Word32
- type Timestamp = Word32
- data BlockHeader = BlockHeader {}
- headerHash :: BlockHeader -> BlockHash
- type BlockLocator = [BlockHash]
- data GetBlocks = GetBlocks {}
- data GetHeaders = GetHeaders {}
- type BlockHeaderCount = (BlockHeader, VarInt)
- newtype BlockHash = BlockHash {}
- blockHashToHex :: BlockHash -> Text
- hexToBlockHash :: Text -> Maybe BlockHash
- newtype Headers = Headers {
- list :: [BlockHeaderCount]
- decodeCompact :: Word32 -> (Integer, Bool)
- encodeCompact :: Integer -> Word32
Blocks
Block header and transactions.
Constructors
Block | |
Fields
|
Instances
type BlockHeight = Word32 Source #
Height of a block in the block chain, starting at 0 for Genesis.
data BlockHeader Source #
Data type recording information of a Block
. The hash of a block is
defined as the hash of this data structure, serialized. The block mining
process involves finding a partial hash collision by varying the nonce in the
BlockHeader
and/or additional entropy in the coinbase Transaction
of this
Block
. Variations in the coinbase will result in different merkle roots in
the BlockHeader
.
Constructors
BlockHeader | |
Instances
FromJSON BlockHeader Source # | |||||
Defined in Haskoin.Block.Common | |||||
ToJSON BlockHeader Source # | |||||
Defined in Haskoin.Block.Common Methods toJSON :: BlockHeader -> Value # toEncoding :: BlockHeader -> Encoding # toJSONList :: [BlockHeader] -> Value # toEncodingList :: [BlockHeader] -> Encoding # omitField :: BlockHeader -> Bool # | |||||
Generic BlockHeader Source # | |||||
Defined in Haskoin.Block.Common Associated Types
| |||||
Read BlockHeader Source # | |||||
Defined in Haskoin.Block.Common Methods readsPrec :: Int -> ReadS BlockHeader # readList :: ReadS [BlockHeader] # readPrec :: ReadPrec BlockHeader # readListPrec :: ReadPrec [BlockHeader] # | |||||
Show BlockHeader Source # | |||||
Defined in Haskoin.Block.Common Methods showsPrec :: Int -> BlockHeader -> ShowS # show :: BlockHeader -> String # showList :: [BlockHeader] -> ShowS # | |||||
Binary BlockHeader Source # | |||||
Defined in Haskoin.Block.Common | |||||
Serial BlockHeader Source # | |||||
Defined in Haskoin.Block.Common | |||||
Serialize BlockHeader Source # | |||||
Defined in Haskoin.Block.Common | |||||
NFData BlockHeader Source # | |||||
Defined in Haskoin.Block.Common Methods rnf :: BlockHeader -> () # | |||||
Eq BlockHeader Source # | |||||
Defined in Haskoin.Block.Common | |||||
Ord BlockHeader Source # | |||||
Defined in Haskoin.Block.Common Methods compare :: BlockHeader -> BlockHeader -> Ordering # (<) :: BlockHeader -> BlockHeader -> Bool # (<=) :: BlockHeader -> BlockHeader -> Bool # (>) :: BlockHeader -> BlockHeader -> Bool # (>=) :: BlockHeader -> BlockHeader -> Bool # max :: BlockHeader -> BlockHeader -> BlockHeader # min :: BlockHeader -> BlockHeader -> BlockHeader # | |||||
Hashable BlockHeader Source # | |||||
Defined in Haskoin.Block.Common | |||||
type Rep BlockHeader Source # | |||||
Defined in Haskoin.Block.Common type Rep BlockHeader = D1 ('MetaData "BlockHeader" "Haskoin.Block.Common" "haskoin-core-1.2.2-IqsPTB3lyDG9ChtLlvwlSX" 'False) (C1 ('MetaCons "BlockHeader" 'PrefixI 'True) ((S1 ('MetaSel ('Just "version") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: (S1 ('MetaSel ('Just "prev") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 BlockHash) :*: S1 ('MetaSel ('Just "merkle") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Hash256))) :*: (S1 ('MetaSel ('Just "timestamp") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Timestamp) :*: (S1 ('MetaSel ('Just "bits") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: S1 ('MetaSel ('Just "nonce") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word32))))) |
headerHash :: BlockHeader -> BlockHash Source #
Compute hash of BlockHeader
.
type BlockLocator = [BlockHash] Source #
A block locator is a set of block headers, denser towards the best block and sparser towards the genesis block. It starts at the highest block known. It is used by a node to synchronize against the network. When the locator is provided to a peer, it will send back block hashes starting from the first block in the locator that it recognizes.
Data type representing a getblocks message request. It is used in the
bitcoin protocol to retrieve blocks from a peer by providing it a
BlockLocator
object. The response to a GetBlocks
message is an Inv
message containing a list of block hashes that the peer believes this node is
missing. The number of block hashes in that inv message will end at the stop
block hash, at at the tip of the chain, or after 500 entries, whichever comes
earlier.
Constructors
GetBlocks | |
Instances
Generic GetBlocks Source # | |||||
Defined in Haskoin.Block.Common Associated Types
| |||||
Read GetBlocks Source # | |||||
Show GetBlocks Source # | |||||
Serial GetBlocks Source # | |||||
Defined in Haskoin.Block.Common | |||||
Serialize GetBlocks Source # | |||||
NFData GetBlocks Source # | |||||
Defined in Haskoin.Block.Common | |||||
Eq GetBlocks Source # | |||||
type Rep GetBlocks Source # | |||||
Defined in Haskoin.Block.Common type Rep GetBlocks = D1 ('MetaData "GetBlocks" "Haskoin.Block.Common" "haskoin-core-1.2.2-IqsPTB3lyDG9ChtLlvwlSX" 'False) (C1 ('MetaCons "GetBlocks" 'PrefixI 'True) (S1 ('MetaSel ('Just "version") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: (S1 ('MetaSel ('Just "locator") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 BlockLocator) :*: S1 ('MetaSel ('Just "stop") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 BlockHash)))) |
data GetHeaders Source #
Similar to the GetBlocks
message type but for retrieving block headers
only. The response to a GetHeaders
request is a Headers
message
containing a list of block headers. A maximum of 2000 block headers can be
returned. GetHeaders
is used by simplified payment verification (SPV)
clients to exclude block contents when synchronizing the block chain.
Constructors
GetHeaders | |
Instances
Generic GetHeaders Source # | |||||
Defined in Haskoin.Block.Common Associated Types
| |||||
Read GetHeaders Source # | |||||
Defined in Haskoin.Block.Common Methods readsPrec :: Int -> ReadS GetHeaders # readList :: ReadS [GetHeaders] # readPrec :: ReadPrec GetHeaders # readListPrec :: ReadPrec [GetHeaders] # | |||||
Show GetHeaders Source # | |||||
Defined in Haskoin.Block.Common Methods showsPrec :: Int -> GetHeaders -> ShowS # show :: GetHeaders -> String # showList :: [GetHeaders] -> ShowS # | |||||
Binary GetHeaders Source # | |||||
Defined in Haskoin.Block.Common | |||||
Serial GetHeaders Source # | |||||
Defined in Haskoin.Block.Common | |||||
Serialize GetHeaders Source # | |||||
Defined in Haskoin.Block.Common | |||||
NFData GetHeaders Source # | |||||
Defined in Haskoin.Block.Common Methods rnf :: GetHeaders -> () # | |||||
Eq GetHeaders Source # | |||||
Defined in Haskoin.Block.Common | |||||
type Rep GetHeaders Source # | |||||
Defined in Haskoin.Block.Common type Rep GetHeaders = D1 ('MetaData "GetHeaders" "Haskoin.Block.Common" "haskoin-core-1.2.2-IqsPTB3lyDG9ChtLlvwlSX" 'False) (C1 ('MetaCons "GetHeaders" 'PrefixI 'True) (S1 ('MetaSel ('Just "version") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: (S1 ('MetaSel ('Just "locator") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 BlockLocator) :*: S1 ('MetaSel ('Just "stop") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 BlockHash)))) |
type BlockHeaderCount = (BlockHeader, VarInt) Source #
BlockHeader
type with a transaction count as VarInt
Block header hash. To be serialized reversed for display purposes.
Instances
FromJSON BlockHash Source # | |||||
Defined in Haskoin.Block.Common | |||||
ToJSON BlockHash Source # | |||||
IsString BlockHash Source # | |||||
Defined in Haskoin.Block.Common Methods fromString :: String -> BlockHash # | |||||
Generic BlockHash Source # | |||||
Defined in Haskoin.Block.Common Associated Types
| |||||
Read BlockHash Source # | |||||
Show BlockHash Source # | |||||
Binary BlockHash Source # | |||||
Serial BlockHash Source # | |||||
Defined in Haskoin.Block.Common | |||||
Serialize BlockHash Source # | |||||
NFData BlockHash Source # | |||||
Defined in Haskoin.Block.Common | |||||
Eq BlockHash Source # | |||||
Ord BlockHash Source # | |||||
Hashable BlockHash Source # | |||||
Defined in Haskoin.Block.Common | |||||
type Rep BlockHash Source # | |||||
Defined in Haskoin.Block.Common |
blockHashToHex :: BlockHash -> Text Source #
Block hashes are reversed with respect to the in-memory byte order in a block hash when displayed.
hexToBlockHash :: Text -> Maybe BlockHash Source #
Convert a human-readable hex block hash into a BlockHash
. Bytes are
reversed as normal.
The Headers
type is used to return a list of block headers in
response to a GetHeaders
message.
Constructors
Headers | |
Fields
|
Instances
Generic Headers Source # | |||||
Defined in Haskoin.Block.Common Associated Types
| |||||
Read Headers Source # | |||||
Show Headers Source # | |||||
Binary Headers Source # | |||||
Serial Headers Source # | |||||
Defined in Haskoin.Block.Common | |||||
Serialize Headers Source # | |||||
NFData Headers Source # | |||||
Defined in Haskoin.Block.Common | |||||
Eq Headers Source # | |||||
type Rep Headers Source # | |||||
Defined in Haskoin.Block.Common type Rep Headers = D1 ('MetaData "Headers" "Haskoin.Block.Common" "haskoin-core-1.2.2-IqsPTB3lyDG9ChtLlvwlSX" 'True) (C1 ('MetaCons "Headers" 'PrefixI 'True) (S1 ('MetaSel ('Just "list") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [BlockHeaderCount]))) |
Decode the compact number used in the difficulty target of a block.
The compact format is a representation of a whole number \(N\) using an unsigned 32-bit number similar to a floating point format. The most significant 8 bits are the unsigned exponent of base 256. This exponent can be thought of as the number of bytes of \(N\). The lower 23 bits are the mantissa. Bit number 24 represents the sign of \(N\).
\[ N = -1^{sign} \times mantissa \times 256^{exponent-3} \]