ouroboros-network-mock-0.1.1.1: Ouroboros Network Chain for testing purposes
Safe HaskellSafe-Inferred
LanguageHaskell2010

Ouroboros.Network.Mock.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 

Instances

Instances details
Functor Chain Source # 
Instance details

Defined in Ouroboros.Network.Mock.Chain

Methods

fmap ∷ (a → b) → Chain a → Chain b #

(<$) ∷ a → Chain b → Chain a #

Show block ⇒ Show (Chain block) Source # 
Instance details

Defined in Ouroboros.Network.Mock.Chain

Methods

showsPrecIntChain block → ShowS #

showChain block → String #

showList ∷ [Chain block] → ShowS #

Eq block ⇒ Eq (Chain block) Source # 
Instance details

Defined in Ouroboros.Network.Mock.Chain

Methods

(==)Chain block → Chain block → Bool #

(/=)Chain block → Chain block → Bool #

Ord block ⇒ Ord (Chain block) Source # 
Instance details

Defined in Ouroboros.Network.Mock.Chain

Methods

compareChain block → Chain block → Ordering #

(<)Chain block → Chain block → Bool #

(<=)Chain block → Chain block → Bool #

(>)Chain block → Chain block → Bool #

(>=)Chain block → Chain block → Bool #

maxChain block → Chain block → Chain block #

minChain block → Chain block → Chain block #

Serialise block ⇒ Serialise (Chain block) Source # 
Instance details

Defined in Ouroboros.Network.Mock.Chain

Methods

encodeChain block → Encoding Source #

decodeDecoder s (Chain block) Source #

encodeList ∷ [Chain block] → Encoding Source #

decodeListDecoder s [Chain block] Source #

validHasFullHeader block ⇒ Chain block → Bool Source #

validExtension ∷ (HasCallStack, HasFullHeader block) ⇒ Chain block → block → Bool Source #

foldChain ∷ (a → b → a) → a → Chain b → a Source #

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

type family HeaderHash (b ∷ k) Source #

Header hash

Instances

Instances details
type HeaderHash Block Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

type HeaderHash BlockHeader Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

type HeaderHash (HeaderFields b ∷ Type) 
Instance details

Defined in Ouroboros.Network.Block

type HeaderHash (Serialised block ∷ Type) 
Instance details

Defined in Ouroboros.Network.Block

type HeaderHash (Serialised block ∷ Type) = HeaderHash block

Point type

newtype Point (block ∷ k) 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.

Constructors

Point 

Fields

Instances

Instances details
ShowProxy block ⇒ ShowProxy (Point block ∷ Type) 
Instance details

Defined in Ouroboros.Network.Block

Methods

showProxyProxy (Point block) → String Source #

Generic (Point block) 
Instance details

Defined in Ouroboros.Network.Block

Associated Types

type Rep (Point block) ∷ TypeType #

Methods

fromPoint block → Rep (Point block) x #

toRep (Point block) x → Point block #

StandardHash block ⇒ Show (Point block) 
Instance details

Defined in Ouroboros.Network.Block

Methods

showsPrecIntPoint block → ShowS #

showPoint block → String #

showList ∷ [Point block] → ShowS #

StandardHash block ⇒ Eq (Point block) 
Instance details

Defined in Ouroboros.Network.Block

Methods

(==)Point block → Point block → Bool #

(/=)Point block → Point block → Bool #

StandardHash block ⇒ Ord (Point block) 
Instance details

Defined in Ouroboros.Network.Block

Methods

comparePoint block → Point block → Ordering #

(<)Point block → Point block → Bool #

(<=)Point block → Point block → Bool #

(>)Point block → Point block → Bool #

(>=)Point block → Point block → Bool #

maxPoint block → Point block → Point block #

minPoint block → Point block → Point block #

StandardHash block ⇒ NoThunks (Point block) 
Instance details

Defined in Ouroboros.Network.Block

Methods

noThunksContextPoint block → IO (Maybe ThunkInfo) Source #

wNoThunksContextPoint block → IO (Maybe ThunkInfo) Source #

showTypeOfProxy (Point block) → String Source #

Serialise (HeaderHash block) ⇒ Serialise (Point block) 
Instance details

Defined in Ouroboros.Network.Block

Methods

encodePoint block → Encoding Source #

decodeDecoder s (Point block) Source #

encodeList ∷ [Point block] → Encoding Source #

decodeListDecoder s [Point block] Source #

type Rep (Point block) 
Instance details

Defined in Ouroboros.Network.Block

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

blockPointHasHeader block ⇒ block → Point block Source #

Chain construction and inspection

Genesis

Head inspection

headPointHasHeader block ⇒ Chain block → Point block Source #

headSlotHasHeader block ⇒ Chain block → WithOrigin SlotNo Source #

headHashHasHeader block ⇒ Chain block → ChainHash block Source #

headTipHasHeader block ⇒ Chain block → Tip block Source #

headAnchorHasHeader block ⇒ Chain block → Anchor block Source #

Basic operations

headChain b → Maybe b Source #

toNewestFirstChain block → [block] Source #

