{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}

{-# OPTIONS_GHC -Wno-orphans #-}

module Ouroboros.Consensus.Shelley.Node.Serialisation () where

import           Cardano.Ledger.Binary (fromCBOR, toCBOR)
import           Cardano.Ledger.Core (fromEraCBOR, toEraCBOR)
import qualified Cardano.Ledger.Shelley.API as SL
import qualified Cardano.Protocol.TPraos.API as SL
import           Codec.Serialise (decode, encode)
import           Control.Exception (Exception, throw)
import qualified Data.ByteString.Lazy as Lazy
import           Data.Typeable (Typeable)
import           Ouroboros.Consensus.Block
import           Ouroboros.Consensus.HeaderValidation
import           Ouroboros.Consensus.Ledger.SupportsMempool (GenTxId)
import           Ouroboros.Consensus.Node.Run
import           Ouroboros.Consensus.Node.Serialisation
import           Ouroboros.Consensus.Protocol.Praos (PraosState)
import qualified Ouroboros.Consensus.Protocol.Praos as Praos
import           Ouroboros.Consensus.Protocol.TPraos
import           Ouroboros.Consensus.Shelley.Eras
import           Ouroboros.Consensus.Shelley.Ledger
import           Ouroboros.Consensus.Shelley.Ledger.NetworkProtocolVersion ()
import           Ouroboros.Consensus.Shelley.Protocol.Abstract
                     (pHeaderBlockSize, pHeaderSize)
import           Ouroboros.Consensus.Storage.Serialisation
import           Ouroboros.Network.Block (Serialised, unwrapCBORinCBOR,
                     wrapCBORinCBOR)

{-------------------------------------------------------------------------------
  EncodeDisk & DecodeDisk
-------------------------------------------------------------------------------}

instance ShelleyCompatible proto era => HasBinaryBlockInfo (ShelleyBlock proto era) where
  getBinaryBlockInfo :: ShelleyBlock proto era -> BinaryBlockInfo
getBinaryBlockInfo = ShelleyBlock proto era -> BinaryBlockInfo
forall proto era.
ShelleyCompatible proto era =>
ShelleyBlock proto era -> BinaryBlockInfo
shelleyBinaryBlockInfo

instance ShelleyCompatible proto era => SerialiseDiskConstraints (ShelleyBlock proto era)

instance ShelleyCompatible proto era => EncodeDisk (ShelleyBlock proto era) (ShelleyBlock proto era) where
  encodeDisk :: CodecConfig (ShelleyBlock proto era)
-> ShelleyBlock proto era -> Encoding
encodeDisk CodecConfig (ShelleyBlock proto era)
_ = ShelleyBlock proto era -> Encoding
forall proto era.
ShelleyCompatible proto era =>
ShelleyBlock proto era -> Encoding
encodeShelleyBlock
instance ShelleyCompatible proto era => DecodeDisk (ShelleyBlock proto era) (Lazy.ByteString -> ShelleyBlock proto era) where
  decodeDisk :: CodecConfig (ShelleyBlock proto era)
-> forall s. Decoder s (ByteString -> ShelleyBlock proto era)
decodeDisk CodecConfig (ShelleyBlock proto era)
_ = Decoder s (ByteString -> ShelleyBlock proto era)
forall s. Decoder s (ByteString -> ShelleyBlock proto era)
forall proto era s.
ShelleyCompatible proto era =>
Decoder s (ByteString -> ShelleyBlock proto era)
decodeShelleyBlock

instance ShelleyCompatible proto era => EncodeDisk (ShelleyBlock proto era) (Header (ShelleyBlock proto era)) where
  encodeDisk :: CodecConfig (ShelleyBlock proto era)
-> Header (ShelleyBlock proto era) -> Encoding
encodeDisk CodecConfig (ShelleyBlock proto era)
_ = Header (ShelleyBlock proto era) -> Encoding
forall proto era.
ShelleyCompatible proto era =>
Header (ShelleyBlock proto era) -> Encoding
encodeShelleyHeader
instance ShelleyCompatible proto era => DecodeDisk (ShelleyBlock proto era) (Lazy.ByteString -> Header (ShelleyBlock proto era)) where
  decodeDisk :: CodecConfig (ShelleyBlock proto era)
-> forall s.
   Decoder s (ByteString -> Header (ShelleyBlock proto era))
decodeDisk CodecConfig (ShelleyBlock proto era)
_ = Decoder s (ByteString -> Header (ShelleyBlock proto era))
forall s. Decoder s (ByteString -> Header (ShelleyBlock proto era))
forall proto era s.
ShelleyCompatible proto era =>
Decoder s (ByteString -> Header (ShelleyBlock proto era))
decodeShelleyHeader

instance ShelleyCompatible proto era => EncodeDisk (ShelleyBlock proto era) (LedgerState (ShelleyBlock proto era)) where
  encodeDisk :: CodecConfig (ShelleyBlock proto era)
-> LedgerState (ShelleyBlock proto era) -> Encoding
encodeDisk CodecConfig (ShelleyBlock proto era)
_ = LedgerState (ShelleyBlock proto era) -> Encoding
forall proto era.
ShelleyCompatible proto era =>
LedgerState (ShelleyBlock proto era) -> Encoding
encodeShelleyLedgerState
instance ShelleyCompatible proto era => DecodeDisk (ShelleyBlock proto era) (LedgerState (ShelleyBlock proto era)) where
  decodeDisk :: CodecConfig (ShelleyBlock proto era)
-> forall s. Decoder s (LedgerState (ShelleyBlock proto era))
decodeDisk CodecConfig (ShelleyBlock proto era)
_ = Decoder s (LedgerState (ShelleyBlock proto era))
forall era proto s.
ShelleyCompatible proto era =>
Decoder s (LedgerState (ShelleyBlock proto era))
decodeShelleyLedgerState

-- | @'ChainDepState' ('BlockProtocol' ('ShelleyBlock' era))@
instance (ShelleyCompatible proto era, EraCrypto era ~ c, SL.PraosCrypto c) => EncodeDisk (ShelleyBlock proto era) (TPraosState c) where
  encodeDisk :: CodecConfig (ShelleyBlock proto era) -> TPraosState c -> Encoding
encodeDisk CodecConfig (ShelleyBlock proto era)
_ = TPraosState c -> Encoding
forall a. Serialise a => a -> Encoding
encode
-- | @'ChainDepState' ('BlockProtocol' ('ShelleyBlock' era))@
instance (ShelleyCompatible proto era, EraCrypto era ~ c, SL.PraosCrypto c) => DecodeDisk (ShelleyBlock proto era) (TPraosState c) where
  decodeDisk :: CodecConfig (ShelleyBlock proto era)
-> forall s. Decoder s (TPraosState c)
decodeDisk CodecConfig (ShelleyBlock proto era)
_ = Decoder s (TPraosState c)
forall s. Decoder s (TPraosState c)
forall a s. Serialise a => Decoder s a
decode

instance (ShelleyCompatible proto era, EraCrypto era ~ c, Praos.PraosCrypto c) => EncodeDisk (ShelleyBlock proto era) (PraosState c) where
  encodeDisk :: CodecConfig (ShelleyBlock proto era) -> PraosState c -> Encoding
encodeDisk CodecConfig (ShelleyBlock proto era)
_ = PraosState c -> Encoding
forall a. Serialise a => a -> Encoding
encode
-- | @'ChainDepState' ('BlockProtocol' ('ShelleyBlock' era))@
instance (ShelleyCompatible proto era, EraCrypto era ~ c, Praos.PraosCrypto c) => DecodeDisk (ShelleyBlock proto era) (PraosState c) where
  decodeDisk :: CodecConfig (ShelleyBlock proto era)
-> forall s. Decoder s (PraosState c)
decodeDisk CodecConfig (ShelleyBlock proto era)
_ = Decoder s (PraosState c)
forall s. Decoder s (PraosState c)
forall a s. Serialise a => Decoder s a
decode
instance ShelleyCompatible proto era
  => EncodeDisk (ShelleyBlock proto era) (AnnTip (ShelleyBlock proto era)) where
  encodeDisk :: CodecConfig (ShelleyBlock proto era)
-> AnnTip (ShelleyBlock proto era) -> Encoding
encodeDisk CodecConfig (ShelleyBlock proto era)
_ = AnnTip (ShelleyBlock proto era) -> Encoding
forall proto era.
ShelleyCompatible proto era =>
AnnTip (ShelleyBlock proto era) -> Encoding
encodeShelleyAnnTip
instance ShelleyCompatible proto era
  =>  DecodeDisk (ShelleyBlock proto era) (AnnTip (ShelleyBlock proto era)) where
  decodeDisk :: CodecConfig (ShelleyBlock proto era)
-> forall s. Decoder s (AnnTip (ShelleyBlock proto era))
decodeDisk CodecConfig (ShelleyBlock proto era)
_ = Decoder s (AnnTip (ShelleyBlock proto era))
forall proto era s.
ShelleyCompatible proto era =>
Decoder s (AnnTip (ShelleyBlock proto era))
decodeShelleyAnnTip

{-------------------------------------------------------------------------------
  SerialiseNodeToNode
-------------------------------------------------------------------------------}

instance ShelleyCompatible proto era
  => SerialiseNodeToNodeConstraints (ShelleyBlock proto era) where
  estimateBlockSize :: Header (ShelleyBlock proto era) -> SizeInBytes
estimateBlockSize Header (ShelleyBlock proto era)
hdr = SizeInBytes
overhead SizeInBytes -> SizeInBytes -> SizeInBytes
forall a. Num a => a -> a -> a
+ SizeInBytes
hdrSize SizeInBytes -> SizeInBytes -> SizeInBytes
forall a. Num a => a -> a -> a
+ SizeInBytes
bodySize
    where
      -- The maximum block size is 65536, the CBOR-in-CBOR tag for this block
      -- is:
      --
      -- > D8 18          # tag(24)
      -- >    1A 00010000 # bytes(65536)
      --
      -- Which is 7 bytes, enough for up to 4294967295 bytes.
      overhead :: SizeInBytes
overhead = SizeInBytes
7 {- CBOR-in-CBOR -} SizeInBytes -> SizeInBytes -> SizeInBytes
forall a. Num a => a -> a -> a
+ SizeInBytes
1 {- encodeListLen -}
      bodySize :: SizeInBytes
bodySize = Natural -> SizeInBytes
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Natural -> SizeInBytes)
-> (Header (ShelleyBlock proto era) -> Natural)
-> Header (ShelleyBlock proto era)
-> SizeInBytes
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShelleyProtocolHeader proto -> Natural
forall proto.
ProtocolHeaderSupportsEnvelope proto =>
ShelleyProtocolHeader proto -> Natural
pHeaderBlockSize (ShelleyProtocolHeader proto -> Natural)
-> (Header (ShelleyBlock proto era) -> ShelleyProtocolHeader proto)
-> Header (ShelleyBlock proto era)
-> Natural
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Header (ShelleyBlock proto era) -> ShelleyProtocolHeader proto
forall proto era.
Header (ShelleyBlock proto era) -> ShelleyProtocolHeader proto
shelleyHeaderRaw (Header (ShelleyBlock proto era) -> SizeInBytes)
-> Header (ShelleyBlock proto era) -> SizeInBytes
forall a b. (a -> b) -> a -> b
$ Header (ShelleyBlock proto era)
hdr
      hdrSize :: SizeInBytes
