Safe Haskell | None |
---|---|
Language | Haskell2010 |
Reference implementation of a representation of a block chain
Synopsis
- data Chain block
- valid :: HasFullHeader block => Chain block -> Bool
- validExtension :: ( HasCallStack , HasFullHeader block) => Chain block -> block -> Bool
- foldChain :: (a -> b -> a) -> a -> Chain b -> a
- chainToList :: Chain block -> [block]
-
class
(
StandardHash
b,
Typeable
b) =>
HasHeader
b
where
- getHeaderFields :: b -> HeaderFields b
- type family HeaderHash b :: Type
-
newtype
Point
block =
Point
{
- getPoint :: WithOrigin ( Block SlotNo ( HeaderHash block))
- blockPoint :: HasHeader block => block -> Point block
- genesis :: Chain b
- headPoint :: HasHeader block => Chain block -> Point block
- headSlot :: HasHeader block => Chain block -> WithOrigin SlotNo
- headHash :: HasHeader block => Chain block -> ChainHash block
- headTip :: HasHeader block => Chain block -> Tip block
- headBlockNo :: HasHeader block => Chain block -> WithOrigin BlockNo
- headAnchor :: HasHeader block => Chain block -> Anchor block
- head :: Chain b -> Maybe b
- toNewestFirst :: Chain block -> [block]
- toOldestFirst :: Chain block -> [block]
- fromNewestFirst :: HasHeader block => [block] -> Chain block
- fromOldestFirst :: HasHeader block => [block] -> Chain block
- drop :: Int -> Chain block -> Chain block
- length :: Chain block -> Int
- null :: Chain block -> Bool
- data ChainUpdate block a
- addBlock :: HasHeader block => block -> Chain block -> Chain block
- rollback :: HasHeader block => Point block -> Chain block -> Maybe ( Chain block)
- applyChainUpdate :: HasHeader block => ChainUpdate block block -> Chain block -> Maybe ( Chain block)
- applyChainUpdates :: HasHeader block => [ ChainUpdate block block] -> Chain block -> Maybe ( Chain block)
- pointOnChain :: HasHeader block => Point block -> Chain block -> Bool
- pointIsAfter :: HasHeader block => Point block -> Point block -> Chain block -> Bool
- successorBlock :: HasHeader block => Point block -> Chain block -> Maybe block
- selectChain :: HasHeader block => Chain block -> Chain block -> Chain block
- selectPoints :: HasHeader block => [ Int ] -> Chain block -> [ Point block]
- findBlock :: (block -> Bool ) -> Chain block -> Maybe block
- selectBlockRange :: HasHeader block => Chain block -> Point block -> Point block -> Maybe [block]
- findFirstPoint :: HasHeader block => [ Point block] -> Chain block -> Maybe ( Point block)
- intersectChains :: HasHeader block => Chain block -> Chain block -> Maybe ( Point block)
- isPrefixOf :: Eq block => Chain block -> Chain block -> Bool
- fromAnchoredFragment :: HasHeader block => AnchoredFragment block -> Maybe ( Chain block)
- toAnchoredFragment :: HasHeader block => Chain block -> AnchoredFragment block
- prettyPrintChain :: String -> (block -> String ) -> Chain block -> String
Chain type and fundamental operations
Instances
Functor Chain Source # | |
Eq block => Eq ( Chain block) Source # | |
Ord block => Ord ( Chain block) Source # | |
Defined in Ouroboros.Network.MockChain.Chain compare :: Chain block -> Chain block -> Ordering Source # (<) :: Chain block -> Chain block -> Bool Source # (<=) :: Chain block -> Chain block -> Bool Source # (>) :: Chain block -> Chain block -> Bool Source # (>=) :: Chain block -> Chain block -> Bool Source # |
|
Show block => Show ( Chain block) Source # | |
Serialise block => Serialise ( Chain block) Source # | |
validExtension :: ( HasCallStack , HasFullHeader block) => Chain block -> block -> Bool Source #
chainToList :: Chain block -> [block] Source #
Make a list from a
Chain
, in newest-to-oldest order.
Block re-exports
class ( StandardHash b, Typeable b) => HasHeader b where Source #
Abstract over the shape of blocks (or indeed just block headers)
getHeaderFields :: b -> HeaderFields b Source #
Instances
HasHeader BlockHeader Source # | |
HasHeader Block Source # | |
Defined in Ouroboros.Network.Testing.ConcreteBlock getHeaderFields :: Block -> HeaderFields Block Source # |
|
( StandardHash b, Typeable b) => HasHeader ( HeaderFields b) Source # | |
Defined in Ouroboros.Network.Block getHeaderFields :: HeaderFields b -> HeaderFields ( HeaderFields b) Source # |
type family HeaderHash b :: Type Source #
Header hash
Instances
type HeaderHash BlockHeader Source # | |
Defined in Ouroboros.Network.Testing.ConcreteBlock |
|
type HeaderHash Block Source # | |
Defined in Ouroboros.Network.Testing.ConcreteBlock |
|
type HeaderHash ( Serialised block) Source # | |
Defined in Ouroboros.Network.Block |
|
type HeaderHash ( HeaderFields b) Source # | |
Defined in Ouroboros.Network.Block |
Point type
A point on the chain is identified by its
Slot
and
HeaderHash
.
The
Slot
tells us where to look and the
HeaderHash
either simply serves
as a check, or in some contexts it disambiguates blocks from different forks
that were in the same slot.
It's a newtype rather than a type synonym, because using a type synonym would lead to ambiguity, since HeaderHash is a non-injective type family.
Point | |
|
Instances
blockPoint :: HasHeader block => block -> Point block Source #
Chain construction and inspection
Genesis
Head inspection
headBlockNo :: HasHeader block => Chain block -> WithOrigin BlockNo Source #
Basic operations
toNewestFirst :: Chain block -> [block] Source #
Produce the list of blocks, from most recent back to genesis
toOldestFirst :: Chain block -> [block] Source #
Produce the list of blocks, from genesis to the most recent
fromNewestFirst :: HasHeader block => [block] -> Chain block Source #
Make a chain from a list of blocks. The head of the list is the head of the chain.
fromOldestFirst :: HasHeader block => [block] -> Chain block Source #
Construct chain from list of blocks from oldest to newest
Update type and operations
data ChainUpdate block a Source #
A representation of two actions to update a chain: add a block or roll back to a previous point.
The type parameter
a
is there to allow a
Functor
instance. Typically,
it will be instantiated with
block
itself.
Instances
applyChainUpdate :: HasHeader block => ChainUpdate block block -> Chain block -> Maybe ( Chain block) Source #
applyChainUpdates :: HasHeader block => [ ChainUpdate block block] -> Chain block -> Maybe ( Chain block) Source #
Special operations
selectPoints :: HasHeader block => [ Int ] -> Chain block -> [ Point block] Source #
Select a bunch of
Point
s based on offsets from the head of the chain.
This is used in the chain consumer protocol as part of finding the
intersection between a local and remote chain.
The typical pattern is to use a selection of offsets covering the last K blocks, biased towards more recent blocks. For example:
selectPoints (0 : [ fib n | n <- [1 .. 17] ])
selectBlockRange :: HasHeader block => Chain block -> Point block -> Point block -> Maybe [block] Source #
Conversion to/from AnchoredFragment
fromAnchoredFragment :: HasHeader block => AnchoredFragment block -> Maybe ( Chain block) Source #
Convert an
AnchoredFragment
to a
Chain
.
The anchor of the fragment must be
genesisPoint
, otherwise
Nothing
is returned.
toAnchoredFragment :: HasHeader block => Chain block -> AnchoredFragment block Source #
Convert a
Chain
to an
AnchoredFragment
.
The anchor of the fragment will be
genesisPoint
.