Produce the list of blocks, from most recent back to genesis

toOldestFirstChain block → [block] Source #

Produce the list of blocks, from genesis to the most recent

fromNewestFirstHasHeader block ⇒ [block] → Chain block Source #

Make a chain from a list of blocks. The head of the list is the head of the chain.

fromOldestFirstHasHeader block ⇒ [block] → Chain block Source #

Construct chain from list of blocks from oldest to newest

dropIntChain block → Chain block Source #

lengthChain block → Int Source #

nullChain block → Bool Source #

takeWhile ∷ (blk → Bool) → Chain blk → Chain blk Source #

Update type and operations

data ChainUpdate (block ∷ k) 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
Foldable (ChainUpdate block) 
Instance details

Defined in Ouroboros.Network.Block

Methods

foldMonoid m ⇒ ChainUpdate block m → m #

foldMapMonoid m ⇒ (a → m) → ChainUpdate block a → m #

foldMap'Monoid m ⇒ (a → m) → ChainUpdate block a → m #

foldr ∷ (a → b → b) → b → ChainUpdate block a → b #

foldr' ∷ (a → b → b) → b → ChainUpdate block a → b #

foldl ∷ (b → a → b) → b → ChainUpdate block a → b #

foldl' ∷ (b → a → b) → b → ChainUpdate block a → b #

foldr1 ∷ (a → a → a) → ChainUpdate block a → a #

foldl1 ∷ (a → a → a) → ChainUpdate block a → a #

toListChainUpdate block a → [a] #

nullChainUpdate block a → Bool #

lengthChainUpdate block a → Int #

elemEq a ⇒ a → ChainUpdate block a → Bool #

maximumOrd a ⇒ ChainUpdate block a → a #

minimumOrd a ⇒ ChainUpdate block a → a #

sumNum a ⇒ ChainUpdate block a → a #

productNum a ⇒ ChainUpdate block a → a #

Traversable (ChainUpdate block) 
Instance details

Defined in Ouroboros.Network.Block

Methods

traverseApplicative f ⇒ (a → f b) → ChainUpdate block a → f (ChainUpdate block b) #

sequenceAApplicative f ⇒ ChainUpdate block (f a) → f (ChainUpdate block a) #

mapMMonad m ⇒ (a → m b) → ChainUpdate block a → m (ChainUpdate block b) #

sequenceMonad m ⇒ ChainUpdate block (m a) → m (ChainUpdate block a) #

Functor (ChainUpdate block) 
Instance details

Defined in Ouroboros.Network.Block

Methods

fmap ∷ (a → b) → ChainUpdate block a → ChainUpdate block b #

(<$) ∷ a → ChainUpdate block b → ChainUpdate block a #

(StandardHash block, Show a) ⇒ Show (ChainUpdate block a) 
Instance details

Defined in Ouroboros.Network.Block

Methods

showsPrecIntChainUpdate block a → ShowS #

showChainUpdate block a → String #

showList ∷ [ChainUpdate block a] → ShowS #

(StandardHash block, Eq a) ⇒ Eq (ChainUpdate block a) 
Instance details

Defined in Ouroboros.Network.Block

Methods

(==)ChainUpdate block a → ChainUpdate block a → Bool #

(/=)ChainUpdate block a → ChainUpdate block a → Bool #

addBlockHasHeader block ⇒ block → Chain block → Chain block Source #

rollbackHasHeader block ⇒ Point block → Chain block → Maybe (Chain block) Source #

applyChainUpdateHasHeader block ⇒ ChainUpdate block block → Chain block → Maybe (Chain block) Source #

applyChainUpdatesHasHeader block ⇒ [ChainUpdate block block] → Chain block → Maybe (Chain block) Source #

Special operations

pointOnChainHasHeader block ⇒ Point block → Chain block → Bool Source #

pointIsAfterHasHeader 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 SlotNos, 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.

successorBlockHasHeader block ⇒ Point block → Chain block → Maybe block Source #

A Just result holds the provided point's successor block. A Nothing result means the provided point was the tip.

The function will error if the point is not on the chain - callers can use pointOnChain to check point membership on a chain in advance of calling this function.

selectChainHasHeader block ⇒ Chain block → Chain block → Chain block Source #

selectPointsHasHeader block ⇒ [Int] → Chain block → [Point block] Source #

Select a bunch of Points 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 #

selectBlockRangeHasHeader block ⇒ Chain block → Point block → Point block → Maybe [block] Source #

findFirstPointHasHeader block ⇒ [Point block] → Chain block → Maybe (Point block) Source #

intersectChainsHasHeader block ⇒ Chain block → Chain block → Maybe (Point block) Source #

isPrefixOfEq block ⇒ Chain block → Chain block → Bool Source #

Conversion to/from AnchoredFragment

fromAnchoredFragmentHasHeader 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.

toAnchoredFragmentHasHeader block ⇒ Chain block → AnchoredFragment block Source #

Convert a Chain to an AnchoredFragment.

The anchor of the fragment will be genesisPoint.

Helper functions

prettyPrintChainString → (block → String) → Chain block → String Source #