hdrSize  = Natural -> SizeInBytes
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Natural -> SizeInBytes)
-> (Header (ShelleyBlock proto era) -> Natural)
-> Header (ShelleyBlock proto era)
-> SizeInBytes
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShelleyProtocolHeader proto -> Natural
forall proto.
ProtocolHeaderSupportsEnvelope proto =>
ShelleyProtocolHeader proto -> Natural
pHeaderSize (ShelleyProtocolHeader proto -> Natural)
-> (Header (ShelleyBlock proto era) -> ShelleyProtocolHeader proto)
-> Header (ShelleyBlock proto era)
-> Natural
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Header (ShelleyBlock proto era) -> ShelleyProtocolHeader proto
forall proto era.
Header (ShelleyBlock proto era) -> ShelleyProtocolHeader proto
shelleyHeaderRaw (Header (ShelleyBlock proto era) -> SizeInBytes)
-> Header (ShelleyBlock proto era) -> SizeInBytes
forall a b. (a -> b) -> a -> b
$ Header (ShelleyBlock proto era)
hdr

-- | CBOR-in-CBOR for the annotation. This also makes it compatible with the
-- wrapped ('Serialised') variant.
instance ShelleyCompatible proto era
  => SerialiseNodeToNode (ShelleyBlock proto era) (ShelleyBlock proto era) where
  encodeNodeToNode :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToNodeVersion (ShelleyBlock proto era)
