ouroboros-consensus-0.1.0.1: Consensus layer for the Ouroboros blockchain protocol
Safe Haskell None
Language Haskell2010

Ouroboros.Consensus.Util.Versioned

Contents

Synopsis

Documentation

data VersionDecoder a where Source #

How to decode a version of a format.

Constructors

Incompatible :: String -> VersionDecoder a

This version is incompatible, fail with IncompatibleVersion and the given message.

Decode :: ( forall s. Decoder s a) -> VersionDecoder a

Decode the version using the given Decoder .

Migrate :: VersionDecoder from -> (from -> Either String to) -> VersionDecoder to

Decode an other format ( from ) and migrate from that. When migration fails, the version decoder will fail with MigrationFailed .

decodeVersion :: [( VersionNumber , VersionDecoder a)] -> forall s. Decoder s a Source #

Decode a versioned a (encoded using encodeVersion or encodeVersioned ).

The corresponding VersionDecoder for the deserialised VersionNumber is looked up in the given list. The first match is used (using the semantics of lookup ). When no match is found, a decoder that fails with UnknownVersion is returned.

decodeVersionWithHook :: forall a. ( forall s. Maybe Int -> Decoder s a) -> [( VersionNumber , VersionDecoder a)] -> forall s. Decoder s a Source #

Same as decodeVersion , but with a hook that gets called in case the encoding was not produced by a versioned encoder. This allows a transition from non-versioned to versioned encodings.

Versioned encodings start with list length 2. Whenever the encoding starts this way, this decoder will use the regular versioned decoder. When the encoding starts differently, either with a different list length ( Just as argument) or with another token ( Nothing as argument), the hook is called, allowing the previous non-versioned decoder to try to decode the encoding.

Note that the hook should not try to decode the list length again .

Note that this will not work if the previous encoding can start with list length 2, as the new versioned decoder will be called in those cases, not the hook.

encodeVersion :: VersionNumber -> Encoding -> Encoding Source #

Given a VersionNumber and the encoding of an a , encode the corresponding Versioned a . Use decodeVersion to decode it.

opaque

data VersionNumber Source #

Instances

Instances details
Eq VersionNumber Source #
Instance details

Defined in Ouroboros.Consensus.Util.Versioned

Num VersionNumber Source #
Instance details

Defined in Ouroboros.Consensus.Util.Versioned

Ord VersionNumber Source #
Instance details

Defined in Ouroboros.Consensus.Util.Versioned

Show VersionNumber Source #
Instance details

Defined in Ouroboros.Consensus.Util.Versioned

Serialise VersionNumber Source #
Instance details

Defined in Ouroboros.Consensus.Util.Versioned