{-# LANGUAGE DataKinds #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}

{-# OPTIONS_GHC -Wno-orphans #-}

module Ouroboros.Consensus.HardFork.Combinator.Serialisation.SerialiseNodeToClient () where

import           Cardano.Binary (enforceSize)
import           Codec.CBOR.Decoding (Decoder)
import qualified Codec.CBOR.Decoding as Dec
import           Codec.CBOR.Encoding (Encoding)
import qualified Codec.CBOR.Encoding as Enc
import qualified Codec.Serialise as Serialise
import           Control.Exception (throw)
import           Data.Proxy
import           Data.SOP.BasicFunctors
import           Data.SOP.Constraint
import           Data.SOP.NonEmpty (ProofNonEmpty (..), checkIsNonEmpty,
                     isNonEmpty)
import           Data.SOP.Strict
import           Ouroboros.Consensus.Block
import           Ouroboros.Consensus.HardFork.Combinator.Abstract.SingleEraBlock
import           Ouroboros.Consensus.HardFork.Combinator.AcrossEras
import           Ouroboros.Consensus.HardFork.Combinator.Basics
import           Ouroboros.Consensus.HardFork.Combinator.Ledger.Query
import           Ouroboros.Consensus.HardFork.Combinator.Mempool
import           Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common
import           Ouroboros.Consensus.HardFork.Combinator.Serialisation.SerialiseDisk ()
import           Ouroboros.Consensus.HardFork.History (EraParamsFormat (..))
import           Ouroboros.Consensus.Ledger.SupportsMempool (GenTxId)
import           Ouroboros.Consensus.Node.NetworkProtocolVersion
import           Ouroboros.Consensus.Node.Run
import           Ouroboros.Consensus.Node.Serialisation
import           Ouroboros.Consensus.Util ((.:))
import           Ouroboros.Network.Block (Serialised, unwrapCBORinCBOR,
                     wrapCBORinCBOR)

instance SerialiseHFC xs => SerialiseNodeToClientConstraints (HardForkBlock xs)

{-------------------------------------------------------------------------------
  Dispatch to first era or HFC
-------------------------------------------------------------------------------}

dispatchEncoder :: forall f xs. (
                     SerialiseHFC xs
                   , forall blk. SerialiseNodeToClientConstraints blk
                              => SerialiseNodeToClient blk (f blk)
                   )
                => CodecConfig (HardForkBlock xs)
                -> BlockNodeToClientVersion (HardForkBlock xs)
                -> NS f xs -> Encoding
dispatchEncoder :: forall (f :: * -> *) (xs :: [*]).
(SerialiseHFC xs,
 forall blk.
 SerialiseNodeToClientConstraints blk =>
 SerialiseNodeToClient blk (f blk)) =>
CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> NS f xs
-> Encoding
dispatchEncoder CodecConfig (HardForkBlock xs)
ccfg BlockNodeToClientVersion (HardForkBlock xs)
version NS f xs
ns =
    case Proxy xs -> ProofNonEmpty xs
forall {a} (xs :: [a]) (proxy :: [a] -> *).
IsNonEmpty xs =>
proxy xs -> ProofNonEmpty xs
forall (proxy :: [*] -> *). proxy xs -> ProofNonEmpty xs
isNonEmpty (forall (t :: [*]). Proxy t
forall {k} (t :: k). Proxy t
Proxy @xs) of
      ProofNonEmpty {} ->
        case (NP CodecConfig xs
ccfgs, BlockNodeToClientVersion (HardForkBlock xs)
HardForkNodeToClientVersion xs
version, NS f xs
ns) of
          (CodecConfig x
c0 :* NP CodecConfig xs1
_, HardForkNodeToClientDisabled BlockNodeToClientVersion x
v0, Z f x
x0) ->
            CodecConfig x -> BlockNodeToClientVersion x -> f x -> Encoding
forall blk a.
SerialiseNodeToClient blk a =>
CodecConfig blk -> BlockNodeToClientVersion blk -> a -> Encoding
encodeNodeToClient CodecConfig x
c0 BlockNodeToClientVersion x
BlockNodeToClientVersion x
v0 f x
x0
          (NP CodecConfig xs
_, HardForkNodeToClientDisabled BlockNodeToClientVersion x
_, S NS f xs1
later) ->
            HardForkEncoderException -> Encoding
forall a e. Exception e => e -> a
throw (HardForkEncoderException -> Encoding)
-> HardForkEncoderException -> Encoding
forall a b. (a -> b) -> a -> b
$ NS SingleEraInfo xs1 -> HardForkEncoderException
forall (xs :: [*]).
SListI xs =>
NS SingleEraInfo xs -> HardForkEncoderException
futureEraException (NS f xs1 -> NS SingleEraInfo xs1
forall (xs :: [*]) (f :: * -> *).
All SingleEraBlock xs =>
NS f xs -> NS SingleEraInfo xs
notFirstEra NS f xs1
later)
          (NP CodecConfig xs
_, HardForkNodeToClientEnabled HardForkSpecificNodeToClientVersion
_ NP EraNodeToClientVersion xs
versions, NS f xs
_) ->
            NP (f -.-> K Encoding) xs -> NS f xs -> Encoding
forall (xs :: [*]) (f :: * -> *).
SListI xs =>
NP (f -.-> K Encoding) xs -> NS f xs -> Encoding
encodeNS (Proxy SerialiseConstraintsHFC
-> (forall a.
    SerialiseConstraintsHFC a =>
    CodecConfig a
    -> EraNodeToClientVersion a -> (-.->) f (K Encoding) a)
-> Prod NP CodecConfig xs
-> NP EraNodeToClientVersion xs
-> NP (f -.-> K Encoding) xs
forall {k} {l} (h :: (k -> *) -> l -> *) (c :: k -> Constraint)
       (xs :: l) (proxy :: (k -> Constraint) -> *) (f :: k -> *)
       (f' :: k -> *) (f'' :: k -> *).
(AllN (Prod h) c xs, HAp h, HAp (Prod h)) =>
proxy c
-> (forall (a :: k). c a => f a -> f' a -> f'' a)
-> Prod h f xs
-> h f' xs
-> h f'' xs
hczipWith Proxy SerialiseConstraintsHFC
pSHFC CodecConfig a
-> EraNodeToClientVersion a -> (-.->) f (K Encoding) a
forall blk.
(SingleEraBlock blk, SerialiseNodeToClientConstraints blk) =>
CodecConfig blk
-> EraNodeToClientVersion blk -> (-.->) f (K Encoding) blk
forall a.
SerialiseConstraintsHFC a =>
CodecConfig a
-> EraNodeToClientVersion a -> (-.->) f (K Encoding) a
aux Prod NP CodecConfig xs
NP CodecConfig xs
ccfgs NP EraNodeToClientVersion xs
versions) NS f xs
ns
  where
    ccfgs :: NP CodecConfig xs
ccfgs = PerEraCodecConfig xs -> NP CodecConfig xs
forall (xs :: [*]). PerEraCodecConfig xs -> NP CodecConfig xs
getPerEraCodecConfig (PerEraCodecConfig xs -> NP CodecConfig xs)
-> PerEraCodecConfig xs -> NP CodecConfig xs
forall a b. (a -> b) -> a -> b
$ CodecConfig (HardForkBlock xs) -> PerEraCodecConfig xs
forall (xs :: [*]).
CodecConfig (HardForkBlock xs) -> PerEraCodecConfig xs
hardForkCodecConfigPerEra CodecConfig (HardForkBlock xs)
ccfg

    aux :: forall blk. (SingleEraBlock blk, SerialiseNodeToClientConstraints blk)
        => CodecConfig blk
        -> EraNodeToClientVersion blk
        -> (f -.-> K Encoding) blk
    aux :: forall blk.
(SingleEraBlock blk, SerialiseNodeToClientConstraints blk) =>
CodecConfig blk
-> EraNodeToClientVersion blk -> (-.->) f (K Encoding) blk
aux CodecConfig blk
ccfg' (EraNodeToClientEnabled BlockNodeToClientVersion blk
v) = (f blk -> K Encoding blk) -> (-.->) f (K Encoding) blk
forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
(f a -> g a) -> (-.->) f g a
Fn ((f blk -> K Encoding blk) -> (-.->) f (K Encoding) blk)
-> (f blk -> K Encoding blk) -> (-.->) f (K Encoding) blk
forall a b. (a -> b) -> a -> b
$ Encoding -> K Encoding blk
forall k a (b :: k). a -> K a b
K (Encoding -> K Encoding blk)
-> (f blk -> Encoding) -> f blk -> K Encoding blk
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CodecConfig blk
-> BlockNodeToClientVersion blk -> f blk -> Encoding
forall blk a.
SerialiseNodeToClient blk a =>
CodecConfig blk -> BlockNodeToClientVersion blk -> a -> Encoding
encodeNodeToClient CodecConfig blk
ccfg' BlockNodeToClientVersion blk
v
    aux CodecConfig blk
_      EraNodeToClientVersion blk
EraNodeToClientDisabled   = (f blk -> K Encoding blk) -> (-.->) f (K Encoding) blk
forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
(f a -> g a) -> (-.->) f g a
Fn ((f blk -> K Encoding blk) -> (-.->) f (K Encoding) blk)
-> (f blk -> K Encoding blk) -> (-.->) f (K Encoding) blk
forall a b. (a -> b) -> a -> b
$ \f blk
_ ->
        HardForkEncoderException -> K Encoding blk
forall a e. Exception e => e -> a
throw (HardForkEncoderException -> K Encoding blk)
-> HardForkEncoderException -> K Encoding blk
forall a b. (a -> b) -> a -> b
$ Proxy blk -> HardForkEncoderException
forall blk.
SingleEraBlock blk =>
Proxy blk -> HardForkEncoderException
disabledEraException (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @blk)

dispatchDecoder :: forall f xs. (
                     SerialiseHFC xs
                   , forall blk. SerialiseNodeToClientConstraints blk
                              => SerialiseNodeToClient blk (f blk)
                   )
                => CodecConfig (HardForkBlock xs)
                -> BlockNodeToClientVersion (HardForkBlock xs)
                -> forall s. Decoder s (NS f xs)
dispatchDecoder :: forall (f :: * -> *) (xs :: [*]).
(SerialiseHFC xs,
 forall blk.
 SerialiseNodeToClientConstraints blk =>
 SerialiseNodeToClient blk (f blk)) =>
CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> forall s. Decoder s (NS f xs)
dispatchDecoder CodecConfig (HardForkBlock xs)
ccfg BlockNodeToClientVersion (HardForkBlock xs)
version =
    case Proxy xs -> ProofNonEmpty xs
forall {a} (xs :: [a]) (proxy :: [a] -> *).
IsNonEmpty xs =>
proxy xs -> ProofNonEmpty xs
forall (proxy :: [*] -> *). proxy xs -> ProofNonEmpty xs
isNonEmpty (forall (t :: [*]). Proxy t
forall {k} (t :: k). Proxy t
Proxy @xs) of
      ProofNonEmpty {} ->
        case (NP CodecConfig xs
ccfgs, BlockNodeToClientVersion (HardForkBlock xs)
HardForkNodeToClientVersion xs
version) of
          (CodecConfig x
c0 :* NP CodecConfig xs1
_, HardForkNodeToClientDisabled BlockNodeToClientVersion x
v0) ->
            f x -> NS f xs
f x -> NS f (x : xs1)
forall {k} (f :: k -> *) (x :: k) (xs1 :: [k]).
f x -> NS f (x : xs1)
Z (f x -> NS f xs) -> Decoder s (f x) -> Decoder s (NS f xs)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CodecConfig x
-> BlockNodeToClientVersion x -> forall s. Decoder s (f x)
forall blk a.
SerialiseNodeToClient blk a =>
CodecConfig blk
-> BlockNodeToClientVersion blk -> forall s. Decoder s a
decodeNodeToClient CodecConfig x
c0 BlockNodeToClientVersion x
BlockNodeToClientVersion x
v0
          (NP CodecConfig xs
_, HardForkNodeToClientEnabled HardForkSpecificNodeToClientVersion
_ NP EraNodeToClientVersion xs
versions) ->
            NP (Decoder s :.: f) xs -> Decoder s (NS f xs)
forall (xs :: [*]) s (f :: * -> *).
SListI xs =>
NP (Decoder s :.: f) xs -> Decoder s (NS f xs)
decodeNS (Proxy SerialiseConstraintsHFC
-> (forall a.
    SerialiseConstraintsHFC a =>
    CodecConfig a -> EraNodeToClientVersion a -> (:.:) (Decoder s) f a)
-> Prod NP CodecConfig xs
-> NP EraNodeToClientVersion xs
-> NP (Decoder s :.: f) xs
forall {k} {l} (h :: (k -> *) -> l -> *) (c :: k -> Constraint)
       (xs :: l) (proxy :: (k -> Constraint) -> *) (f :: k -> *)
       (f' :: k -> *) (f'' :: k -> *).
(AllN (Prod h) c xs, HAp h, HAp (Prod h)) =>
proxy c
-> (forall (a :: k). c a => f a -> f' a -> f'' a)
-> Prod h f xs
-> h f' xs
-> h f'' xs
hczipWith Proxy SerialiseConstraintsHFC
pSHFC CodecConfig a -> EraNodeToClientVersion a -> (:.:) (Decoder s) f a
CodecConfig a
-> EraNodeToClientVersion a -> forall s. (:.:) (Decoder s) f a
forall blk.
(SingleEraBlock blk, SerialiseNodeToClientConstraints blk) =>
CodecConfig blk
-> EraNodeToClientVersion blk -> forall s. (:.:) (Decoder s) f blk
forall a.
SerialiseConstraintsHFC a =>
CodecConfig a -> EraNodeToClientVersion a -> (:.:) (Decoder s) f a
aux Prod NP CodecConfig xs
NP CodecConfig xs
ccfgs NP EraNodeToClientVersion xs
versions)
  where
    ccfgs :: NP CodecConfig xs
ccfgs = PerEraCodecConfig xs -> NP CodecConfig xs
forall (xs :: [*]). PerEraCodecConfig xs -> NP CodecConfig xs
getPerEraCodecConfig (PerEraCodecConfig xs -> NP CodecConfig xs)
-> PerEraCodecConfig xs -> NP CodecConfig xs
forall a b. (a -> b) -> a -> b
$ CodecConfig (HardForkBlock xs) -> PerEraCodecConfig xs
forall (xs :: [*]).
CodecConfig (HardForkBlock xs) -> PerEraCodecConfig xs
hardForkCodecConfigPerEra CodecConfig (HardForkBlock xs)
ccfg

    aux :: forall blk. (SingleEraBlock blk, SerialiseNodeToClientConstraints blk)
        => CodecConfig blk
        -> EraNodeToClientVersion blk
        -> forall s. (Decoder s :.: f) blk
    aux :: forall blk.
(SingleEraBlock blk, SerialiseNodeToClientConstraints blk) =>
CodecConfig blk
-> EraNodeToClientVersion blk -> forall s. (:.:) (Decoder s) f blk
aux CodecConfig blk
ccfg' (EraNodeToClientEnabled BlockNodeToClientVersion blk
v) = Decoder s (f blk) -> (:.:) (Decoder s) f blk
forall l k (f :: l -> *) (g :: k -> l) (p :: k).
f (g p) -> (:.:) f g p
Comp (Decoder s (f blk) -> (:.:) (Decoder s) f blk)
-> Decoder s (f blk) -> (:.:) (Decoder s) f blk
forall a b. (a -> b) -> a -> b
$ CodecConfig blk
-> BlockNodeToClientVersion blk -> forall s. Decoder s (f blk)
forall blk a.
SerialiseNodeToClient blk a =>
CodecConfig blk
-> BlockNodeToClientVersion blk -> forall s. Decoder s a
decodeNodeToClient CodecConfig blk
ccfg' BlockNodeToClientVersion blk
v
    aux CodecConfig blk
_      EraNodeToClientVersion blk
EraNodeToClientDisabled   = Decoder s (f blk) -> (:.:) (Decoder s) f blk
forall l k (f :: l -> *) (g :: k -> l) (p :: k).
f (g p) -> (:.:) f g p
Comp (Decoder s (f blk) -> (:.:) (Decoder s) f blk)
-> Decoder s (f blk) -> (:.:) (Decoder s) f blk
forall a b. (a -> b) -> a -> b
$
        String -> Decoder s (f blk)
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Decoder s (f blk))
-> (HardForkEncoderException -> String)
-> HardForkEncoderException
-> Decoder s (f blk)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HardForkEncoderException -> String
forall a. Show a => a -> String
show (HardForkEncoderException -> Decoder s (f blk))
-> HardForkEncoderException -> Decoder s (f blk)
forall a b. (a -> b) -> a -> b
$ Proxy blk -> HardForkEncoderException
forall blk.
SingleEraBlock blk =>
Proxy blk -> HardForkEncoderException
disabledEraException (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @blk)

dispatchEncoderErr :: forall f xs. (
                        SerialiseHFC xs
                      , forall blk. SerialiseNodeToClientConstraints blk
                                 => SerialiseNodeToClient blk (f blk)
                      )
                   => CodecConfig (HardForkBlock xs)
                   -> BlockNodeToClientVersion (HardForkBlock xs)
                   -> Either (MismatchEraInfo xs) (NS f xs) -> Encoding
dispatchEncoderErr :: forall (f :: * -> *) (xs :: [*]).
(SerialiseHFC xs,
 forall blk.
 SerialiseNodeToClientConstraints blk =>
 SerialiseNodeToClient blk (f blk)) =>
CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> Either (MismatchEraInfo xs) (NS f xs)
-> Encoding
dispatchEncoderErr CodecConfig (HardForkBlock xs)
ccfg BlockNodeToClientVersion (HardForkBlock xs)
version =
    BlockNodeToClientVersion (HardForkBlock xs)
-> (NS f xs -> Encoding)
-> Either (MismatchEraInfo xs) (NS f xs)
-> Encoding
forall (xs :: [*]) a.
SListI xs =>
BlockNodeToClientVersion (HardForkBlock xs)
-> (a -> Encoding) -> Either (MismatchEraInfo xs) a -> Encoding
encodeEitherMismatch BlockNodeToClientVersion (HardForkBlock xs)
version ((NS f xs -> Encoding)
 -> Either (MismatchEraInfo xs) (NS f xs) -> Encoding)
-> (NS f xs -> Encoding)
-> Either (MismatchEraInfo xs) (NS f xs)
-> Encoding
forall a b. (a -> b) -> a -> b
$
      CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> NS f xs
-> Encoding
forall (f :: * -> *) (xs :: [*]).
(SerialiseHFC xs,
 forall blk.
 SerialiseNodeToClientConstraints blk =>
 SerialiseNodeToClient blk (f blk)) =>
CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> NS f xs
-> Encoding
dispatchEncoder CodecConfig (HardForkBlock xs)
ccfg BlockNodeToClientVersion (HardForkBlock xs)
version

dispatchDecoderErr :: forall f xs. (
                        SerialiseHFC xs
                      , forall blk. SerialiseNodeToClientConstraints blk
                                 => SerialiseNodeToClient blk (f blk)
                      )
                   => CodecConfig (HardForkBlock xs)
                   -> BlockNodeToClientVersion (HardForkBlock xs)
                   -> forall s. Decoder s (Either (MismatchEraInfo xs) (NS f xs))
dispatchDecoderErr :: forall (f :: * -> *) (xs :: [*]).
(SerialiseHFC xs,
 forall blk.
 SerialiseNodeToClientConstraints blk =>
 SerialiseNodeToClient blk (f blk)) =>
CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> forall s. Decoder s (Either (MismatchEraInfo xs) (NS f xs))
dispatchDecoderErr CodecConfig (HardForkBlock xs)
ccfg BlockNodeToClientVersion (HardForkBlock xs)
version =
    BlockNodeToClientVersion (HardForkBlock xs)
-> Decoder s (NS f xs)
-> Decoder s (Either (MismatchEraInfo xs) (NS f xs))
forall (xs :: [*]) s a.
SListI xs =>
BlockNodeToClientVersion (HardForkBlock xs)
-> Decoder s a -> Decoder s (Either (MismatchEraInfo xs) a)
decodeEitherMismatch BlockNodeToClientVersion (HardForkBlock xs)
version (Decoder s (NS f xs)
 -> Decoder s (Either (MismatchEraInfo xs) (NS f xs)))
-> Decoder s (NS f xs)
-> Decoder s (Either (MismatchEraInfo xs) (NS f xs))
forall a b. (a -> b) -> a -> b
$
      CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> forall s. Decoder s (NS f xs)
forall (f :: * -> *) (xs :: [*]).
(SerialiseHFC xs,
 forall blk.
 SerialiseNodeToClientConstraints blk =>
 SerialiseNodeToClient blk (f blk)) =>
CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> forall s. Decoder s (NS f xs)
dispatchDecoder CodecConfig (HardForkBlock xs)
ccfg BlockNodeToClientVersion (HardForkBlock xs)
version

after :: (a -> b -> d -> e) -> (c -> d) -> a -> b -> c -> e
after :: forall a b d e c.
(a -> b -> d -> e) -> (c -> d) -> a -> b -> c -> e
after a -> b -> d -> e
f c -> d
g a
x b
y c
z = a -> b -> d -> e
f a
x b
y (c -> d
g c
z)

{-------------------------------------------------------------------------------
  Blocks
-------------------------------------------------------------------------------}

instance SerialiseHFC xs
      => SerialiseNodeToClient (HardForkBlock xs) (HardForkBlock xs) where
  encodeNodeToClient :: CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> HardForkBlock xs
-> Encoding
encodeNodeToClient CodecConfig (HardForkBlock xs)
ccfg BlockNodeToClientVersion (HardForkBlock xs)
_ = (HardForkBlock xs -> Encoding) -> HardForkBlock xs -> Encoding
forall a. (a -> Encoding) -> a -> Encoding
wrapCBORinCBOR   (CodecConfig (HardForkBlock xs) -> HardForkBlock xs -> Encoding
forall (xs :: [*]).
SerialiseHFC xs =>
CodecConfig (HardForkBlock xs) -> HardForkBlock xs -> Encoding
encodeDiskHfcBlock CodecConfig (HardForkBlock xs)
ccfg)
  decodeNodeToClient :: CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> forall s. Decoder s (HardForkBlock xs)
decodeNodeToClient CodecConfig (HardForkBlock xs)
ccfg BlockNodeToClientVersion (HardForkBlock xs)
_ = (forall s. Decoder s (ByteString -> HardForkBlock xs))
-> forall s. Decoder s (HardForkBlock xs)
forall a.
(forall s. Decoder s (ByteString -> a)) -> forall s. Decoder s a
unwrapCBORinCBOR (CodecConfig (HardForkBlock xs)
-> forall s. Decoder s (ByteString -> HardForkBlock xs)
forall (xs :: [*]).
SerialiseHFC xs =>
CodecConfig (HardForkBlock xs)
-> forall s. Decoder s (ByteString -> HardForkBlock xs)
decodeDiskHfcBlock CodecConfig (HardForkBlock xs)
ccfg)

{-------------------------------------------------------------------------------
  Serialised blocks
-------------------------------------------------------------------------------}

instance SerialiseHFC xs
      => SerialiseNodeToClient (HardForkBlock xs) (Serialised (HardForkBlock xs)) where
  encodeNodeToClient :: CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> Serialised (HardForkBlock xs)
-> Encoding
encodeNodeToClient CodecConfig (HardForkBlock xs)
_ BlockNodeToClientVersion (HardForkBlock xs)
_ = Serialised (HardForkBlock xs) -> Encoding
forall a. Serialise a => a -> Encoding
Serialise.encode
  decodeNodeToClient :: CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> forall s. Decoder s (Serialised (HardForkBlock xs))
decodeNodeToClient CodecConfig (HardForkBlock xs)
_ BlockNodeToClientVersion (HardForkBlock xs)
_ = Decoder s (Serialised (HardForkBlock xs))
forall s. Decoder s (Serialised (HardForkBlock xs))
forall a s. Serialise a => Decoder s a
Serialise.decode

{-------------------------------------------------------------------------------
  Transactions
-------------------------------------------------------------------------------}

instance SerialiseHFC xs
      => SerialiseNodeToClient (HardForkBlock xs) (GenTx (HardForkBlock xs)) where
  encodeNodeToClient :: CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> GenTx (HardForkBlock xs)
-> Encoding
encodeNodeToClient = CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> NS GenTx xs
-> Encoding
CodecConfig (HardForkBlock xs)
-> HardForkNodeToClientVersion xs -> NS GenTx xs -> Encoding
forall (f :: * -> *) (xs :: [*]).
(SerialiseHFC xs,
 forall blk.
 SerialiseNodeToClientConstraints blk =>
 SerialiseNodeToClient blk (f blk)) =>
CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> NS f xs
-> Encoding
dispatchEncoder (CodecConfig (HardForkBlock xs)
 -> HardForkNodeToClientVersion xs -> NS GenTx xs -> Encoding)
-> (GenTx (HardForkBlock xs) -> NS GenTx xs)
-> CodecConfig (HardForkBlock xs)
-> HardForkNodeToClientVersion xs
-> GenTx (HardForkBlock xs)
-> Encoding
forall a b d e c.
(a -> b -> d -> e) -> (c -> d) -> a -> b -> c -> e
`after` (OneEraGenTx xs -> NS GenTx xs
forall (xs :: [*]). OneEraGenTx xs -> NS GenTx xs
getOneEraGenTx (OneEraGenTx xs -> NS GenTx xs)
-> (GenTx (HardForkBlock xs) -> OneEraGenTx xs)
-> GenTx (HardForkBlock xs)
-> NS GenTx xs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenTx (HardForkBlock xs) -> OneEraGenTx xs
forall (xs :: [*]). GenTx (HardForkBlock xs) -> OneEraGenTx xs
getHardForkGenTx)
  decodeNodeToClient :: CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> forall s. Decoder s (GenTx (HardForkBlock xs))
decodeNodeToClient = (NS GenTx xs -> GenTx (HardForkBlock xs))
-> Decoder s (NS GenTx xs) -> Decoder s (GenTx (HardForkBlock xs))
forall a b. (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (OneEraGenTx xs -> GenTx (HardForkBlock xs)
forall (xs :: [*]). OneEraGenTx xs -> GenTx (HardForkBlock xs)
HardForkGenTx (OneEraGenTx xs -> GenTx (HardForkBlock xs))
-> (NS GenTx xs -> OneEraGenTx xs)
-> NS GenTx xs
-> GenTx (HardForkBlock xs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NS GenTx xs -> OneEraGenTx xs
forall (xs :: [*]). NS GenTx xs -> OneEraGenTx xs
OneEraGenTx) (Decoder s (NS GenTx xs) -> Decoder s (GenTx (HardForkBlock xs)))
-> (CodecConfig (HardForkBlock xs)
    -> HardForkNodeToClientVersion xs -> Decoder s (NS GenTx xs))
-> CodecConfig (HardForkBlock xs)
-> HardForkNodeToClientVersion xs
-> Decoder s (GenTx (HardForkBlock xs))
forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z
.: CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> forall s. Decoder s (NS GenTx xs)
CodecConfig (HardForkBlock xs)
-> HardForkNodeToClientVersion xs -> Decoder s (NS GenTx xs)
forall (f :: * -> *) (xs :: [*]).
(SerialiseHFC xs,
 forall blk.
 SerialiseNodeToClientConstraints blk =>
 SerialiseNodeToClient blk (f blk)) =>
CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> forall s. Decoder s (NS f xs)
dispatchDecoder

instance SerialiseHFC xs
      => SerialiseNodeToClient (HardForkBlock xs) (GenTxId (HardForkBlock xs)) where
  encodeNodeToClient :: CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> GenTxId (HardForkBlock xs)
-> Encoding
encodeNodeToClient = CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> NS WrapGenTxId xs
-> Encoding
CodecConfig (HardForkBlock xs)
-> HardForkNodeToClientVersion xs -> NS WrapGenTxId xs -> Encoding
forall (f :: * -> *) (xs :: [*]).
(SerialiseHFC xs,
 forall blk.
 SerialiseNodeToClientConstraints blk =>
 SerialiseNodeToClient blk (f blk)) =>
CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> NS f xs
-> Encoding
dispatchEncoder (CodecConfig (HardForkBlock xs)
 -> HardForkNodeToClientVersion xs -> NS WrapGenTxId xs -> Encoding)
-> (GenTxId (HardForkBlock xs) -> NS WrapGenTxId xs)
-> CodecConfig (HardForkBlock xs)
-> HardForkNodeToClientVersion xs
-> GenTxId (HardForkBlock xs)
-> Encoding
forall a b d e c.
(a -> b -> d -> e) -> (c -> d) -> a -> b -> c -> e
`after` (OneEraGenTxId xs -> NS WrapGenTxId xs
forall (xs :: [*]). OneEraGenTxId xs -> NS WrapGenTxId xs
getOneEraGenTxId (OneEraGenTxId xs -> NS WrapGenTxId xs)
-> (GenTxId (HardForkBlock xs) -> OneEraGenTxId xs)
-> GenTxId (HardForkBlock xs)
-> NS WrapGenTxId xs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenTxId (HardForkBlock xs) -> OneEraGenTxId xs
forall (xs :: [*]).
TxId (GenTx (HardForkBlock xs)) -> OneEraGenTxId xs
getHardForkGenTxId)
  decodeNodeToClient :: CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> forall s. Decoder s (GenTxId (HardForkBlock xs))
decodeNodeToClient = (NS WrapGenTxId xs -> GenTxId (HardForkBlock xs))
-> Decoder s (NS WrapGenTxId xs)
-> Decoder s (GenTxId (HardForkBlock xs))
forall a b. (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (OneEraGenTxId xs -> GenTxId (HardForkBlock xs)
forall (xs :: [*]).
OneEraGenTxId xs -> TxId (GenTx (HardForkBlock xs))
HardForkGenTxId (OneEraGenTxId xs -> GenTxId (HardForkBlock xs))
-> (NS WrapGenTxId xs -> OneEraGenTxId xs)
-> NS WrapGenTxId xs
-> GenTxId (HardForkBlock xs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NS WrapGenTxId xs -> OneEraGenTxId xs
forall (xs :: [*]). NS WrapGenTxId xs -> OneEraGenTxId xs
OneEraGenTxId) (Decoder s (NS WrapGenTxId xs)
 -> Decoder s (GenTxId (HardForkBlock xs)))
-> (CodecConfig (HardForkBlock xs)
    -> HardForkNodeToClientVersion xs -> Decoder s (NS WrapGenTxId xs))
-> CodecConfig (HardForkBlock xs)
-> HardForkNodeToClientVersion xs
-> Decoder s (GenTxId (HardForkBlock xs))
forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z
.: CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> forall s. Decoder s (NS WrapGenTxId xs)
CodecConfig (HardForkBlock xs)
-> HardForkNodeToClientVersion xs -> Decoder s (NS WrapGenTxId xs)
forall (f :: * -> *) (xs :: [*]).
(SerialiseHFC xs,
 forall blk.
 SerialiseNodeToClientConstraints blk =>
 SerialiseNodeToClient blk (f blk)) =>
CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> forall s. Decoder s (NS f xs)
dispatchDecoder

instance SerialiseHFC xs
      => SerialiseNodeToClient (HardForkBlock xs) SlotNo where
  encodeNodeToClient :: CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> SlotNo
-> Encoding
encodeNodeToClient CodecConfig (HardForkBlock xs)
_ BlockNodeToClientVersion (HardForkBlock xs)
_ = SlotNo -> Encoding
forall a. Serialise a => a -> Encoding
Serialise.encode
  decodeNodeToClient :: CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> forall s. Decoder s SlotNo
decodeNodeToClient CodecConfig (HardForkBlock xs)
_ BlockNodeToClientVersion (HardForkBlock xs)
_ = Decoder s SlotNo
forall s. Decoder s SlotNo
forall a s. Serialise a => Decoder s a
Serialise.decode

instance SerialiseHFC xs
      => SerialiseNodeToClient (HardForkBlock xs) (HardForkApplyTxErr xs) where
  encodeNodeToClient :: CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> HardForkApplyTxErr xs
-> Encoding
encodeNodeToClient = CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> Either (MismatchEraInfo xs) (NS WrapApplyTxErr xs)
-> Encoding
CodecConfig (HardForkBlock xs)
-> HardForkNodeToClientVersion xs
-> Either (MismatchEraInfo xs) (NS WrapApplyTxErr xs)
-> Encoding
forall (f :: * -> *) (xs :: [*]).
(SerialiseHFC xs,
 forall blk.
 SerialiseNodeToClientConstraints blk =>
 SerialiseNodeToClient blk (f blk)) =>
CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> Either (MismatchEraInfo xs) (NS f xs)
-> Encoding
dispatchEncoderErr (CodecConfig (HardForkBlock xs)
 -> HardForkNodeToClientVersion xs
 -> Either (MismatchEraInfo xs) (NS WrapApplyTxErr xs)
 -> Encoding)
-> (HardForkApplyTxErr xs
    -> Either (MismatchEraInfo xs) (NS WrapApplyTxErr xs))
-> CodecConfig (HardForkBlock xs)
-> HardForkNodeToClientVersion xs
-> HardForkApplyTxErr xs
-> Encoding
forall a b d e c.
(a -> b -> d -> e) -> (c -> d) -> a -> b -> c -> e
`after` ((OneEraApplyTxErr xs -> NS WrapApplyTxErr xs)
-> Either (MismatchEraInfo xs) (OneEraApplyTxErr xs)
-> Either (MismatchEraInfo xs) (NS WrapApplyTxErr xs)
forall a b.
(a -> b)
-> Either (MismatchEraInfo xs) a -> Either (MismatchEraInfo xs) b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap OneEraApplyTxErr xs -> NS WrapApplyTxErr xs
forall (xs :: [*]). OneEraApplyTxErr xs -> NS WrapApplyTxErr xs
getOneEraApplyTxErr (Either (MismatchEraInfo xs) (OneEraApplyTxErr xs)
 -> Either (MismatchEraInfo xs) (NS WrapApplyTxErr xs))
-> (HardForkApplyTxErr xs
    -> Either (MismatchEraInfo xs) (OneEraApplyTxErr xs))
-> HardForkApplyTxErr xs
-> Either (MismatchEraInfo xs) (NS WrapApplyTxErr xs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HardForkApplyTxErr xs
-> Either (MismatchEraInfo xs) (OneEraApplyTxErr xs)
forall (xs :: [*]).
HardForkApplyTxErr xs
-> Either (MismatchEraInfo xs) (OneEraApplyTxErr xs)
hardForkApplyTxErrToEither)
  decodeNodeToClient :: CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> forall s. Decoder s (HardForkApplyTxErr xs)
decodeNodeToClient = (Either (MismatchEraInfo xs) (NS WrapApplyTxErr xs)
 -> HardForkApplyTxErr xs)
-> Decoder s (Either (MismatchEraInfo xs) (NS WrapApplyTxErr xs))
-> Decoder s (HardForkApplyTxErr xs)
forall a b. (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Either (MismatchEraInfo xs) (OneEraApplyTxErr xs)
-> HardForkApplyTxErr xs
forall (xs :: [*]).
Either (MismatchEraInfo xs) (OneEraApplyTxErr xs)
-> HardForkApplyTxErr xs
hardForkApplyTxErrFromEither (Either (MismatchEraInfo xs) (OneEraApplyTxErr xs)
 -> HardForkApplyTxErr xs)
-> (Either (MismatchEraInfo xs) (NS WrapApplyTxErr xs)
    -> Either (MismatchEraInfo xs) (OneEraApplyTxErr xs))
-> Either (MismatchEraInfo xs) (NS WrapApplyTxErr xs)
-> HardForkApplyTxErr xs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NS WrapApplyTxErr xs -> OneEraApplyTxErr xs)
-> Either (MismatchEraInfo xs) (NS WrapApplyTxErr xs)
-> Either (MismatchEraInfo xs) (OneEraApplyTxErr xs)
forall a b.
(a -> b)
-> Either (MismatchEraInfo xs) a -> Either (MismatchEraInfo xs) b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NS WrapApplyTxErr xs -> OneEraApplyTxErr xs
forall (xs :: [*]). NS WrapApplyTxErr xs -> OneEraApplyTxErr xs
OneEraApplyTxErr) (Decoder s (Either (MismatchEraInfo xs) (NS WrapApplyTxErr xs))
 -> Decoder s (HardForkApplyTxErr xs))
-> (CodecConfig (HardForkBlock xs)
    -> HardForkNodeToClientVersion xs
    -> Decoder s (Either (MismatchEraInfo xs) (NS WrapApplyTxErr xs)))
-> CodecConfig (HardForkBlock xs)
-> HardForkNodeToClientVersion xs
-> Decoder s (HardForkApplyTxErr xs)
forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z
.: CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> forall s.
   Decoder s (Either (MismatchEraInfo xs) (NS WrapApplyTxErr xs))
CodecConfig (HardForkBlock xs)
-> HardForkNodeToClientVersion xs
-> Decoder s (Either (MismatchEraInfo xs) (NS WrapApplyTxErr xs))
forall (f :: * -> *) (xs :: [*]).
(SerialiseHFC xs,
 forall blk.
 SerialiseNodeToClientConstraints blk =>
 SerialiseNodeToClient blk (f blk)) =>
CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> forall s. Decoder s (Either (MismatchEraInfo xs) (NS f xs))
dispatchDecoderErr

{-------------------------------------------------------------------------------
  Queries
-------------------------------------------------------------------------------}

encodeQueryHardFork ::
     HardForkSpecificNodeToClientVersion
  -> Some (QueryHardFork xs)
  -> Encoding
encodeQueryHardFork :: forall (xs :: [*]).
HardForkSpecificNodeToClientVersion
-> Some (QueryHardFork xs) -> Encoding
encodeQueryHardFork HardForkSpecificNodeToClientVersion
vHfc = \case
    Some QueryHardFork xs a
GetInterpreter -> [Encoding] -> Encoding
forall a. Monoid a => [a] -> a
mconcat [
        Word -> Encoding
Enc.encodeListLen Word
1
      , Word8 -> Encoding
Enc.encodeWord8 Word8
0
      ]
    Some QueryHardFork xs a
GetCurrentEra
      | HardForkSpecificNodeToClientVersion
vHfc HardForkSpecificNodeToClientVersion
-> HardForkSpecificNodeToClientVersion -> Bool
forall a. Ord a => a -> a -> Bool
< HardForkSpecificNodeToClientVersion
HardForkSpecificNodeToClientVersion2 ->
        HardForkEncoderException -> Encoding
forall a e. Exception e => e -> a
throw HardForkEncoderException
HardForkEncoderQueryWrongVersion
      | Bool
otherwise -> [Encoding] -> Encoding
forall a. Monoid a => [a] -> a
mconcat [
        Word -> Encoding
Enc.encodeListLen Word
1
      , Word8 -> Encoding
Enc.encodeWord8 Word8
1
      ]

decodeQueryHardFork :: Decoder s (Some (QueryHardFork xs))
decodeQueryHardFork :: forall s (xs :: [*]). Decoder s (Some (QueryHardFork xs))
decodeQueryHardFork = do
    Text -> Int -> Decoder s ()
forall s. Text -> Int -> Decoder s ()
enforceSize Text
"QueryHardFork" Int
1
    Word8
tag <- Decoder s Word8
forall s. Decoder s Word8
Dec.decodeWord8
    case Word8
tag of
      Word8
0 -> Some (QueryHardFork xs) -> Decoder s (Some (QueryHardFork xs))
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (Some (QueryHardFork xs) -> Decoder s (Some (QueryHardFork xs)))
-> Some (QueryHardFork xs) -> Decoder s (Some (QueryHardFork xs))
forall a b. (a -> b) -> a -> b
$ QueryHardFork xs (Interpreter xs) -> Some (QueryHardFork xs)
forall {k} (f :: k -> *) (a :: k). f a -> Some f
Some QueryHardFork xs (Interpreter xs)
forall (xs :: [*]). QueryHardFork xs (Interpreter xs)
GetInterpreter
      Word8
1 -> Some (QueryHardFork xs) -> Decoder s (Some (QueryHardFork xs))
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (Some (QueryHardFork xs) -> Decoder s (Some (QueryHardFork xs)))
-> Some (QueryHardFork xs) -> Decoder s (Some (QueryHardFork xs))
forall a b. (a -> b) -> a -> b
$ QueryHardFork xs (EraIndex xs) -> Some (QueryHardFork xs)
forall {k} (f :: k -> *) (a :: k). f a -> Some f
Some QueryHardFork xs (EraIndex xs)
forall (xs :: [*]). QueryHardFork xs (EraIndex xs)
GetCurrentEra
      Word8
_ -> String -> Decoder s (Some (QueryHardFork xs))
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Decoder s (Some (QueryHardFork xs)))
-> String -> Decoder s (Some (QueryHardFork xs))
forall a b. (a -> b) -> a -> b
$ String
"QueryHardFork: invalid tag " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
tag

instance SerialiseHFC xs
      => SerialiseNodeToClient (HardForkBlock xs) (SomeSecond BlockQuery (HardForkBlock xs)) where
  encodeNodeToClient :: CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> SomeSecond BlockQuery (HardForkBlock xs)
-> Encoding
encodeNodeToClient CodecConfig (HardForkBlock xs)
ccfg BlockNodeToClientVersion (HardForkBlock xs)
version (SomeSecond BlockQuery (HardForkBlock xs) b
q) = case BlockNodeToClientVersion (HardForkBlock xs)
version of
      HardForkNodeToClientDisabled BlockNodeToClientVersion x
v0 -> case BlockQuery (HardForkBlock xs) b
q of
        QueryIfCurrent QueryIfCurrent xs result
qry ->
          case Some (QueryIfCurrent xs) -> NS (SomeSecond BlockQuery) xs
forall (xs :: [*]).
Some (QueryIfCurrent xs) -> NS (SomeSecond BlockQuery) xs
distribQueryIfCurrent (QueryIfCurrent xs result -> Some (QueryIfCurrent xs)
forall {k} (f :: k -> *) (a :: k). f a -> Some f
Some QueryIfCurrent xs result
qry) of
            Z SomeSecond BlockQuery x
qry0  -> CodecConfig x
-> BlockNodeToClientVersion x
-> SomeSecond BlockQuery x
-> Encoding
forall blk a.
SerialiseNodeToClient blk a =>
CodecConfig blk -> BlockNodeToClientVersion blk -> a -> Encoding
encodeNodeToClient (NP CodecConfig (x : xs1) -> CodecConfig x
forall {k} (f :: k -> *) (x :: k) (xs :: [k]). NP f (x : xs) -> f x
hd NP CodecConfig xs
NP CodecConfig (x : xs1)
ccfgs) BlockNodeToClientVersion x
v0 SomeSecond BlockQuery x
qry0
            S NS (SomeSecond BlockQuery) xs1
later -> HardForkEncoderException -> Encoding
forall a e. Exception e => e -> a
throw (HardForkEncoderException -> Encoding)
-> HardForkEncoderException -> Encoding
forall a b. (a -> b) -> a -> b
$ NS SingleEraInfo xs1 -> HardForkEncoderException
forall (xs :: [*]).
SListI xs =>
NS SingleEraInfo xs -> HardForkEncoderException
futureEraException (NS (SomeSecond BlockQuery) xs1 -> NS SingleEraInfo xs1
forall (xs :: [*]) (f :: * -> *).
All SingleEraBlock xs =>
NS f xs -> NS SingleEraInfo xs
notFirstEra NS (SomeSecond BlockQuery) xs1
later)
        QueryAnytime {} ->
          HardForkEncoderException -> Encoding
forall a e. Exception e => e -> a
throw HardForkEncoderException
HardForkEncoderQueryHfcDisabled
        QueryHardFork {} ->
          HardForkEncoderException -> Encoding
forall a e. Exception e => e -> a
throw HardForkEncoderException
HardForkEncoderQueryHfcDisabled

      HardForkNodeToClientEnabled HardForkSpecificNodeToClientVersion
vHfc NP EraNodeToClientVersion xs
_ -> case BlockQuery (HardForkBlock xs) b
q of
        QueryIfCurrent QueryIfCurrent xs result
qry -> [Encoding] -> Encoding
forall a. Monoid a => [a] -> a
mconcat [
            Word -> Encoding
Enc.encodeListLen Word
2
          , Word8 -> Encoding
Enc.encodeWord8 Word8
0
          , CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> NS (SomeSecond BlockQuery) xs
-> Encoding
forall (f :: * -> *) (xs :: [*]).
(SerialiseHFC xs,
 forall blk.
 SerialiseNodeToClientConstraints blk =>
 SerialiseNodeToClient blk (f blk)) =>
CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> NS f xs
-> Encoding
dispatchEncoder CodecConfig (HardForkBlock xs)
ccfg BlockNodeToClientVersion (HardForkBlock xs)
version (Some (QueryIfCurrent xs) -> NS (SomeSecond BlockQuery) xs
forall (xs :: [*]).
Some (QueryIfCurrent xs) -> NS (SomeSecond BlockQuery) xs
distribQueryIfCurrent (QueryIfCurrent xs result -> Some (QueryIfCurrent xs)
forall {k} (f :: k -> *) (a :: k). f a -> Some f
Some QueryIfCurrent xs result
qry))
          ]
        QueryAnytime QueryAnytime b
qry EraIndex (x : xs1)
eraIndex -> [Encoding] -> Encoding
forall a. Monoid a => [a] -> a
mconcat [
            Word -> Encoding
Enc.encodeListLen Word
3
          , Word8 -> Encoding
Enc.encodeWord8 Word8
1
          , Some QueryAnytime -> Encoding
forall a. Serialise a => a -> Encoding
Serialise.encode (QueryAnytime b -> Some QueryAnytime
forall {k} (f :: k -> *) (a :: k). f a -> Some f
Some QueryAnytime b
qry)
          , EraIndex (x : xs1) -> Encoding
forall a. Serialise a => a -> Encoding
Serialise.encode EraIndex (x : xs1)
eraIndex
          ]
        QueryHardFork QueryHardFork (x : xs1) b
qry -> [Encoding] -> Encoding
forall a. Monoid a => [a] -> a
mconcat [
            Word -> Encoding
Enc.encodeListLen Word
2
          , Word8 -> Encoding
Enc.encodeWord8 Word8
2
          , HardForkSpecificNodeToClientVersion
-> Some (QueryHardFork (x : xs1)) -> Encoding
forall (xs :: [*]).
HardForkSpecificNodeToClientVersion
-> Some (QueryHardFork xs) -> Encoding
encodeQueryHardFork HardForkSpecificNodeToClientVersion
vHfc (QueryHardFork (x : xs1) b -> Some (QueryHardFork (x : xs1))
forall {k} (f :: k -> *) (a :: k). f a -> Some f
Some QueryHardFork (x : xs1) b
qry)
          ]
    where
      ccfgs :: NP CodecConfig xs
ccfgs = PerEraCodecConfig xs -> NP CodecConfig xs
forall (xs :: [*]). PerEraCodecConfig xs -> NP CodecConfig xs
getPerEraCodecConfig (PerEraCodecConfig xs -> NP CodecConfig xs)
-> PerEraCodecConfig xs -> NP CodecConfig xs
forall a b. (a -> b) -> a -> b
$ CodecConfig (HardForkBlock xs) -> PerEraCodecConfig xs
forall (xs :: [*]).
CodecConfig (HardForkBlock xs) -> PerEraCodecConfig xs
hardForkCodecConfigPerEra CodecConfig (HardForkBlock xs)
ccfg

  decodeNodeToClient :: CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> forall s. Decoder s (SomeSecond BlockQuery (HardForkBlock xs))
decodeNodeToClient CodecConfig (HardForkBlock xs)
ccfg BlockNodeToClientVersion (HardForkBlock xs)
version = case BlockNodeToClientVersion (HardForkBlock xs)
version of
      HardForkNodeToClientDisabled BlockNodeToClientVersion x
v0 ->
        NS (SomeSecond BlockQuery) xs
-> SomeSecond BlockQuery (HardForkBlock xs)
injQueryIfCurrent (NS (SomeSecond BlockQuery) xs
 -> SomeSecond BlockQuery (HardForkBlock xs))
-> (SomeSecond BlockQuery x -> NS (SomeSecond BlockQuery) xs)
-> SomeSecond BlockQuery x
-> SomeSecond BlockQuery (HardForkBlock xs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SomeSecond BlockQuery x -> NS (SomeSecond BlockQuery) xs
SomeSecond BlockQuery x -> NS (SomeSecond BlockQuery) (x : xs1)
forall {k} (f :: k -> *) (x :: k) (xs1 :: [k]).
f x -> NS f (x : xs1)
Z (SomeSecond BlockQuery x
 -> SomeSecond BlockQuery (HardForkBlock xs))
-> Decoder s (SomeSecond BlockQuery x)
-> Decoder s (SomeSecond BlockQuery (HardForkBlock xs))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
          CodecConfig x
-> BlockNodeToClientVersion x
-> forall s. Decoder s (SomeSecond BlockQuery x)
forall blk a.
SerialiseNodeToClient blk a =>
CodecConfig blk
-> BlockNodeToClientVersion blk -> forall s. Decoder s a
decodeNodeToClient (NP CodecConfig (x : xs1) -> CodecConfig x
forall {k} (f :: k -> *) (x :: k) (xs :: [k]). NP f (x : xs) -> f x
hd NP CodecConfig xs
NP CodecConfig (x : xs1)
ccfgs) BlockNodeToClientVersion x
v0
      HardForkNodeToClientEnabled {} -> case Proxy xs -> ProofNonEmpty xs
forall {a} (xs :: [a]) (proxy :: [a] -> *).
IsNonEmpty xs =>
proxy xs -> ProofNonEmpty xs
forall (proxy :: [*] -> *). proxy xs -> ProofNonEmpty xs
isNonEmpty (forall (t :: [*]). Proxy t
forall {k} (t :: k). Proxy t
Proxy @xs) of
        ProofNonEmpty (Proxy x
_ :: Proxy x') (Proxy xs1
p :: Proxy xs') -> do
          Int
size <- Decoder s Int
forall s. Decoder s Int
Dec.decodeListLen
          Word8
tag  <- Decoder s Word8
forall s. Decoder s Word8
Dec.decodeWord8
          case (Int
size, Word8
tag) of
            (Int
2, Word8
0) -> NS (SomeSecond BlockQuery) xs
-> SomeSecond BlockQuery (HardForkBlock xs)
injQueryIfCurrent (NS (SomeSecond BlockQuery) xs
 -> SomeSecond BlockQuery (HardForkBlock xs))
-> Decoder s (NS (SomeSecond BlockQuery) xs)
-> Decoder s (SomeSecond BlockQuery (HardForkBlock xs))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> forall s. Decoder s (NS (SomeSecond BlockQuery) xs)
forall (f :: * -> *) (xs :: [*]).
(SerialiseHFC xs,
 forall blk.
 SerialiseNodeToClientConstraints blk =>
 SerialiseNodeToClient blk (f blk)) =>
CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> forall s. Decoder s (NS f xs)
dispatchDecoder CodecConfig (HardForkBlock xs)
ccfg BlockNodeToClientVersion (HardForkBlock xs)
version

            (Int
3, Word8
1) -> do
              Some (QueryAnytime a
qry :: QueryAnytime result) <- Decoder s (Some QueryAnytime)
forall s. Decoder s (Some QueryAnytime)
forall a s. Serialise a => Decoder s a
Serialise.decode
              EraIndex (x : xs1)
eraIndex :: EraIndex (x' ': xs')  <- Decoder s (EraIndex (x : xs1))
forall s. Decoder s (EraIndex (x : xs1))
forall a s. Serialise a => Decoder s a
Serialise.decode
              case Proxy xs1 -> Maybe (ProofNonEmpty xs1)
forall {a} (xs :: [a]).
SListI xs =>
Proxy xs -> Maybe (ProofNonEmpty xs)
checkIsNonEmpty Proxy xs1
p of
                Maybe (ProofNonEmpty xs1)
Nothing -> String -> Decoder s (SomeSecond BlockQuery (HardForkBlock xs))
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Decoder s (SomeSecond BlockQuery (HardForkBlock xs)))
-> String -> Decoder s (SomeSecond BlockQuery (HardForkBlock xs))
forall a b. (a -> b) -> a -> b
$ String
"QueryAnytime requires multiple era"
                Just (ProofNonEmpty {}) ->
                  SomeSecond BlockQuery (HardForkBlock xs)
-> Decoder s (SomeSecond BlockQuery (HardForkBlock xs))
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (SomeSecond BlockQuery (HardForkBlock xs)
 -> Decoder s (SomeSecond BlockQuery (HardForkBlock xs)))
-> SomeSecond BlockQuery (HardForkBlock xs)
-> Decoder s (SomeSecond BlockQuery (HardForkBlock xs))
forall a b. (a -> b) -> a -> b
$ BlockQuery (HardForkBlock xs) a
-> SomeSecond BlockQuery (HardForkBlock xs)
forall {k1} {k2} (f :: k1 -> k2 -> *) (a :: k1) (b :: k2).
f a b -> SomeSecond f a
SomeSecond (QueryAnytime a
-> EraIndex (x : xs1) -> BlockQuery (HardForkBlock (x : xs1)) a
forall (xs1 :: [*]) a x.
IsNonEmpty xs1 =>
QueryAnytime a
-> EraIndex (x : xs1) -> BlockQuery (HardForkBlock (x : xs1)) a
QueryAnytime QueryAnytime a
qry EraIndex (x : xs1)
eraIndex)

            (Int
2, Word8
2) -> do
              Some (QueryHardFork xs a
qry :: QueryHardFork xs result) <- Decoder s (Some (QueryHardFork (x : xs1)))
forall s (xs :: [*]). Decoder s (Some (QueryHardFork xs))
decodeQueryHardFork
              case Proxy xs1 -> Maybe (ProofNonEmpty xs1)
forall {a} (xs :: [a]).
SListI xs =>
Proxy xs -> Maybe (ProofNonEmpty xs)
checkIsNonEmpty Proxy xs1
p of
                Maybe (ProofNonEmpty xs1)
Nothing -> String -> Decoder s (SomeSecond BlockQuery (HardForkBlock xs))
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Decoder s (SomeSecond BlockQuery (HardForkBlock xs)))
-> String -> Decoder s (SomeSecond BlockQuery (HardForkBlock xs))
forall a b. (a -> b) -> a -> b
$ String
"QueryHardFork requires multiple era"
                Just (ProofNonEmpty {}) ->
                  SomeSecond BlockQuery (HardForkBlock xs)
-> Decoder s (SomeSecond BlockQuery (HardForkBlock xs))
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (SomeSecond BlockQuery (HardForkBlock xs)
 -> Decoder s (SomeSecond BlockQuery (HardForkBlock xs)))
-> SomeSecond BlockQuery (HardForkBlock xs)
-> Decoder s (SomeSecond BlockQuery (HardForkBlock xs))
forall a b. (a -> b) -> a -> b
$ BlockQuery (HardForkBlock xs) a
-> SomeSecond BlockQuery (HardForkBlock xs)
forall {k1} {k2} (f :: k1 -> k2 -> *) (a :: k1) (b :: k2).
f a b -> SomeSecond f a
SomeSecond (QueryHardFork (x : x : xs1) a
-> BlockQuery (HardForkBlock (x : x : xs1)) a
forall (xs1 :: [*]) x a.
IsNonEmpty xs1 =>
QueryHardFork (x : xs1) a -> BlockQuery (HardForkBlock (x : xs1)) a
QueryHardFork QueryHardFork xs a
QueryHardFork (x : x : xs1) a
qry)

            (Int, Word8)
_ -> String -> Decoder s (SomeSecond BlockQuery (HardForkBlock xs))
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Decoder s (SomeSecond BlockQuery (HardForkBlock xs)))
-> String -> Decoder s (SomeSecond BlockQuery (HardForkBlock xs))
forall a b. (a -> b) -> a -> b
$ String
"HardForkQuery: invalid size and tag" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> (Int, Word8) -> String
forall a. Show a => a -> String
show (Int
size, Word8
tag)
    where
      ccfgs :: NP CodecConfig xs
ccfgs = PerEraCodecConfig xs -> NP CodecConfig xs
forall (xs :: [*]). PerEraCodecConfig xs -> NP CodecConfig xs
getPerEraCodecConfig (PerEraCodecConfig xs -> NP CodecConfig xs)
-> PerEraCodecConfig xs -> NP CodecConfig xs
forall a b. (a -> b) -> a -> b
$ CodecConfig (HardForkBlock xs) -> PerEraCodecConfig xs
forall (xs :: [*]).
CodecConfig (HardForkBlock xs) -> PerEraCodecConfig xs
hardForkCodecConfigPerEra CodecConfig (HardForkBlock xs)
ccfg

      injQueryIfCurrent :: NS (SomeSecond BlockQuery) xs
                        -> SomeSecond BlockQuery (HardForkBlock xs)
      injQueryIfCurrent :: NS (SomeSecond BlockQuery) xs
-> SomeSecond BlockQuery (HardForkBlock xs)
injQueryIfCurrent NS (SomeSecond BlockQuery) xs
ns =
          case NS (SomeSecond BlockQuery) xs -> Some (QueryIfCurrent xs)
forall (xs :: [*]).
NS (SomeSecond BlockQuery) xs -> Some (QueryIfCurrent xs)
undistribQueryIfCurrent NS (SomeSecond BlockQuery) xs
ns of
            Some QueryIfCurrent xs a
q -> BlockQuery (HardForkBlock xs) (Either (MismatchEraInfo xs) a)
-> SomeSecond BlockQuery (HardForkBlock xs)
forall {k1} {k2} (f :: k1 -> k2 -> *) (a :: k1) (b :: k2).
f a b -> SomeSecond f a
SomeSecond (QueryIfCurrent xs a
-> BlockQuery (HardForkBlock xs) (Either (MismatchEraInfo xs) a)
forall (xs :: [*]) result.
QueryIfCurrent xs result
-> BlockQuery
     (HardForkBlock xs) (Either (MismatchEraInfo xs) result)
QueryIfCurrent QueryIfCurrent xs a
q)

{-------------------------------------------------------------------------------
  Results
-------------------------------------------------------------------------------}

instance SerialiseHFC xs
      => SerialiseResult (HardForkBlock xs) (BlockQuery (HardForkBlock xs)) where
  encodeResult :: forall result.
CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> BlockQuery (HardForkBlock xs) result
-> result
-> Encoding
encodeResult CodecConfig (HardForkBlock xs)
ccfg BlockNodeToClientVersion (HardForkBlock xs)
version (QueryIfCurrent QueryIfCurrent xs result
qry) =
      case Proxy xs -> ProofNonEmpty xs
forall {a} (xs :: [a]) (proxy :: [a] -> *).
IsNonEmpty xs =>
proxy xs -> ProofNonEmpty xs
forall (proxy :: [*] -> *). proxy xs -> ProofNonEmpty xs
isNonEmpty (forall (t :: [*]). Proxy t
forall {k} (t :: k). Proxy t
Proxy @xs) of
        ProofNonEmpty {} ->
          BlockNodeToClientVersion (HardForkBlock (x : xs1))
-> (result -> Encoding)
-> Either (MismatchEraInfo (x : xs1)) result
-> Encoding
forall (xs :: [*]) a.
SListI xs =>
BlockNodeToClientVersion (HardForkBlock xs)
-> (a -> Encoding) -> Either (MismatchEraInfo xs) a -> Encoding
encodeEitherMismatch BlockNodeToClientVersion (HardForkBlock xs)
BlockNodeToClientVersion (HardForkBlock (x : xs1))
version ((result -> Encoding)
 -> Either (MismatchEraInfo (x : xs1)) result -> Encoding)
-> (result -> Encoding)
-> Either (MismatchEraInfo (x : xs1)) result
-> Encoding
forall a b. (a -> b) -> a -> b
$
            case (NP CodecConfig xs
ccfgs, BlockNodeToClientVersion (HardForkBlock xs)
HardForkNodeToClientVersion xs
version, QueryIfCurrent xs result
qry) of
              (CodecConfig x
c0 :* NP CodecConfig xs1
_, HardForkNodeToClientDisabled BlockNodeToClientVersion x
v0, QZ BlockQuery x result
qry') ->
                CodecConfig x
-> BlockNodeToClientVersion x
-> BlockQuery x result
-> result
-> Encoding
forall result.
CodecConfig x
-> BlockNodeToClientVersion x
-> BlockQuery x result
-> result
-> Encoding
forall blk (query :: * -> *) result.
SerialiseResult blk query =>
CodecConfig blk
-> BlockNodeToClientVersion blk
-> query result
-> result
-> Encoding
encodeResult CodecConfig x
c0 BlockNodeToClientVersion x
BlockNodeToClientVersion x
v0 BlockQuery x result
qry'
              (NP CodecConfig xs
_, HardForkNodeToClientDisabled BlockNodeToClientVersion x
_, QS QueryIfCurrent xs result
qry') ->
                HardForkEncoderException -> result -> Encoding
forall a e. Exception e => e -> a
throw (HardForkEncoderException -> result -> Encoding)
-> HardForkEncoderException -> result -> Encoding
forall a b. (a -> b) -> a -> b
$ NS SingleEraInfo xs -> HardForkEncoderException
forall (xs :: [*]).
SListI xs =>
NS SingleEraInfo xs -> HardForkEncoderException
futureEraException (QueryIfCurrent xs result -> NS SingleEraInfo xs
forall (xs :: [*]) result.
All SingleEraBlock xs =>
QueryIfCurrent xs result -> NS SingleEraInfo xs
hardForkQueryInfo QueryIfCurrent xs result
qry')
              (NP CodecConfig xs
_, HardForkNodeToClientEnabled HardForkSpecificNodeToClientVersion
_ NP EraNodeToClientVersion xs
versions, QueryIfCurrent xs result
_) ->
                NP CodecConfig xs
-> NP EraNodeToClientVersion xs
-> QueryIfCurrent xs result
-> result
-> Encoding
forall (xs :: [*]) result.
All SerialiseConstraintsHFC xs =>
NP CodecConfig xs
-> NP EraNodeToClientVersion xs
-> QueryIfCurrent xs result
-> result
-> Encoding
encodeQueryIfCurrentResult NP CodecConfig xs
ccfgs NP EraNodeToClientVersion xs
versions QueryIfCurrent xs result
qry
    where
      ccfgs :: NP CodecConfig xs
ccfgs = PerEraCodecConfig xs -> NP CodecConfig xs
forall (xs :: [*]). PerEraCodecConfig xs -> NP CodecConfig xs
getPerEraCodecConfig (PerEraCodecConfig xs -> NP CodecConfig xs)
-> PerEraCodecConfig xs -> NP CodecConfig xs
forall a b. (a -> b) -> a -> b
$ CodecConfig (HardForkBlock xs) -> PerEraCodecConfig xs
forall (xs :: [*]).
CodecConfig (HardForkBlock xs) -> PerEraCodecConfig xs
hardForkCodecConfigPerEra CodecConfig (HardForkBlock xs)
ccfg

  encodeResult CodecConfig (HardForkBlock xs)
_ BlockNodeToClientVersion (HardForkBlock xs)
_       (QueryAnytime QueryAnytime result
qry EraIndex (x : xs1)
_) = QueryAnytime result -> result -> Encoding
forall result. QueryAnytime result -> result -> Encoding
encodeQueryAnytimeResult      QueryAnytime result
qry
  encodeResult CodecConfig (HardForkBlock xs)
_ BlockNodeToClientVersion (HardForkBlock xs)
version (QueryHardFork QueryHardFork (x : xs1) result
qry)  = EraParamsFormat
-> QueryHardFork (x : xs1) result -> result -> Encoding
forall (xs :: [*]) result.
SListI xs =>
EraParamsFormat -> QueryHardFork xs result -> result -> Encoding
encodeQueryHardForkResult EraParamsFormat
epf QueryHardFork (x : xs1) result
qry
    where
      epf :: EraParamsFormat
epf = HardForkNodeToClientVersion (x : xs1) -> EraParamsFormat
forall (xs :: [*]).
HardForkNodeToClientVersion xs -> EraParamsFormat
eraParamsFormatFromVersion BlockNodeToClientVersion (HardForkBlock xs)
HardForkNodeToClientVersion (x : xs1)
version

  decodeResult :: forall result.
CodecConfig (HardForkBlock xs)
-> BlockNodeToClientVersion (HardForkBlock xs)
-> BlockQuery (HardForkBlock xs) result
-> forall s. Decoder s result
decodeResult CodecConfig (HardForkBlock xs)
ccfg BlockNodeToClientVersion (HardForkBlock xs)
version (QueryIfCurrent QueryIfCurrent xs result
qry) =
      case Proxy xs -> ProofNonEmpty xs
forall {a} (xs :: [a]) (proxy :: [a] -> *).
IsNonEmpty xs =>
proxy xs -> ProofNonEmpty xs
forall (proxy :: [*] -> *). proxy xs -> ProofNonEmpty xs
isNonEmpty (forall (t :: [*]). Proxy t
forall {k} (t :: k). Proxy t
Proxy @xs) of
        ProofNonEmpty {} ->
          BlockNodeToClientVersion (HardForkBlock (x : xs1))
-> Decoder s result
-> Decoder s (Either (MismatchEraInfo (x : xs1)) result)
forall (xs :: [*]) s a.
SListI xs =>
BlockNodeToClientVersion (HardForkBlock xs)
-> Decoder s a -> Decoder s (Either (MismatchEraInfo xs) a)
decodeEitherMismatch BlockNodeToClientVersion (HardForkBlock xs)
BlockNodeToClientVersion (HardForkBlock (x : xs1))
version (Decoder s result
 -> Decoder s (Either (MismatchEraInfo (x : xs1)) result))
-> Decoder s result
-> Decoder s (Either (MismatchEraInfo (x : xs1)) result)
forall a b. (a -> b) -> a -> b
$
            case (NP CodecConfig xs
ccfgs, BlockNodeToClientVersion (HardForkBlock xs)
HardForkNodeToClientVersion xs
version, QueryIfCurrent xs result
qry) of
              (CodecConfig x
c0 :* NP CodecConfig xs1
_, HardForkNodeToClientDisabled BlockNodeToClientVersion x
v0, QZ BlockQuery x result
qry') ->
                CodecConfig x
-> BlockNodeToClientVersion x
-> BlockQuery x result
-> forall s. Decoder s result
forall result.
CodecConfig x
-> BlockNodeToClientVersion x
-> BlockQuery x result
-> forall s. Decoder s result
forall blk (query :: * -> *) result.
SerialiseResult blk query =>
CodecConfig blk
-> BlockNodeToClientVersion blk
-> query result
-> forall s. Decoder s result
decodeResult CodecConfig x
c0 BlockNodeToClientVersion x
BlockNodeToClientVersion x
v0 BlockQuery x result
qry'
              (NP CodecConfig xs
_, HardForkNodeToClientDisabled BlockNodeToClientVersion x
_, QS QueryIfCurrent xs result
qry') ->
                HardForkEncoderException -> Decoder s result
forall a e. Exception e => e -> a
throw (HardForkEncoderException -> Decoder s result)
-> HardForkEncoderException -> Decoder s result
forall a b. (a -> b) -> a -> b
$ NS SingleEraInfo xs -> HardForkEncoderException
forall (xs :: [*]).
SListI xs =>
NS SingleEraInfo xs -> HardForkEncoderException
futureEraException (QueryIfCurrent xs result -> NS SingleEraInfo xs
forall (xs :: [*]) result.
All SingleEraBlock xs =>
QueryIfCurrent xs result -> NS SingleEraInfo xs
hardForkQueryInfo QueryIfCurrent xs result
qry')
              (NP CodecConfig xs
_, HardForkNodeToClientEnabled HardForkSpecificNodeToClientVersion
_ NP EraNodeToClientVersion xs
versions, QueryIfCurrent xs result
_) ->
                NP CodecConfig xs
-> NP EraNodeToClientVersion xs
-> QueryIfCurrent xs result
-> Decoder s result
forall (xs :: [*]) result s.
All SerialiseConstraintsHFC xs =>
NP CodecConfig xs
-> NP EraNodeToClientVersion xs
-> QueryIfCurrent xs result
-> Decoder s result
decodeQueryIfCurrentResult NP CodecConfig xs
ccfgs NP EraNodeToClientVersion xs
versions QueryIfCurrent xs result
qry
    where
      ccfgs :: NP CodecConfig xs
ccfgs = PerEraCodecConfig xs -> NP CodecConfig xs
forall (xs :: [*]). PerEraCodecConfig xs -> NP CodecConfig xs
getPerEraCodecConfig (PerEraCodecConfig xs -> NP CodecConfig xs)
-> PerEraCodecConfig xs -> NP CodecConfig xs
forall a b. (a -> b) -> a -> b
$ CodecConfig (HardForkBlock xs) -> PerEraCodecConfig xs
forall (xs :: [*]).
CodecConfig (HardForkBlock xs) -> PerEraCodecConfig xs
hardForkCodecConfigPerEra CodecConfig (HardForkBlock xs)
ccfg

  decodeResult CodecConfig (HardForkBlock xs)
_ BlockNodeToClientVersion (HardForkBlock xs)
_       (QueryAnytime QueryAnytime result
qry EraIndex (x : xs1)
_) = QueryAnytime result -> forall s. Decoder s result
forall result. QueryAnytime result -> forall s. Decoder s result
decodeQueryAnytimeResult      QueryAnytime result
qry
  decodeResult CodecConfig (HardForkBlock xs)
_ BlockNodeToClientVersion (HardForkBlock xs)
version (QueryHardFork QueryHardFork (x : xs1) result
qry)  = EraParamsFormat
-> QueryHardFork (x : xs1) result -> forall s. Decoder s result
forall (xs :: [*]) result.
SListI xs =>
EraParamsFormat
-> QueryHardFork xs result -> forall s. Decoder s result
decodeQueryHardForkResult EraParamsFormat
epf QueryHardFork (x : xs1) result
qry
    where
      epf :: EraParamsFormat
epf = HardForkNodeToClientVersion (x : xs1) -> EraParamsFormat
forall (xs :: [*]).
HardForkNodeToClientVersion xs -> EraParamsFormat
eraParamsFormatFromVersion BlockNodeToClientVersion (HardForkBlock xs)
HardForkNodeToClientVersion (x : xs1)
version

eraParamsFormatFromVersion :: HardForkNodeToClientVersion xs -> EraParamsFormat
eraParamsFormatFromVersion :: forall (xs :: [*]).
HardForkNodeToClientVersion xs -> EraParamsFormat
eraParamsFormatFromVersion = \case
    HardForkNodeToClientDisabled BlockNodeToClientVersion x
_ -> HardForkEncoderException -> EraParamsFormat
forall a e. Exception e => e -> a
throw HardForkEncoderException
HardForkEncoderQueryHfcDisabled
    HardForkNodeToClientEnabled HardForkSpecificNodeToClientVersion
v NP EraNodeToClientVersion xs
_
      | HardForkSpecificNodeToClientVersion
v HardForkSpecificNodeToClientVersion
-> HardForkSpecificNodeToClientVersion -> Bool
forall a. Ord a => a -> a -> Bool
>= HardForkSpecificNodeToClientVersion
HardForkSpecificNodeToClientVersion3 -> EraParamsFormat
EraParamsWithGenesisWindow
      | Bool
otherwise                                 -> EraParamsFormat
EraParamsWithoutGenesisWindow

encodeQueryIfCurrentResult ::
     All SerialiseConstraintsHFC xs
  => NP CodecConfig xs
  -> NP EraNodeToClientVersion xs
  -> QueryIfCurrent xs result
  -> result -> Encoding
encodeQueryIfCurrentResult :: forall (xs :: [*]) result.
All SerialiseConstraintsHFC xs =>
NP CodecConfig xs
-> NP EraNodeToClientVersion xs
-> QueryIfCurrent xs result
-> result
-> Encoding
encodeQueryIfCurrentResult (CodecConfig x
c :* NP CodecConfig xs1
_) (EraNodeToClientEnabled BlockNodeToClientVersion x
v :* NP EraNodeToClientVersion xs1
_) (QZ BlockQuery x result
qry) =
    CodecConfig x
-> BlockNodeToClientVersion x
-> BlockQuery x result
-> result
-> Encoding
forall result.
CodecConfig x
-> BlockNodeToClientVersion x
-> BlockQuery x result
-> result
-> Encoding
forall blk (query :: * -> *) result.
SerialiseResult blk query =>
CodecConfig blk
-> BlockNodeToClientVersion blk
-> query result
-> result
-> Encoding
encodeResult CodecConfig x
c BlockNodeToClientVersion x
BlockNodeToClientVersion x
v BlockQuery x result
qry
encodeQueryIfCurrentResult (CodecConfig x
_ :* NP CodecConfig xs1
_) (EraNodeToClientVersion x
EraNodeToClientDisabled :* NP EraNodeToClientVersion xs1
_) (QZ BlockQuery x result
qry) =
    BlockQuery x result -> result -> Encoding
forall blk result.
SingleEraBlock blk =>
BlockQuery blk result -> result -> Encoding
qryDisabledEra BlockQuery x result
qry
  where
    qryDisabledEra :: forall blk result. SingleEraBlock blk
                   => BlockQuery blk result -> result -> Encoding
    qryDisabledEra :: forall blk result.
SingleEraBlock blk =>
BlockQuery blk result -> result -> Encoding
qryDisabledEra BlockQuery blk result
_ result
_ = HardForkEncoderException -> Encoding
forall a e. Exception e => e -> a
throw (HardForkEncoderException -> Encoding)
-> HardForkEncoderException -> Encoding
forall a b. (a -> b) -> a -> b
$ Proxy blk -> HardForkEncoderException
forall blk.
SingleEraBlock blk =>
Proxy blk -> HardForkEncoderException
disabledEraException (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @blk)
encodeQueryIfCurrentResult (CodecConfig x
_ :* NP CodecConfig xs1
cs) (EraNodeToClientVersion x
_ :* NP EraNodeToClientVersion xs1
vs) (QS QueryIfCurrent xs result
qry) =
    NP CodecConfig xs1
-> NP EraNodeToClientVersion xs1
-> QueryIfCurrent xs1 result
-> result
-> Encoding
forall (xs :: [*]) result.
All SerialiseConstraintsHFC xs =>
NP CodecConfig xs
-> NP EraNodeToClientVersion xs
-> QueryIfCurrent xs result
-> result
-> Encoding
encodeQueryIfCurrentResult NP CodecConfig xs1
cs NP EraNodeToClientVersion xs1
NP EraNodeToClientVersion xs1
vs QueryIfCurrent xs1 result
QueryIfCurrent xs result
qry
encodeQueryIfCurrentResult NP CodecConfig xs
Nil NP EraNodeToClientVersion xs
_ QueryIfCurrent xs result
qry =
    case QueryIfCurrent xs result
qry of {}

decodeQueryIfCurrentResult ::
     All SerialiseConstraintsHFC xs
  => NP CodecConfig xs
  -> NP EraNodeToClientVersion xs
  -> QueryIfCurrent xs result
  -> Decoder s result
decodeQueryIfCurrentResult :: forall (xs :: [*]) result s.
All SerialiseConstraintsHFC xs =>
NP CodecConfig xs
-> NP EraNodeToClientVersion xs
-> QueryIfCurrent xs result
-> Decoder s result
decodeQueryIfCurrentResult (CodecConfig x
c :* NP CodecConfig xs1
_) (EraNodeToClientEnabled BlockNodeToClientVersion x
v :* NP EraNodeToClientVersion xs1
_) (QZ BlockQuery x result
qry) =
    CodecConfig x
-> BlockNodeToClientVersion x
-> BlockQuery x result
-> forall s. Decoder s result
forall result.
CodecConfig x
-> BlockNodeToClientVersion x
-> BlockQuery x result
-> forall s. Decoder s result
forall blk (query :: * -> *) result.
SerialiseResult blk query =>
CodecConfig blk
-> BlockNodeToClientVersion blk
-> query result
-> forall s. Decoder s result
decodeResult CodecConfig x
c BlockNodeToClientVersion x
BlockNodeToClientVersion x
v BlockQuery x result
qry
decodeQueryIfCurrentResult (CodecConfig x
_ :* NP CodecConfig xs1
_) (EraNodeToClientVersion x
EraNodeToClientDisabled :* NP EraNodeToClientVersion xs1
_) (QZ BlockQuery x result
qry) =
    BlockQuery x result -> forall s. Decoder s result
forall blk result.
SingleEraBlock blk =>
BlockQuery blk result -> forall s. Decoder s result
qryDisabledEra BlockQuery x result
qry
  where
    qryDisabledEra :: forall blk result. SingleEraBlock blk
                   => BlockQuery blk result -> forall s. Decoder s result
    qryDisabledEra :: forall blk result.
SingleEraBlock blk =>
BlockQuery blk result -> forall s. Decoder s result
qryDisabledEra BlockQuery blk result
_ = String -> Decoder s result
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Decoder s result)
-> (HardForkEncoderException -> String)
-> HardForkEncoderException
-> Decoder s result
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HardForkEncoderException -> String
forall a. Show a => a -> String
show (HardForkEncoderException -> Decoder s result)
-> HardForkEncoderException -> Decoder s result
forall a b. (a -> b) -> a -> b
$ Proxy blk -> HardForkEncoderException
forall blk.
SingleEraBlock blk =>
Proxy blk -> HardForkEncoderException
disabledEraException (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @blk)
decodeQueryIfCurrentResult (CodecConfig x
_ :* NP CodecConfig xs1
cs) (EraNodeToClientVersion x
_ :* NP EraNodeToClientVersion xs1
vs) (QS QueryIfCurrent xs result
qry) =
    NP CodecConfig xs1
-> NP EraNodeToClientVersion xs1
-> QueryIfCurrent xs1 result
-> Decoder s result
forall (xs :: [*]) result s.
All SerialiseConstraintsHFC xs =>
NP CodecConfig xs
-> NP EraNodeToClientVersion xs
-> QueryIfCurrent xs result
-> Decoder s result
decodeQueryIfCurrentResult NP CodecConfig xs1
cs NP EraNodeToClientVersion xs1
NP EraNodeToClientVersion xs1
vs QueryIfCurrent xs1 result
QueryIfCurrent xs result
qry
decodeQueryIfCurrentResult NP CodecConfig xs
Nil NP EraNodeToClientVersion xs
_ QueryIfCurrent xs result
qry =
    case QueryIfCurrent xs result
qry of {}