-> ShelleyBlock proto era
-> Encoding
encodeNodeToNode CodecConfig (ShelleyBlock proto era)
_ BlockNodeToNodeVersion (ShelleyBlock proto era)
_ = (ShelleyBlock proto era -> Encoding)
-> ShelleyBlock proto era -> Encoding
forall a. (a -> Encoding) -> a -> Encoding
wrapCBORinCBOR   ShelleyBlock proto era -> Encoding
forall proto era.
ShelleyCompatible proto era =>
ShelleyBlock proto era -> Encoding
encodeShelleyBlock
  decodeNodeToNode :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToNodeVersion (ShelleyBlock proto era)
-> forall s. Decoder s (ShelleyBlock proto era)
decodeNodeToNode CodecConfig (ShelleyBlock proto era)
_ BlockNodeToNodeVersion (ShelleyBlock proto era)
_ = (forall s. Decoder s (ByteString -> ShelleyBlock proto era))
-> forall s. Decoder s (ShelleyBlock proto era)
forall a.
(forall s. Decoder s (ByteString -> a)) -> forall s. Decoder s a
unwrapCBORinCBOR Decoder s (ByteString -> ShelleyBlock proto era)
forall s. Decoder s (ByteString -> ShelleyBlock proto era)
forall proto era s.
ShelleyCompatible proto era =>
Decoder s (ByteString -> ShelleyBlock proto era)
decodeShelleyBlock

