ouroboros-network-0.1.0.1: A networking layer for the Ouroboros blockchain protocol
Safe Haskell None
Language Haskell2010

Ouroboros.Network.MockChain.Chain

Description

Reference implementation of a representation of a block chain

Synopsis

Chain type and fundamental operations

data Chain block Source #

Constructors

Genesis
( Chain block) :> block infixl 5

foldChain :: (a -> b -> a) -> a -> Chain b -> a Source #

chainToList :: Chain block -> [block] Source #

Make a list from a Chain , in newest-to-oldest order.

Block re-exports

Point type

newtype Point block Source #

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.

Instances

Instances details
StandardHash block => Eq ( Point block) Source #
Instance details

Defined in Ouroboros.Network.Block

StandardHash block => Ord ( Point block) Source #
Instance details

Defined in Ouroboros.Network.Block

StandardHash block => Show ( Point block) Source #
Instance details

Defined in Ouroboros.Network.Block

Generic ( Point block) Source #
Instance details

Defined in Ouroboros.Network.Block

Associated Types

type Rep ( Point block) :: Type -> Type Source #

StandardHash block => NoThunks ( Point block) Source #
Instance details

Defined in Ouroboros.Network.Block

Serialise ( HeaderHash block) => Serialise ( Point block) Source #
Instance details

Defined in Ouroboros.Network.Block

ShowProxy block => ShowProxy ( Point block :: Type ) Source #
Instance details

Defined in Ouroboros.Network.Block

type Rep ( Point block) Source #
Instance details

Defined in Ouroboros.Network.Block

type Rep ( Point block) = D1 (' MetaData "Point" "Ouroboros.Network.Block" "ouroboros-network-0.1.0.1-2UgqzRSdBh49QYumtriFSI" ' True ) ( C1 (' MetaCons "Point" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "getPoint") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( WithOrigin ( Block SlotNo ( HeaderHash block))))))

Chain construction and inspection

Genesis

Head inspection

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.

Constructors

AddBlock a
RollBack ( Point block)

Instances

Instances details
Functor ( ChainUpdate block) Source #
Instance details

Defined in Ouroboros.Network.Block

Methods

fmap :: (a -> b) -> ChainUpdate block a -> ChainUpdate block b Source #

(<$) :: a -> ChainUpdate block b -> ChainUpdate block a Source #

Foldable ( ChainUpdate block) Source #
Instance details

Defined in Ouroboros.Network.Block

Traversable ( ChainUpdate block) Source #
Instance details

Defined in Ouroboros.Network.Block

( StandardHash block, Eq a) => Eq ( ChainUpdate block a) Source #
Instance details

Defined in Ouroboros.Network.Block

( StandardHash block, Show a) => Show ( ChainUpdate block a) Source #
Instance details

Defined in Ouroboros.Network.Block

addBlock :: HasHeader block => block -> Chain block -> Chain block Source #

Special operations

pointIsAfter :: HasHeader block => Point block -> Point block -> Chain block -> Bool Source #

Check whether the first point is after the second point on the chain. Usually, this can simply be checked using the SlotNo s, but some blocks may have the same SlotNo .

When the first point equals the second point, the answer will be False .

PRECONDITION: both points are on the chain.

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] ])

findBlock :: (block -> Bool ) -> Chain 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 .

Helper functions