-- | 'Serialised' uses CBOR-in-CBOR by default.
instance SerialiseNodeToNode (ShelleyBlock proto era) (Serialised (ShelleyBlock proto era))
  -- Default instance

-- | CBOR-in-CBOR to be compatible with the wrapped ('Serialised') variant.
instance ShelleyCompatible proto era
  => SerialiseNodeToNode (ShelleyBlock proto era) (Header (ShelleyBlock proto era)) where
  encodeNodeToNode :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToNodeVersion (ShelleyBlock proto era)
-> Header (ShelleyBlock proto era)
-> Encoding
encodeNodeToNode CodecConfig (ShelleyBlock proto era)
_ BlockNodeToNodeVersion (ShelleyBlock proto era)
_ = (Header (ShelleyBlock proto era) -> Encoding)
-> Header (ShelleyBlock proto era) -> Encoding
forall a. (a -> Encoding) -> a -> Encoding
wrapCBORinCBOR   Header (ShelleyBlock proto era) -> Encoding
forall proto era.
ShelleyCompatible proto era =>
Header (ShelleyBlock proto era) -> Encoding
encodeShelleyHeader
  decodeNodeToNode :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToNodeVersion (ShelleyBlock proto era)
-> forall s. Decoder s (Header (ShelleyBlock proto era))
decodeNodeToNode CodecConfig (ShelleyBlock proto era)
_ BlockNodeToNodeVersion (ShelleyBlock proto era)
_ = (forall s.
 Decoder s (ByteString -> Header (ShelleyBlock proto era)))
-> forall s. Decoder s (Header (ShelleyBlock proto era))
forall a.
(forall s. Decoder s (ByteString -> a)) -> forall s. Decoder s a
unwrapCBORinCBOR Decoder s (ByteString -> Header (ShelleyBlock proto era))
forall s. Decoder s (ByteString -> Header (ShelleyBlock proto era))
forall proto era s.
ShelleyCompatible proto era =>
Decoder s (ByteString -> Header (ShelleyBlock proto era))
decodeShelleyHeader

-- | We use CBOR-in-CBOR
instance SerialiseNodeToNode (ShelleyBlock proto era) (SerialisedHeader (ShelleyBlock proto era)) where
  encodeNodeToNode :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToNodeVersion (ShelleyBlock proto era)
-> SerialisedHeader (ShelleyBlock proto era)
-> Encoding
encodeNodeToNode CodecConfig (ShelleyBlock proto era)
_ BlockNodeToNodeVersion (ShelleyBlock proto era)
_ = SerialisedHeader (ShelleyBlock proto era) -> Encoding
forall blk.
TrivialDependency (NestedCtxt_ blk Header) =>
SerialisedHeader blk -> Encoding
encodeTrivialSerialisedHeader
  decodeNodeToNode :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToNodeVersion (ShelleyBlock proto era)
-> forall s. Decoder s (SerialisedHeader (ShelleyBlock proto era))
decodeNodeToNode CodecConfig (ShelleyBlock proto era)
_ BlockNodeToNodeVersion (ShelleyBlock proto era)
_ = Decoder s (SerialisedHeader (ShelleyBlock proto era))
forall s. Decoder s (SerialisedHeader (ShelleyBlock proto era))
forall blk s.
TrivialDependency (NestedCtxt_ blk Header) =>
Decoder s (SerialisedHeader blk)
decodeTrivialSerialisedHeader

-- | The @To/FromCBOR@ instances defined in @cardano-ledger@ use
-- CBOR-in-CBOR to get the annotation.
instance ShelleyCompatible proto era
  => SerialiseNodeToNode (ShelleyBlock proto era) (GenTx (ShelleyBlock proto era)) where
  encodeNodeToNode :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToNodeVersion (ShelleyBlock proto era)
-> GenTx (ShelleyBlock proto era)
-> Encoding
encodeNodeToNode CodecConfig (ShelleyBlock proto era)
_ BlockNodeToNodeVersion (ShelleyBlock proto era)
_ = GenTx (ShelleyBlock proto era) -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR
  decodeNodeToNode :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToNodeVersion (ShelleyBlock proto era)
-> forall s. Decoder s (GenTx (ShelleyBlock proto era))
decodeNodeToNode CodecConfig (ShelleyBlock proto era)
_ BlockNodeToNodeVersion (ShelleyBlock proto era)
_ = Decoder s (GenTx (ShelleyBlock proto era))
forall s. Decoder s (GenTx (ShelleyBlock proto era))
forall a s. FromCBOR a => Decoder s a
fromCBOR

instance ShelleyCompatible proto era
  => SerialiseNodeToNode (ShelleyBlock proto era) (GenTxId (ShelleyBlock proto era)) where
  encodeNodeToNode :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToNodeVersion (ShelleyBlock proto era)
-> GenTxId (ShelleyBlock proto era)
-> Encoding
encodeNodeToNode CodecConfig (ShelleyBlock proto era)
_ BlockNodeToNodeVersion (ShelleyBlock proto era)
_ = forall era t. (Era era, EncCBOR t) => t -> Encoding
toEraCBOR @era
  decodeNodeToNode :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToNodeVersion (ShelleyBlock proto era)
-> forall s. Decoder s (GenTxId (ShelleyBlock proto era))
decodeNodeToNode CodecConfig (ShelleyBlock proto era)
_ BlockNodeToNodeVersion (ShelleyBlock proto era)
_ = forall era t s. (Era era, DecCBOR t) => Decoder s t
fromEraCBOR @era

{-------------------------------------------------------------------------------
  SerialiseNodeToClient
-------------------------------------------------------------------------------}

-- | Exception thrown in the encoders
data ShelleyEncoderException era proto =
    -- | A query was submitted that is not supported by the given
    -- 'ShelleyNodeToClientVersion'.
    ShelleyEncoderUnsupportedQuery
         (SomeSecond BlockQuery (ShelleyBlock proto era))
         ShelleyNodeToClientVersion
  deriving (Int -> ShelleyEncoderException era proto -> ShowS
[ShelleyEncoderException era proto] -> ShowS
ShelleyEncoderException era proto -> String
(Int -> ShelleyEncoderException era proto -> ShowS)
-> (ShelleyEncoderException era proto -> String)
-> ([ShelleyEncoderException era proto] -> ShowS)
-> Show (ShelleyEncoderException era proto)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall era proto. Int -> ShelleyEncoderException era proto -> ShowS
forall era proto. [ShelleyEncoderException era proto] -> ShowS
forall era proto. ShelleyEncoderException era proto -> String
$cshowsPrec :: forall era proto. Int -> ShelleyEncoderException era proto -> ShowS
showsPrec :: Int -> ShelleyEncoderException era proto -> ShowS
$cshow :: forall era proto. ShelleyEncoderException era proto -> String
show :: ShelleyEncoderException era proto -> String
$cshowList :: forall era proto. [ShelleyEncoderException era proto] -> ShowS
showList :: [ShelleyEncoderException era proto] -> ShowS
Show)

instance (Typeable era, Typeable proto)
  => Exception (ShelleyEncoderException era proto)

instance ShelleyCompatible proto era
  => SerialiseNodeToClientConstraints (ShelleyBlock proto era)

-- | CBOR-in-CBOR for the annotation. This also makes it compatible with the
-- wrapped ('Serialised') variant.
instance ShelleyCompatible proto era
  => SerialiseNodeToClient (ShelleyBlock proto era) (ShelleyBlock proto era) where
  encodeNodeToClient :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToClientVersion (ShelleyBlock proto era)
-> ShelleyBlock proto era
-> Encoding
encodeNodeToClient CodecConfig (ShelleyBlock proto era)
_ BlockNodeToClientVersion (ShelleyBlock proto era)
_ = (ShelleyBlock proto era -> Encoding)
-> ShelleyBlock proto era -> Encoding
forall a. (a -> Encoding) -> a -> Encoding
wrapCBORinCBOR   ShelleyBlock proto era -> Encoding
forall proto era.
ShelleyCompatible proto era =>
ShelleyBlock proto era -> Encoding
encodeShelleyBlock
  decodeNodeToClient :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToClientVersion (ShelleyBlock proto era)
-> forall s. Decoder s (ShelleyBlock proto era)
decodeNodeToClient CodecConfig (ShelleyBlock proto era)
_ BlockNodeToClientVersion (ShelleyBlock proto era)
_ = (forall s. Decoder s (ByteString -> ShelleyBlock proto era))
-> forall s. Decoder s (ShelleyBlock proto era)
forall a.
(forall s. Decoder s (ByteString -> a)) -> forall s. Decoder s a
unwrapCBORinCBOR Decoder s (ByteString -> ShelleyBlock proto era)
forall s. Decoder s (ByteString -> ShelleyBlock proto era)
forall proto era s.
ShelleyCompatible proto era =>
Decoder s (ByteString -> ShelleyBlock proto era)
decodeShelleyBlock

-- | 'Serialised' uses CBOR-in-CBOR by default.
instance SerialiseNodeToClient (ShelleyBlock proto era) (Serialised (ShelleyBlock proto era))
  -- Default instance

-- | Uses CBOR-in-CBOR in the @To/FromCBOR@ instances to get the annotation.
instance ShelleyCompatible proto era
  => SerialiseNodeToClient (ShelleyBlock proto era) (GenTx (ShelleyBlock proto era)) where
  encodeNodeToClient :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToClientVersion (ShelleyBlock proto era)
-> GenTx (ShelleyBlock proto era)
-> Encoding
encodeNodeToClient CodecConfig (ShelleyBlock proto era)
_ BlockNodeToClientVersion (ShelleyBlock proto era)
_ = GenTx (ShelleyBlock proto era) -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR
  decodeNodeToClient :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToClientVersion (ShelleyBlock proto era)
-> forall s. Decoder s (GenTx (ShelleyBlock proto era))
decodeNodeToClient CodecConfig (ShelleyBlock proto era)
_ BlockNodeToClientVersion (ShelleyBlock proto era)
_ = Decoder s (GenTx (ShelleyBlock proto era))
forall s. Decoder s (GenTx (ShelleyBlock proto era))
forall a s. FromCBOR a => Decoder s a
fromCBOR

instance ShelleyCompatible proto era
  => SerialiseNodeToClient (ShelleyBlock proto era) (GenTxId (ShelleyBlock proto era)) where
  encodeNodeToClient :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToClientVersion (ShelleyBlock proto era)
-> GenTxId (ShelleyBlock proto era)
-> Encoding
encodeNodeToClient CodecConfig (ShelleyBlock proto era)
_ BlockNodeToClientVersion (ShelleyBlock proto era)
_ = forall era t. (Era era, EncCBOR t) => t -> Encoding
toEraCBOR @era
  decodeNodeToClient :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToClientVersion (ShelleyBlock proto era)
-> forall s. Decoder s (GenTxId (ShelleyBlock proto era))
decodeNodeToClient CodecConfig (ShelleyBlock proto era)
_ BlockNodeToClientVersion (ShelleyBlock proto era)
_ = forall era t s. (Era era, DecCBOR t) => Decoder s t
fromEraCBOR @era

-- | @'ApplyTxErr' '(ShelleyBlock era)'@
instance ShelleyBasedEra era => SerialiseNodeToClient (ShelleyBlock proto era) (SL.ApplyTxError era) where
  encodeNodeToClient :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToClientVersion (ShelleyBlock proto era)
-> ApplyTxError era
-> Encoding
encodeNodeToClient CodecConfig (ShelleyBlock proto era)
_ BlockNodeToClientVersion (ShelleyBlock proto era)
_ = forall era t. (Era era, EncCBOR t) => t -> Encoding
toEraCBOR @era
  decodeNodeToClient :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToClientVersion (ShelleyBlock proto era)
-> forall s. Decoder s (ApplyTxError era)
decodeNodeToClient CodecConfig (ShelleyBlock proto era)
_ BlockNodeToClientVersion (ShelleyBlock proto era)
_ = forall era t s. (Era era, DecCBOR t) => Decoder s t
fromEraCBOR @era

instance ShelleyCompatible proto era
      => SerialiseNodeToClient (ShelleyBlock proto era) (SomeSecond BlockQuery (ShelleyBlock proto era)) where
  encodeNodeToClient :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToClientVersion (ShelleyBlock proto era)
-> SomeSecond BlockQuery (ShelleyBlock proto era)
-> Encoding
encodeNodeToClient CodecConfig (ShelleyBlock proto era)
_ BlockNodeToClientVersion (ShelleyBlock proto era)
version (SomeSecond BlockQuery (ShelleyBlock proto era) b
q)
    | BlockQuery (ShelleyBlock proto era) b
-> ShelleyNodeToClientVersion -> Bool
forall proto era result.
BlockQuery (ShelleyBlock proto era) result
-> ShelleyNodeToClientVersion -> Bool
querySupportedVersion BlockQuery (ShelleyBlock proto era) b
q BlockNodeToClientVersion (ShelleyBlock proto era)
ShelleyNodeToClientVersion
version
    = BlockQuery (ShelleyBlock proto era) b -> Encoding
forall era proto result.
ShelleyBasedEra era =>
BlockQuery (ShelleyBlock proto era) result -> Encoding
encodeShelleyQuery BlockQuery (ShelleyBlock proto era) b
q
    | Bool
otherwise
    = ShelleyEncoderException era proto -> Encoding
forall a e. Exception e => e -> a
throw (ShelleyEncoderException era proto -> Encoding)
-> ShelleyEncoderException era proto -> Encoding
forall a b. (a -> b) -> a -> b
$ SomeSecond BlockQuery (ShelleyBlock proto era)
-> ShelleyNodeToClientVersion -> ShelleyEncoderException era proto
forall era proto.
SomeSecond BlockQuery (ShelleyBlock proto era)
-> ShelleyNodeToClientVersion -> ShelleyEncoderException era proto
ShelleyEncoderUnsupportedQuery (BlockQuery (ShelleyBlock proto era) b
-> SomeSecond BlockQuery (ShelleyBlock proto era)
forall {k1} {k2} (f :: k1 -> k2 -> *) (a :: k1) (b :: k2).
f a b -> SomeSecond f a
SomeSecond BlockQuery (ShelleyBlock proto era) b
q) BlockNodeToClientVersion (ShelleyBlock proto era)
ShelleyNodeToClientVersion
version
  decodeNodeToClient :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToClientVersion (ShelleyBlock proto era)
-> forall s.
   Decoder s (SomeSecond BlockQuery (ShelleyBlock proto era))
decodeNodeToClient CodecConfig (ShelleyBlock proto era)
_ BlockNodeToClientVersion (ShelleyBlock proto era)
_ = Decoder s (SomeSecond BlockQuery (ShelleyBlock proto era))
forall s.
Decoder s (SomeSecond BlockQuery (ShelleyBlock proto era))
forall era proto s.
ShelleyBasedEra era =>
Decoder s (SomeSecond BlockQuery (ShelleyBlock proto era))
decodeShelleyQuery

instance ShelleyCompatible proto era => SerialiseResult (ShelleyBlock proto era) (BlockQuery (ShelleyBlock proto era)) where
  encodeResult :: forall result.
CodecConfig (ShelleyBlock proto era)
-> BlockNodeToClientVersion (ShelleyBlock proto era)
-> BlockQuery (ShelleyBlock proto era) result
-> result
-> Encoding
encodeResult CodecConfig (ShelleyBlock proto era)
_ = BlockNodeToClientVersion (ShelleyBlock proto era)
-> BlockQuery (ShelleyBlock proto era) result -> result -> Encoding
ShelleyNodeToClientVersion
-> BlockQuery (ShelleyBlock proto era) result -> result -> Encoding
forall proto era result.
ShelleyCompatible proto era =>
ShelleyNodeToClientVersion
-> BlockQuery (ShelleyBlock proto era) result -> result -> Encoding
encodeShelleyResult
  decodeResult :: forall result.
CodecConfig (ShelleyBlock proto era)
-> BlockNodeToClientVersion (ShelleyBlock proto era)
-> BlockQuery (ShelleyBlock proto era) result
-> forall s. Decoder s result
decodeResult CodecConfig (ShelleyBlock proto era)
_ = BlockNodeToClientVersion (ShelleyBlock proto era)
-> BlockQuery (ShelleyBlock proto era) result -> Decoder s result
ShelleyNodeToClientVersion
-> BlockQuery (ShelleyBlock proto era) result
-> forall s. Decoder s result
forall proto era result.
ShelleyCompatible proto era =>
ShelleyNodeToClientVersion
-> BlockQuery (ShelleyBlock proto era) result
-> forall s. Decoder s result
decodeShelleyResult

instance ShelleyCompatible proto era  => SerialiseNodeToClient (ShelleyBlock proto era) SlotNo where
  encodeNodeToClient :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToClientVersion (ShelleyBlock proto era)
-> SlotNo
-> Encoding
encodeNodeToClient CodecConfig (ShelleyBlock proto era)
_ BlockNodeToClientVersion (ShelleyBlock proto era)
_ = SlotNo -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR
  decodeNodeToClient :: CodecConfig (ShelleyBlock proto era)
-> BlockNodeToClientVersion (ShelleyBlock proto era)
-> forall s. Decoder s SlotNo
decodeNodeToClient CodecConfig (ShelleyBlock proto era)
_ BlockNodeToClientVersion (ShelleyBlock proto era)
_ = Decoder s SlotNo
forall s. Decoder s SlotNo
forall a s. FromCBOR a => Decoder s a
fromCBOR

{-------------------------------------------------------------------------------
  HFC support

  Since 'NestedCtxt' for Shelley is trivial, these instances can use defaults.
-------------------------------------------------------------------------------}

instance ShelleyBasedEra era => ReconstructNestedCtxt Header (ShelleyBlock proto era)
instance ShelleyBasedEra era => EncodeDiskDepIx (NestedCtxt Header) (ShelleyBlock proto era)
instance ShelleyCompatible proto era => EncodeDiskDep   (NestedCtxt Header) (ShelleyBlock proto era)
instance ShelleyBasedEra era => DecodeDiskDepIx (NestedCtxt Header) (ShelleyBlock proto era)
instance ShelleyCompatible proto era => DecodeDiskDep   (NestedCtxt Header) (ShelleyBlock proto era)