{-# LANGUAGE DataKinds                  #-}
{-# LANGUAGE DeriveAnyClass             #-}
{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE DerivingStrategies         #-}
{-# LANGUAGE EmptyCase                  #-}
{-# LANGUAGE EmptyDataDeriving          #-}
{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE FlexibleInstances          #-}
{-# LANGUAGE GADTs                      #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase                 #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE NamedFieldPuns             #-}
{-# LANGUAGE RankNTypes                 #-}
{-# LANGUAGE RecordWildCards            #-}
{-# LANGUAGE ScopedTypeVariables        #-}
{-# LANGUAGE StandaloneDeriving         #-}
{-# LANGUAGE TypeApplications           #-}
{-# LANGUAGE TypeFamilies               #-}
{-# LANGUAGE UndecidableInstances       #-}

-- | Simple block to go with the mock ledger
--
-- None of the definitions in this module depend on, or even refer to, any
-- specific consensus protocols.
module Ouroboros.Consensus.Mock.Ledger.Block (
    BlockQuery (..)
  , Header (..)
  , SimpleBlock
  , SimpleBlock' (..)
  , SimpleBody (..)
  , SimpleHash
  , SimpleHeader
  , SimpleStdHeader (..)
    -- * Working with 'SimpleBlock'
  , countSimpleGenTxs
  , matchesSimpleHeader
  , mkSimpleHeader
    -- * Configuration
  , BlockConfig (..)
  , CodecConfig (..)
  , SimpleLedgerConfig (..)
  , StorageConfig (..)
    -- * Protocol-specific part
  , MockProtocolSpecific (..)
    -- * 'UpdateLedger'
  , LedgerState (..)
  , Ticked (..)
  , genesisSimpleLedgerState
  , updateSimpleLedgerState
    -- * 'ApplyTx' (mempool support)
  , GenTx (..)
  , TxId (..)
  , Validated (..)
  , mkSimpleGenTx
  , txSize
    -- * Crypto
  , SimpleCrypto
  , SimpleMockCrypto
  , SimpleStandardCrypto
    -- * Serialisation
  , decodeSimpleHeader
  , encodeSimpleHeader
  , simpleBlockBinaryBlockInfo
  ) where

import qualified Codec.CBOR.Decoding as CBOR
import qualified Codec.CBOR.Encoding as CBOR
import           Codec.Serialise (Serialise (..), serialise)
import           Control.Monad.Except
import qualified Data.ByteString.Lazy as Lazy
import           Data.Kind (Type)
import           Data.Proxy
import           Data.Typeable
import           Data.Word
import           GHC.Generics (Generic)
import           NoThunks.Class (NoThunks (..))

import           Cardano.Binary (ToCBOR (..))
import           Cardano.Crypto.Hash (Hash, HashAlgorithm, SHA256, ShortHash)
import qualified Cardano.Crypto.Hash as Hash

import           Ouroboros.Consensus.Block
import           Ouroboros.Consensus.Config
import           Ouroboros.Consensus.HardFork.Abstract
import qualified Ouroboros.Consensus.HardFork.History as HardFork
import           Ouroboros.Consensus.HeaderValidation
import           Ouroboros.Consensus.Ledger.Abstract
import           Ouroboros.Consensus.Ledger.CommonProtocolParams
import           Ouroboros.Consensus.Ledger.Extended
import           Ouroboros.Consensus.Ledger.Inspect
import           Ouroboros.Consensus.Ledger.Query
import           Ouroboros.Consensus.Ledger.SupportsMempool
import           Ouroboros.Consensus.Ledger.SupportsPeerSelection
import           Ouroboros.Consensus.Mock.Ledger.Address
import           Ouroboros.Consensus.Mock.Ledger.State
import qualified Ouroboros.Consensus.Mock.Ledger.UTxO as Mock
import           Ouroboros.Consensus.Util (ShowProxy (..), hashFromBytesShortE,
                     (..:), (.:))
import           Ouroboros.Consensus.Util.Condense
import           Ouroboros.Consensus.Util.Orphans ()

import           Ouroboros.Consensus.Storage.Common (BinaryBlockInfo (..))

{-------------------------------------------------------------------------------
  Definition of a block

  The primed versions allow to vary the @ext@ parameter independently of the
  previous block hash.
-------------------------------------------------------------------------------}

type SimpleBlock  c ext = SimpleBlock'  c ext ext
type SimpleHeader c ext = Header (SimpleBlock c ext)

data SimpleBlock' c ext ext' = SimpleBlock {
      SimpleBlock' c ext ext' -> Header (SimpleBlock' c ext ext')
simpleHeader :: Header (SimpleBlock' c ext ext')
    , SimpleBlock' c ext ext' -> SimpleBody
simpleBody   :: SimpleBody
    }
  deriving ((forall x.
 SimpleBlock' c ext ext' -> Rep (SimpleBlock' c ext ext') x)
-> (forall x.
    Rep (SimpleBlock' c ext ext') x -> SimpleBlock' c ext ext')
-> Generic (SimpleBlock' c ext ext')
forall x.
Rep (SimpleBlock' c ext ext') x -> SimpleBlock' c ext ext'
forall x.
SimpleBlock' c ext ext' -> Rep (SimpleBlock' c ext ext') x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall c ext ext' x.
Rep (SimpleBlock' c ext ext') x -> SimpleBlock' c ext ext'
forall c ext ext' x.
SimpleBlock' c ext ext' -> Rep (SimpleBlock' c ext ext') x
$cto :: forall c ext ext' x.
Rep (SimpleBlock' c ext ext') x -> SimpleBlock' c ext ext'
$cfrom :: forall c ext ext' x.
SimpleBlock' c ext ext' -> Rep (SimpleBlock' c ext ext') x
Generic, Int -> SimpleBlock' c ext ext' -> ShowS
[SimpleBlock' c ext ext'] -> ShowS
SimpleBlock' c ext ext' -> String
(Int -> SimpleBlock' c ext ext' -> ShowS)
-> (SimpleBlock' c ext ext' -> String)
-> ([SimpleBlock' c ext ext'] -> ShowS)
-> Show (SimpleBlock' c ext ext')
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall c ext ext'.
(SimpleCrypto c, Show ext', Typeable ext) =>
Int -> SimpleBlock' c ext ext' -> ShowS
forall c ext ext'.
(SimpleCrypto c, Show ext', Typeable ext) =>
[SimpleBlock' c ext ext'] -> ShowS
forall c ext ext'.
(SimpleCrypto c, Show ext', Typeable ext) =>
SimpleBlock' c ext ext' -> String
showList :: [SimpleBlock' c ext ext'] -> ShowS
$cshowList :: forall c ext ext'.
(SimpleCrypto c, Show ext', Typeable ext) =>
[SimpleBlock' c ext ext'] -> ShowS
show :: SimpleBlock' c ext ext' -> String
$cshow :: forall c ext ext'.
(SimpleCrypto c, Show ext', Typeable ext) =>
SimpleBlock' c ext ext' -> String
showsPrec :: Int -> SimpleBlock' c ext ext' -> ShowS
$cshowsPrec :: forall c ext ext'.
(SimpleCrypto c, Show ext', Typeable ext) =>
Int -> SimpleBlock' c ext ext' -> ShowS
Show, SimpleBlock' c ext ext' -> SimpleBlock' c ext ext' -> Bool
(SimpleBlock' c ext ext' -> SimpleBlock' c ext ext' -> Bool)
-> (SimpleBlock' c ext ext' -> SimpleBlock' c ext ext' -> Bool)
-> Eq (SimpleBlock' c ext ext')
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall c ext ext'.
(SimpleCrypto c, Eq ext', Typeable ext) =>
SimpleBlock' c ext ext' -> SimpleBlock' c ext ext' -> Bool
/= :: SimpleBlock' c ext ext' -> SimpleBlock' c ext ext' -> Bool
$c/= :: forall c ext ext'.
(SimpleCrypto c, Eq ext', Typeable ext) =>
SimpleBlock' c ext ext' -> SimpleBlock' c ext ext' -> Bool
== :: SimpleBlock' c ext ext' -> SimpleBlock' c ext ext' -> Bool
$c== :: forall c ext ext'.
(SimpleCrypto c, Eq ext', Typeable ext) =>
SimpleBlock' c ext ext' -> SimpleBlock' c ext ext' -> Bool
Eq)

instance (SimpleCrypto c, Serialise ext') => Serialise (SimpleBlock' c ext ext') where
  encode :: SimpleBlock' c ext ext' -> Encoding
encode (SimpleBlock Header (SimpleBlock' c ext ext')
hdr SimpleBody
body) = [Encoding] -> Encoding
forall a. Monoid a => [a] -> a
mconcat [
        Word -> Encoding
CBOR.encodeListLen Word
2
      , Header (SimpleBlock' c ext ext') -> Encoding
forall a. Serialise a => a -> Encoding
encode Header (SimpleBlock' c ext ext')
hdr
      , SimpleBody -> Encoding
forall a. Serialise a => a -> Encoding
encode SimpleBody
body
      ]
  decode :: Decoder s (SimpleBlock' c ext ext')
decode = do
      Int -> Decoder s ()
forall s. Int -> Decoder s ()
CBOR.decodeListLenOf Int
2
      Header (SimpleBlock' c ext ext')
hdr  <- Decoder s (Header (SimpleBlock' c ext ext'))
forall a s. Serialise a => Decoder s a
decode
      SimpleBody
body <- Decoder s SimpleBody
forall a s. Serialise a => Decoder s a
decode
      SimpleBlock' c ext ext' -> Decoder s (SimpleBlock' c ext ext')
forall (m :: * -> *) a. Monad m => a -> m a
return (Header (SimpleBlock' c ext ext')
-> SimpleBody -> SimpleBlock' c ext ext'
forall c ext ext'.
Header (SimpleBlock' c ext ext')
-> SimpleBody -> SimpleBlock' c ext ext'
SimpleBlock Header (SimpleBlock' c ext ext')
hdr SimpleBody
body)

instance (Typeable c, Typeable ext, Typeable ext')
    => ShowProxy (SimpleBlock' c ext ext') where

data instance Header (SimpleBlock' c ext ext') = SimpleHeader {
      -- | The header hash
      --
      -- This is the hash of the header itself. This is a bit unpleasant,
      -- because it makes the hash look self-referential (when computing the
      -- hash we must ignore the 'simpleHeaderHash' field). However, the benefit
      -- is that we can give a 'HasHeader' instance that does not require
      -- a (static) 'Serialise' instance.
      Header (SimpleBlock' c ext ext')
-> HeaderHash (SimpleBlock' c ext ext')
simpleHeaderHash :: HeaderHash (SimpleBlock' c ext ext')

      -- | Fields required for the 'HasHeader' instance
    , Header (SimpleBlock' c ext ext') -> SimpleStdHeader c ext
simpleHeaderStd  :: SimpleStdHeader c ext

      -- | Header extension
      --
      -- This extension will be required when using 'SimpleBlock' for specific
      -- consensus protocols.
    , Header (SimpleBlock' c ext ext') -> ext'
simpleHeaderExt  :: ext'
    }
  deriving ((forall x.
 Header (SimpleBlock' c ext ext')
 -> Rep (Header (SimpleBlock' c ext ext')) x)
-> (forall x.
    Rep (Header (SimpleBlock' c ext ext')) x
    -> Header (SimpleBlock' c ext ext'))
-> Generic (Header (SimpleBlock' c ext ext'))
forall x.
Rep (Header (SimpleBlock' c ext ext')) x
-> Header (SimpleBlock' c ext ext')
forall x.
Header (SimpleBlock' c ext ext')
-> Rep (Header (SimpleBlock' c ext ext')) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall c ext ext' x.
Rep (Header (SimpleBlock' c ext ext')) x
-> Header (SimpleBlock' c ext ext')
forall c ext ext' x.
Header (SimpleBlock' c ext ext')
-> Rep (Header (SimpleBlock' c ext ext')) x
$cto :: forall c ext ext' x.
Rep (Header (SimpleBlock' c ext ext')) x
-> Header (SimpleBlock' c ext ext')
$cfrom :: forall c ext ext' x.
Header (SimpleBlock' c ext ext')
-> Rep (Header (SimpleBlock' c ext ext')) x
Generic, Int -> Header (SimpleBlock' c ext ext') -> ShowS
[Header (SimpleBlock' c ext ext')] -> ShowS
Header (SimpleBlock' c ext ext') -> String
(Int -> Header (SimpleBlock' c ext ext') -> ShowS)
-> (Header (SimpleBlock' c ext ext') -> String)
-> ([Header (SimpleBlock' c ext ext')] -> ShowS)
-> Show (Header (SimpleBlock' c ext ext'))
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall c ext ext'.
(SimpleCrypto c, Show ext', Typeable ext) =>
Int -> Header (SimpleBlock' c ext ext') -> ShowS
forall c ext ext'.
(SimpleCrypto c, Show ext', Typeable ext) =>
[Header (SimpleBlock' c ext ext')] -> ShowS
forall c ext ext'.
(SimpleCrypto c, Show ext', Typeable ext) =>
Header (SimpleBlock' c ext ext') -> String
showList :: [Header (SimpleBlock' c ext ext')] -> ShowS
$cshowList :: forall c ext ext'.
(SimpleCrypto c, Show ext', Typeable ext) =>
[Header (SimpleBlock' c ext ext')] -> ShowS
show :: Header (SimpleBlock' c ext ext') -> String
$cshow :: forall c ext ext'.
(SimpleCrypto c, Show ext', Typeable ext) =>
Header (SimpleBlock' c ext ext') -> String
showsPrec :: Int -> Header (SimpleBlock' c ext ext') -> ShowS
$cshowsPrec :: forall c ext ext'.
(SimpleCrypto c, Show ext', Typeable ext) =>
Int -> Header (SimpleBlock' c ext ext') -> ShowS
Show, Header (SimpleBlock' c ext ext')
-> Header (SimpleBlock' c ext ext') -> Bool
(Header (SimpleBlock' c ext ext')
 -> Header (SimpleBlock' c ext ext') -> Bool)
-> (Header (SimpleBlock' c ext ext')
    -> Header (SimpleBlock' c ext ext') -> Bool)
-> Eq (Header (SimpleBlock' c ext ext'))
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall c ext ext'.
(SimpleCrypto c, Eq ext', Typeable ext) =>
Header (SimpleBlock' c ext ext')
-> Header (SimpleBlock' c ext ext') -> Bool
/= :: Header (SimpleBlock' c ext ext')
-> Header (SimpleBlock' c ext ext') -> Bool
$c/= :: forall c ext ext'.
(SimpleCrypto c, Eq ext', Typeable ext) =>
Header (SimpleBlock' c ext ext')
-> Header (SimpleBlock' c ext ext') -> Bool
== :: Header (SimpleBlock' c ext ext')
-> Header (SimpleBlock' c ext ext') -> Bool
$c== :: forall c ext ext'.
(SimpleCrypto c, Eq ext', Typeable ext) =>
Header (SimpleBlock' c ext ext')
-> Header (SimpleBlock' c ext ext') -> Bool
Eq, Context -> Header (SimpleBlock' c ext ext') -> IO (Maybe ThunkInfo)
Proxy (Header (SimpleBlock' c ext ext')) -> String
(Context
 -> Header (SimpleBlock' c ext ext') -> IO (Maybe ThunkInfo))
-> (Context
    -> Header (SimpleBlock' c ext ext') -> IO (Maybe ThunkInfo))
-> (Proxy (Header (SimpleBlock' c ext ext')) -> String)
-> NoThunks (Header (SimpleBlock' c ext ext'))
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
forall c ext ext'.
(SimpleCrypto c, NoThunks ext', Typeable ext) =>
Context -> Header (SimpleBlock' c ext ext') -> IO (Maybe ThunkInfo)
forall c ext ext'.
(SimpleCrypto c, NoThunks ext', Typeable ext) =>
Proxy (Header (SimpleBlock' c ext ext')) -> String
showTypeOf :: Proxy (Header (SimpleBlock' c ext ext')) -> String
$cshowTypeOf :: forall c ext ext'.
(SimpleCrypto c, NoThunks ext', Typeable ext) =>
Proxy (Header (SimpleBlock' c ext ext')) -> String
wNoThunks :: Context -> Header (SimpleBlock' c ext ext') -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall c ext ext'.
(SimpleCrypto c, NoThunks ext', Typeable ext) =>
Context -> Header (SimpleBlock' c ext ext') -> IO (Maybe ThunkInfo)
noThunks :: Context -> Header (SimpleBlock' c ext ext') -> IO (Maybe ThunkInfo)
$cnoThunks :: forall c ext ext'.
(SimpleCrypto c, NoThunks ext', Typeable ext) =>
Context -> Header (SimpleBlock' c ext ext') -> IO (Maybe ThunkInfo)
NoThunks)

instance (Typeable c, Typeable ext, Typeable ext')
    => ShowProxy (Header (SimpleBlock' c ext ext')) where

instance (SimpleCrypto c, Typeable ext, Typeable ext')
      => GetHeader (SimpleBlock' c ext ext') where
  getHeader :: SimpleBlock' c ext ext' -> Header (SimpleBlock' c ext ext')
getHeader = SimpleBlock' c ext ext' -> Header (SimpleBlock' c ext ext')
forall c ext ext'.
SimpleBlock' c ext ext' -> Header (SimpleBlock' c ext ext')
simpleHeader

  blockMatchesHeader :: Header (SimpleBlock' c ext ext') -> SimpleBlock' c ext ext' -> Bool
blockMatchesHeader = Header (SimpleBlock' c ext ext') -> SimpleBlock' c ext ext' -> Bool
forall c ext ext' ext''.
SimpleCrypto c =>
Header (SimpleBlock' c ext ext')
-> SimpleBlock' c ext ext'' -> Bool
matchesSimpleHeader

  headerIsEBB :: Header (SimpleBlock' c ext ext') -> Maybe EpochNo
headerIsEBB = Maybe EpochNo -> Header (SimpleBlock' c ext ext') -> Maybe EpochNo
forall a b. a -> b -> a
const Maybe EpochNo
forall a. Maybe a
Nothing

data SimpleStdHeader c ext = SimpleStdHeader {
      SimpleStdHeader c ext -> ChainHash (SimpleBlock c ext)
simplePrev     :: ChainHash (SimpleBlock c ext)
    , SimpleStdHeader c ext -> SlotNo
simpleSlotNo   :: SlotNo
    , SimpleStdHeader c ext -> BlockNo
simpleBlockNo  :: BlockNo
    , SimpleStdHeader c ext -> Hash (SimpleHash c) SimpleBody
simpleBodyHash :: Hash (SimpleHash c) SimpleBody
    , SimpleStdHeader c ext -> Word32
simpleBodySize :: Word32
    }
  deriving stock    ((forall x. SimpleStdHeader c ext -> Rep (SimpleStdHeader c ext) x)
-> (forall x.
    Rep (SimpleStdHeader c ext) x -> SimpleStdHeader c ext)
-> Generic (SimpleStdHeader c ext)
forall x. Rep (SimpleStdHeader c ext) x -> SimpleStdHeader c ext
forall x. SimpleStdHeader c ext -> Rep (SimpleStdHeader c ext) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall c ext x.
Rep (SimpleStdHeader c ext) x -> SimpleStdHeader c ext
forall c ext x.
SimpleStdHeader c ext -> Rep (SimpleStdHeader c ext) x
$cto :: forall c ext x.
Rep (SimpleStdHeader c ext) x -> SimpleStdHeader c ext
$cfrom :: forall c ext x.
SimpleStdHeader c ext -> Rep (SimpleStdHeader c ext) x
Generic, Int -> SimpleStdHeader c ext -> ShowS
[SimpleStdHeader c ext] -> ShowS
SimpleStdHeader c ext -> String
(Int -> SimpleStdHeader c ext -> ShowS)
-> (SimpleStdHeader c ext -> String)
-> ([SimpleStdHeader c ext] -> ShowS)
-> Show (SimpleStdHeader c ext)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall c ext.
(SimpleCrypto c, Typeable ext) =>
Int -> SimpleStdHeader c ext -> ShowS
forall c ext.
(SimpleCrypto c, Typeable ext) =>
[SimpleStdHeader c ext] -> ShowS
forall c ext.
(SimpleCrypto c, Typeable ext) =>
SimpleStdHeader c ext -> String
showList :: [SimpleStdHeader c ext] -> ShowS
$cshowList :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
[SimpleStdHeader c ext] -> ShowS
show :: SimpleStdHeader c ext -> String
$cshow :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
SimpleStdHeader c ext -> String
showsPrec :: Int -> SimpleStdHeader c ext -> ShowS
$cshowsPrec :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
Int -> SimpleStdHeader c ext -> ShowS
Show, SimpleStdHeader c ext -> SimpleStdHeader c ext -> Bool
(SimpleStdHeader c ext -> SimpleStdHeader c ext -> Bool)
-> (SimpleStdHeader c ext -> SimpleStdHeader c ext -> Bool)
-> Eq (SimpleStdHeader c ext)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall c ext.
(SimpleCrypto c, Typeable ext) =>
SimpleStdHeader c ext -> SimpleStdHeader c ext -> Bool
/= :: SimpleStdHeader c ext -> SimpleStdHeader c ext -> Bool
$c/= :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
SimpleStdHeader c ext -> SimpleStdHeader c ext -> Bool
== :: SimpleStdHeader c ext -> SimpleStdHeader c ext -> Bool
$c== :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
SimpleStdHeader c ext -> SimpleStdHeader c ext -> Bool
Eq)
  deriving anyclass ([SimpleStdHeader c ext] -> Encoding
SimpleStdHeader c ext -> Encoding
(SimpleStdHeader c ext -> Encoding)
-> (forall s. Decoder s (SimpleStdHeader c ext))
-> ([SimpleStdHeader c ext] -> Encoding)
-> (forall s. Decoder s [SimpleStdHeader c ext])
-> Serialise (SimpleStdHeader c ext)
forall s. Decoder s [SimpleStdHeader c ext]
forall s. Decoder s (SimpleStdHeader c ext)
forall a.
(a -> Encoding)
-> (forall s. Decoder s a)
-> ([a] -> Encoding)
-> (forall s. Decoder s [a])
-> Serialise a
forall c ext. [SimpleStdHeader c ext] -> Encoding
forall c ext. SimpleStdHeader c ext -> Encoding
forall c ext s. Decoder s [SimpleStdHeader c ext]
forall c ext s. Decoder s (SimpleStdHeader c ext)
decodeList :: Decoder s [SimpleStdHeader c ext]
$cdecodeList :: forall c ext s. Decoder s [SimpleStdHeader c ext]
encodeList :: [SimpleStdHeader c ext] -> Encoding
$cencodeList :: forall c ext. [SimpleStdHeader c ext] -> Encoding
decode :: Decoder s (SimpleStdHeader c ext)
$cdecode :: forall c ext s. Decoder s (SimpleStdHeader c ext)
encode :: SimpleStdHeader c ext -> Encoding
$cencode :: forall c ext. SimpleStdHeader c ext -> Encoding
Serialise, Context -> SimpleStdHeader c ext -> IO (Maybe ThunkInfo)
Proxy (SimpleStdHeader c ext) -> String
(Context -> SimpleStdHeader c ext -> IO (Maybe ThunkInfo))
-> (Context -> SimpleStdHeader c ext -> IO (Maybe ThunkInfo))
-> (Proxy (SimpleStdHeader c ext) -> String)
-> NoThunks (SimpleStdHeader c ext)
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
forall c ext.
(SimpleCrypto c, Typeable ext) =>
Context -> SimpleStdHeader c ext -> IO (Maybe ThunkInfo)
forall c ext.
(SimpleCrypto c, Typeable ext) =>
Proxy (SimpleStdHeader c ext) -> String
showTypeOf :: Proxy (SimpleStdHeader c ext) -> String
$cshowTypeOf :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
Proxy (SimpleStdHeader c ext) -> String
wNoThunks :: Context -> SimpleStdHeader c ext -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
Context -> SimpleStdHeader c ext -> IO (Maybe ThunkInfo)
noThunks :: Context -> SimpleStdHeader c ext -> IO (Maybe ThunkInfo)
$cnoThunks :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
Context -> SimpleStdHeader c ext -> IO (Maybe ThunkInfo)
NoThunks)

data SimpleBody = SimpleBody {
      SimpleBody -> [Tx]
simpleTxs :: [Mock.Tx]
    }
  deriving ((forall x. SimpleBody -> Rep SimpleBody x)
-> (forall x. Rep SimpleBody x -> SimpleBody) -> Generic SimpleBody
forall x. Rep SimpleBody x -> SimpleBody
forall x. SimpleBody -> Rep SimpleBody x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SimpleBody x -> SimpleBody
$cfrom :: forall x. SimpleBody -> Rep SimpleBody x
Generic, Int -> SimpleBody -> ShowS
[SimpleBody] -> ShowS
SimpleBody -> String
(Int -> SimpleBody -> ShowS)
-> (SimpleBody -> String)
-> ([SimpleBody] -> ShowS)
-> Show SimpleBody
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SimpleBody] -> ShowS
$cshowList :: [SimpleBody] -> ShowS
show :: SimpleBody -> String
$cshow :: SimpleBody -> String
showsPrec :: Int -> SimpleBody -> ShowS
$cshowsPrec :: Int -> SimpleBody -> ShowS
Show, SimpleBody -> SimpleBody -> Bool
(SimpleBody -> SimpleBody -> Bool)
-> (SimpleBody -> SimpleBody -> Bool) -> Eq SimpleBody
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SimpleBody -> SimpleBody -> Bool
$c/= :: SimpleBody -> SimpleBody -> Bool
== :: SimpleBody -> SimpleBody -> Bool
$c== :: SimpleBody -> SimpleBody -> Bool
Eq)

instance Serialise SimpleBody where
  encode :: SimpleBody -> Encoding
encode (SimpleBody [Tx]
txs) = [Tx] -> Encoding
forall a. Serialise a => a -> Encoding
encode [Tx]
txs
  decode :: Decoder s SimpleBody
decode = [Tx] -> SimpleBody
SimpleBody ([Tx] -> SimpleBody) -> Decoder s [Tx] -> Decoder s SimpleBody
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s [Tx]
forall a s. Serialise a => Decoder s a
decode

{-------------------------------------------------------------------------------
  Working with 'SimpleBlock'
-------------------------------------------------------------------------------}

-- | Create a header by hashing the header without hash and adding to the
-- resulting value.
mkSimpleHeader :: SimpleCrypto c
               => (ext' -> CBOR.Encoding)
               -> SimpleStdHeader c ext
               -> ext'
               -> Header (SimpleBlock' c ext ext')
mkSimpleHeader :: (ext' -> Encoding)
-> SimpleStdHeader c ext
-> ext'
-> Header (SimpleBlock' c ext ext')
mkSimpleHeader ext' -> Encoding
encodeExt SimpleStdHeader c ext
std ext'
ext =
    Header (SimpleBlock' c ext ext')
R:HeaderSimpleBlock' c ext ext'
headerWithoutHash {
        simpleHeaderHash :: HeaderHash (SimpleBlock' c ext ext')
simpleHeaderHash = (Header (SimpleBlock' c ext ext') -> Encoding)
-> Header (SimpleBlock' c ext ext')
-> Hash (SimpleHash c) (Header (SimpleBlock' c ext ext'))
forall h a. HashAlgorithm h => (a -> Encoding) -> a -> Hash h a
Hash.hashWithSerialiser
                             ((ext' -> Encoding) -> Header (SimpleBlock' c ext ext') -> Encoding
forall ext' c ext.
(ext' -> Encoding) -> Header (SimpleBlock' c ext ext') -> Encoding
encodeSimpleHeader ext' -> Encoding
encodeExt)
                             Header (SimpleBlock' c ext ext')
headerWithoutHash
      }
  where
    headerWithoutHash :: Header (SimpleBlock' c ext ext')
headerWithoutHash = SimpleHeader :: forall c ext ext'.
HeaderHash (SimpleBlock' c ext ext')
-> SimpleStdHeader c ext
-> ext'
-> Header (SimpleBlock' c ext ext')
SimpleHeader {
        simpleHeaderHash :: HeaderHash (SimpleBlock' c ext ext')
simpleHeaderHash = String -> Hash (SimpleHash c) (Header (SimpleBlock' c ext ext'))
forall a. HasCallStack => String -> a
error String
"Serialise instances should ignore hash"
      , simpleHeaderStd :: SimpleStdHeader c ext
simpleHeaderStd  = SimpleStdHeader c ext
std
      , simpleHeaderExt :: ext'
simpleHeaderExt  = ext'
ext
      }

-- | Check whether the block matches the header
matchesSimpleHeader :: SimpleCrypto c
                    => Header (SimpleBlock' c ext ext')
                    -> SimpleBlock'  c ext ext''
                    -> Bool
matchesSimpleHeader :: Header (SimpleBlock' c ext ext')
-> SimpleBlock' c ext ext'' -> Bool
matchesSimpleHeader SimpleHeader{..} SimpleBlock {Header (SimpleBlock' c ext ext'')
SimpleBody
simpleBody :: SimpleBody
simpleHeader :: Header (SimpleBlock' c ext ext'')
simpleBody :: forall c ext ext'. SimpleBlock' c ext ext' -> SimpleBody
simpleHeader :: forall c ext ext'.
SimpleBlock' c ext ext' -> Header (SimpleBlock' c ext ext')
..} =
    Hash (SimpleHash c) SimpleBody
simpleBodyHash Hash (SimpleHash c) SimpleBody
-> Hash (SimpleHash c) SimpleBody -> Bool
forall a. Eq a => a -> a -> Bool
== (SimpleBody -> Encoding)
-> SimpleBody -> Hash (SimpleHash c) SimpleBody
forall h a. HashAlgorithm h => (a -> Encoding) -> a -> Hash h a
Hash.hashWithSerialiser SimpleBody -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR SimpleBody
simpleBody
  where
    SimpleStdHeader{Word32
SlotNo
BlockNo
ChainHash (SimpleBlock c ext)
Hash (SimpleHash c) SimpleBody
simpleBodySize :: Word32
simpleBlockNo :: BlockNo
simpleSlotNo :: SlotNo
simplePrev :: ChainHash (SimpleBlock c ext)
simpleBodyHash :: Hash (SimpleHash c) SimpleBody
simpleBodySize :: forall c ext. SimpleStdHeader c ext -> Word32
simpleBodyHash :: forall c ext.
SimpleStdHeader c ext -> Hash (SimpleHash c) SimpleBody
simpleBlockNo :: forall c ext. SimpleStdHeader c ext -> BlockNo
simpleSlotNo :: forall c ext. SimpleStdHeader c ext -> SlotNo
simplePrev :: forall c ext.
SimpleStdHeader c ext -> ChainHash (SimpleBlock c ext)
..} = SimpleStdHeader c ext
simpleHeaderStd

countSimpleGenTxs :: SimpleBlock c ext -> Word64
countSimpleGenTxs :: SimpleBlock c ext -> Word64
countSimpleGenTxs = Int -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word64)
-> (SimpleBlock c ext -> Int) -> SimpleBlock c ext -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [GenTx (SimpleBlock c ext)] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([GenTx (SimpleBlock c ext)] -> Int)
-> (SimpleBlock c ext -> [GenTx (SimpleBlock c ext)])
-> SimpleBlock c ext
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimpleBlock c ext -> [GenTx (SimpleBlock c ext)]
forall blk. HasTxs blk => blk -> [GenTx blk]
extractTxs

{-------------------------------------------------------------------------------
  HasHeader instance for SimpleHeader
-------------------------------------------------------------------------------}

instance (SimpleCrypto c, Typeable ext, Typeable ext')
      => HasHeader (Header (SimpleBlock' c ext ext')) where
  getHeaderFields :: Header (SimpleBlock' c ext ext')
-> HeaderFields (Header (SimpleBlock' c ext ext'))
getHeaderFields Header (SimpleBlock' c ext ext')
hdr = HeaderFields :: forall b. SlotNo -> BlockNo -> HeaderHash b -> HeaderFields b
HeaderFields {
        headerFieldHash :: HeaderHash (Header (SimpleBlock' c ext ext'))
headerFieldHash    = Header (SimpleBlock' c ext ext')
-> HeaderHash (SimpleBlock' c ext ext')
forall c ext ext'.
Header (SimpleBlock' c ext ext')
-> HeaderHash (SimpleBlock' c ext ext')
simpleHeaderHash Header (SimpleBlock' c ext ext')
hdr
      , headerFieldSlot :: SlotNo
headerFieldSlot    = SimpleStdHeader c ext -> SlotNo
forall c ext. SimpleStdHeader c ext -> SlotNo
simpleSlotNo  (SimpleStdHeader c ext -> SlotNo)
-> (Header (SimpleBlock' c ext ext') -> SimpleStdHeader c ext)
-> Header (SimpleBlock' c ext ext')
-> SlotNo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Header (SimpleBlock' c ext ext') -> SimpleStdHeader c ext
forall c ext ext'.
Header (SimpleBlock' c ext ext') -> SimpleStdHeader c ext
simpleHeaderStd (Header (SimpleBlock' c ext ext') -> SlotNo)
-> Header (SimpleBlock' c ext ext') -> SlotNo
forall a b. (a -> b) -> a -> b
$ Header (SimpleBlock' c ext ext')
hdr
      , headerFieldBlockNo :: BlockNo
headerFieldBlockNo = SimpleStdHeader c ext -> BlockNo
forall c ext. SimpleStdHeader c ext -> BlockNo
simpleBlockNo (SimpleStdHeader c ext -> BlockNo)
-> (Header (SimpleBlock' c ext ext') -> SimpleStdHeader c ext)
-> Header (SimpleBlock' c ext ext')
-> BlockNo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Header (SimpleBlock' c ext ext') -> SimpleStdHeader c ext
forall c ext ext'.
Header (SimpleBlock' c ext ext') -> SimpleStdHeader c ext
simpleHeaderStd (Header (SimpleBlock' c ext ext') -> BlockNo)
-> Header (SimpleBlock' c ext ext') -> BlockNo
forall a b. (a -> b) -> a -> b
$ Header (SimpleBlock' c ext ext')
hdr
      }

{-------------------------------------------------------------------------------
  HasHeader instance for SimpleBlock
-------------------------------------------------------------------------------}

type instance HeaderHash (SimpleBlock' c ext ext') =
  Hash (SimpleHash c) (Header (SimpleBlock' c ext ext'))

instance (SimpleCrypto c, Typeable ext, Typeable ext')
      => HasHeader (SimpleBlock' c ext ext') where
  getHeaderFields :: SimpleBlock' c ext ext' -> HeaderFields (SimpleBlock' c ext ext')
getHeaderFields = SimpleBlock' c ext ext' -> HeaderFields (SimpleBlock' c ext ext')
forall blk. GetHeader blk => blk -> HeaderFields blk
getBlockHeaderFields

instance (SimpleCrypto c, Typeable ext) => GetPrevHash (SimpleBlock c ext) where
  headerPrevHash :: Header (SimpleBlock c ext) -> ChainHash (SimpleBlock c ext)
headerPrevHash = SimpleStdHeader c ext -> ChainHash (SimpleBlock c ext)
forall c ext.
SimpleStdHeader c ext -> ChainHash (SimpleBlock c ext)
simplePrev (SimpleStdHeader c ext -> ChainHash (SimpleBlock c ext))
-> (Header (SimpleBlock c ext) -> SimpleStdHeader c ext)
-> Header (SimpleBlock c ext)
-> ChainHash (SimpleBlock c ext)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Header (SimpleBlock c ext) -> SimpleStdHeader c ext
forall c ext ext'.
Header (SimpleBlock' c ext ext') -> SimpleStdHeader c ext
simpleHeaderStd

instance (SimpleCrypto c, Typeable ext, Typeable ext')
      => StandardHash (SimpleBlock' c ext ext')

instance SimpleCrypto c => ConvertRawHash (SimpleBlock' c ext ext') where
  toShortRawHash :: proxy (SimpleBlock' c ext ext')
-> HeaderHash (SimpleBlock' c ext ext') -> ShortByteString
toShortRawHash   proxy (SimpleBlock' c ext ext')
_ = HeaderHash (SimpleBlock' c ext ext') -> ShortByteString
forall h a. Hash h a -> ShortByteString
Hash.hashToBytesShort
  fromShortRawHash :: proxy (SimpleBlock' c ext ext')
-> ShortByteString -> HeaderHash (SimpleBlock' c ext ext')
fromShortRawHash proxy (SimpleBlock' c ext ext')
_ = ShortByteString -> HeaderHash (SimpleBlock' c ext ext')
forall h a.
(HashAlgorithm h, HasCallStack) =>
ShortByteString -> Hash h a
hashFromBytesShortE
  hashSize :: proxy (SimpleBlock' c ext ext') -> Word32
hashSize         proxy (SimpleBlock' c ext ext')
_ = Word -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word -> Word32) -> Word -> Word32
forall a b. (a -> b) -> a -> b
$ Proxy (SimpleHash c) -> Word
forall h (proxy :: * -> *). HashAlgorithm h => proxy h -> Word
Hash.sizeHash (Proxy (SimpleHash c)
forall k (t :: k). Proxy t
Proxy @(SimpleHash c))

{-------------------------------------------------------------------------------
  HasMockTxs instance
-------------------------------------------------------------------------------}

instance Mock.HasMockTxs (SimpleBlock' c ext ext') where
  getMockTxs :: SimpleBlock' c ext ext' -> [Tx]
getMockTxs = SimpleBody -> [Tx]
forall a. HasMockTxs a => a -> [Tx]
Mock.getMockTxs (SimpleBody -> [Tx])
-> (SimpleBlock' c ext ext' -> SimpleBody)
-> SimpleBlock' c ext ext'
-> [Tx]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimpleBlock' c ext ext' -> SimpleBody
forall c ext ext'. SimpleBlock' c ext ext' -> SimpleBody
simpleBody

instance Mock.HasMockTxs SimpleBody where
  getMockTxs :: SimpleBody -> [Tx]
getMockTxs = SimpleBody -> [Tx]
simpleTxs

{-------------------------------------------------------------------------------
  Envelope validation
-------------------------------------------------------------------------------}

instance (SimpleCrypto c, Typeable ext) => HasAnnTip (SimpleBlock c ext)
  -- Use defaults

instance (SimpleCrypto c, Typeable ext) => BasicEnvelopeValidation (SimpleBlock c ext)
  -- Use defaults

instance (SimpleCrypto c, Typeable ext) => ValidateEnvelope (SimpleBlock c ext)
  -- Use defaults

{-------------------------------------------------------------------------------
  Block config
-------------------------------------------------------------------------------}

data instance BlockConfig (SimpleBlock c ext) = SimpleBlockConfig
  deriving stock   ((forall x.
 BlockConfig (SimpleBlock c ext)
 -> Rep (BlockConfig (SimpleBlock c ext)) x)
-> (forall x.
    Rep (BlockConfig (SimpleBlock c ext)) x
    -> BlockConfig (SimpleBlock c ext))
-> Generic (BlockConfig (SimpleBlock c ext))
forall x.
Rep (BlockConfig (SimpleBlock c ext)) x
-> BlockConfig (SimpleBlock c ext)
forall x.
BlockConfig (SimpleBlock c ext)
-> Rep (BlockConfig (SimpleBlock c ext)) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall c ext x.
Rep (BlockConfig (SimpleBlock c ext)) x
-> BlockConfig (SimpleBlock c ext)
forall c ext x.
BlockConfig (SimpleBlock c ext)
-> Rep (BlockConfig (SimpleBlock c ext)) x
$cto :: forall c ext x.
Rep (BlockConfig (SimpleBlock c ext)) x
-> BlockConfig (SimpleBlock c ext)
$cfrom :: forall c ext x.
BlockConfig (SimpleBlock c ext)
-> Rep (BlockConfig (SimpleBlock c ext)) x
Generic)
  deriving anyclass (Context -> BlockConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
Proxy (BlockConfig (SimpleBlock c ext)) -> String
(Context
 -> BlockConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo))
-> (Context
    -> BlockConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo))
-> (Proxy (BlockConfig (SimpleBlock c ext)) -> String)
-> NoThunks (BlockConfig (SimpleBlock c ext))
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
forall c ext.
Context -> BlockConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
forall c ext. Proxy (BlockConfig (SimpleBlock c ext)) -> String
showTypeOf :: Proxy (BlockConfig (SimpleBlock c ext)) -> String
$cshowTypeOf :: forall c ext. Proxy (BlockConfig (SimpleBlock c ext)) -> String
wNoThunks :: Context -> BlockConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall c ext.
Context -> BlockConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
noThunks :: Context -> BlockConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
$cnoThunks :: forall c ext.
Context -> BlockConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
NoThunks)

{-------------------------------------------------------------------------------
  Codec config
-------------------------------------------------------------------------------}

data instance CodecConfig (SimpleBlock c ext) = SimpleCodecConfig
  deriving stock    ((forall x.
 CodecConfig (SimpleBlock c ext)
 -> Rep (CodecConfig (SimpleBlock c ext)) x)
-> (forall x.
    Rep (CodecConfig (SimpleBlock c ext)) x
    -> CodecConfig (SimpleBlock c ext))
-> Generic (CodecConfig (SimpleBlock c ext))
forall x.
Rep (CodecConfig (SimpleBlock c ext)) x
-> CodecConfig (SimpleBlock c ext)
forall x.
CodecConfig (SimpleBlock c ext)
-> Rep (CodecConfig (SimpleBlock c ext)) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall c ext x.
Rep (CodecConfig (SimpleBlock c ext)) x
-> CodecConfig (SimpleBlock c ext)
forall c ext x.
CodecConfig (SimpleBlock c ext)
-> Rep (CodecConfig (SimpleBlock c ext)) x
$cto :: forall c ext x.
Rep (CodecConfig (SimpleBlock c ext)) x
-> CodecConfig (SimpleBlock c ext)
$cfrom :: forall c ext x.
CodecConfig (SimpleBlock c ext)
-> Rep (CodecConfig (SimpleBlock c ext)) x
Generic)
  deriving anyclass (Context -> CodecConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
Proxy (CodecConfig (SimpleBlock c ext)) -> String
(Context
 -> CodecConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo))
-> (Context
    -> CodecConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo))
-> (Proxy (CodecConfig (SimpleBlock c ext)) -> String)
-> NoThunks (CodecConfig (SimpleBlock c ext))
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
forall c ext.
Context -> CodecConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
forall c ext. Proxy (CodecConfig (SimpleBlock c ext)) -> String
showTypeOf :: Proxy (CodecConfig (SimpleBlock c ext)) -> String
$cshowTypeOf :: forall c ext. Proxy (CodecConfig (SimpleBlock c ext)) -> String
wNoThunks :: Context -> CodecConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall c ext.
Context -> CodecConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
noThunks :: Context -> CodecConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
$cnoThunks :: forall c ext.
Context -> CodecConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
NoThunks)

{-------------------------------------------------------------------------------
  Storage config
-------------------------------------------------------------------------------}

data instance StorageConfig (SimpleBlock c ext) = SimpleStorageConfig SecurityParam
  deriving stock    ((forall x.
 StorageConfig (SimpleBlock c ext)
 -> Rep (StorageConfig (SimpleBlock c ext)) x)
-> (forall x.
    Rep (StorageConfig (SimpleBlock c ext)) x
    -> StorageConfig (SimpleBlock c ext))
-> Generic (StorageConfig (SimpleBlock c ext))
forall x.
Rep (StorageConfig (SimpleBlock c ext)) x
-> StorageConfig (SimpleBlock c ext)
forall x.
StorageConfig (SimpleBlock c ext)
-> Rep (StorageConfig (SimpleBlock c ext)) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall c ext x.
Rep (StorageConfig (SimpleBlock c ext)) x
-> StorageConfig (SimpleBlock c ext)
forall c ext x.
StorageConfig (SimpleBlock c ext)
-> Rep (StorageConfig (SimpleBlock c ext)) x
$cto :: forall c ext x.
Rep (StorageConfig (SimpleBlock c ext)) x
-> StorageConfig (SimpleBlock c ext)
$cfrom :: forall c ext x.
StorageConfig (SimpleBlock c ext)
-> Rep (StorageConfig (SimpleBlock c ext)) x
Generic)
  deriving anyclass (Context
-> StorageConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
Proxy (StorageConfig (SimpleBlock c ext)) -> String
(Context
 -> StorageConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo))
-> (Context
    -> StorageConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo))
-> (Proxy (StorageConfig (SimpleBlock c ext)) -> String)
-> NoThunks (StorageConfig (SimpleBlock c ext))
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
forall c ext.
Context
-> StorageConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
forall c ext. Proxy (StorageConfig (SimpleBlock c ext)) -> String
showTypeOf :: Proxy (StorageConfig (SimpleBlock c ext)) -> String
$cshowTypeOf :: forall c ext. Proxy (StorageConfig (SimpleBlock c ext)) -> String
wNoThunks :: Context
-> StorageConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall c ext.
Context
-> StorageConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
noThunks :: Context
-> StorageConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
$cnoThunks :: forall c ext.
Context
-> StorageConfig (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
NoThunks)

{-------------------------------------------------------------------------------
  Hard fork history
-------------------------------------------------------------------------------}

instance HasHardForkHistory (SimpleBlock c ext) where
  type HardForkIndices (SimpleBlock c ext) = '[SimpleBlock c ext]
  hardForkSummary :: LedgerConfig (SimpleBlock c ext)
-> LedgerState (SimpleBlock c ext)
-> Summary (HardForkIndices (SimpleBlock c ext))
hardForkSummary = (LedgerConfig (SimpleBlock c ext) -> EraParams)
-> LedgerConfig (SimpleBlock c ext)
-> LedgerState (SimpleBlock c ext)
-> Summary '[SimpleBlock c ext]
forall blk.
(LedgerConfig blk -> EraParams)
-> LedgerConfig blk -> LedgerState blk -> Summary '[blk]
neverForksHardForkSummary LedgerConfig (SimpleBlock c ext) -> EraParams
forall c ext. SimpleLedgerConfig c ext -> EraParams
simpleLedgerEraParams

{-------------------------------------------------------------------------------
  Protocol specific constraints
-------------------------------------------------------------------------------}

class ( SimpleCrypto c
      , Typeable ext
      , Show     (MockLedgerConfig c ext)
      , NoThunks (MockLedgerConfig c ext)
      ) => MockProtocolSpecific c ext where
  type family MockLedgerConfig c ext :: Type

{-------------------------------------------------------------------------------
  Update the ledger
-------------------------------------------------------------------------------}

data SimpleLedgerConfig c ext = SimpleLedgerConfig {
      -- | Config required by the various kinds of mock block (PFT, Praos, ..)
      SimpleLedgerConfig c ext -> MockLedgerConfig c ext
simpleMockLedgerConfig :: !(MockLedgerConfig c ext)

      -- | Era parameters
    , SimpleLedgerConfig c ext -> EraParams
simpleLedgerEraParams  :: !HardFork.EraParams
    }
  deriving ((forall x.
 SimpleLedgerConfig c ext -> Rep (SimpleLedgerConfig c ext) x)
-> (forall x.
    Rep (SimpleLedgerConfig c ext) x -> SimpleLedgerConfig c ext)
-> Generic (SimpleLedgerConfig c ext)
forall x.
Rep (SimpleLedgerConfig c ext) x -> SimpleLedgerConfig c ext
forall x.
SimpleLedgerConfig c ext -> Rep (SimpleLedgerConfig c ext) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall c ext x.
Rep (SimpleLedgerConfig c ext) x -> SimpleLedgerConfig c ext
forall c ext x.
SimpleLedgerConfig c ext -> Rep (SimpleLedgerConfig c ext) x
$cto :: forall c ext x.
Rep (SimpleLedgerConfig c ext) x -> SimpleLedgerConfig c ext
$cfrom :: forall c ext x.
SimpleLedgerConfig c ext -> Rep (SimpleLedgerConfig c ext) x
Generic)

deriving instance Show (MockLedgerConfig c ext) => Show (SimpleLedgerConfig c ext)
deriving instance NoThunks (MockLedgerConfig c ext)
               => NoThunks (SimpleLedgerConfig c ext)

type instance LedgerCfg (LedgerState (SimpleBlock c ext)) = SimpleLedgerConfig c ext

instance GetTip (LedgerState (SimpleBlock c ext)) where
  getTip :: LedgerState (SimpleBlock c ext)
-> Point (LedgerState (SimpleBlock c ext))
getTip (SimpleLedgerState st) = Point (SimpleBlock c ext)
-> Point (LedgerState (SimpleBlock c ext))
forall b b'.
Coercible (HeaderHash b) (HeaderHash b') =>
Point b -> Point b'
castPoint (Point (SimpleBlock c ext)
 -> Point (LedgerState (SimpleBlock c ext)))
-> Point (SimpleBlock c ext)
-> Point (LedgerState (SimpleBlock c ext))
forall a b. (a -> b) -> a -> b
$ MockState (SimpleBlock c ext) -> Point (SimpleBlock c ext)
forall blk. MockState blk -> Point blk
mockTip MockState (SimpleBlock c ext)
st

instance GetTip (Ticked (LedgerState (SimpleBlock c ext))) where
  getTip :: Ticked (LedgerState (SimpleBlock c ext))
-> Point (Ticked (LedgerState (SimpleBlock c ext)))
getTip = Point (LedgerState (SimpleBlock c ext))
-> Point (Ticked (LedgerState (SimpleBlock c ext)))
forall b b'.
Coercible (HeaderHash b) (HeaderHash b') =>
Point b -> Point b'
castPoint (Point (LedgerState (SimpleBlock c ext))
 -> Point (Ticked (LedgerState (SimpleBlock c ext))))
-> (Ticked (LedgerState (SimpleBlock c ext))
    -> Point (LedgerState (SimpleBlock c ext)))
-> Ticked (LedgerState (SimpleBlock c ext))
-> Point (Ticked (LedgerState (SimpleBlock c ext)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerState (SimpleBlock c ext)
-> Point (LedgerState (SimpleBlock c ext))
forall l. GetTip l => l -> Point l
getTip (LedgerState (SimpleBlock c ext)
 -> Point (LedgerState (SimpleBlock c ext)))
-> (Ticked (LedgerState (SimpleBlock c ext))
    -> LedgerState (SimpleBlock c ext))
-> Ticked (LedgerState (SimpleBlock c ext))
-> Point (LedgerState (SimpleBlock c ext))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ticked (LedgerState (SimpleBlock c ext))
-> LedgerState (SimpleBlock c ext)
forall c ext.
Ticked (LedgerState (SimpleBlock c ext))
-> LedgerState (SimpleBlock c ext)
getTickedSimpleLedgerState

instance MockProtocolSpecific c ext
      => IsLedger (LedgerState (SimpleBlock c ext)) where
  type LedgerErr (LedgerState (SimpleBlock c ext)) = MockError (SimpleBlock c ext)

  type AuxLedgerEvent (LedgerState (SimpleBlock c ext)) = VoidLedgerEvent (SimpleBlock c ext)

  applyChainTickLedgerResult :: LedgerCfg (LedgerState (SimpleBlock c ext))
-> SlotNo
-> LedgerState (SimpleBlock c ext)
-> LedgerResult
     (LedgerState (SimpleBlock c ext))
     (Ticked (LedgerState (SimpleBlock c ext)))
applyChainTickLedgerResult LedgerCfg (LedgerState (SimpleBlock c ext))
_ SlotNo
_ = Ticked (LedgerState (SimpleBlock c ext))
-> LedgerResult
     (LedgerState (SimpleBlock c ext))
     (Ticked (LedgerState (SimpleBlock c ext)))
forall a l. a -> LedgerResult l a
pureLedgerResult (Ticked (LedgerState (SimpleBlock c ext))
 -> LedgerResult
      (LedgerState (SimpleBlock c ext))
      (Ticked (LedgerState (SimpleBlock c ext))))
-> (LedgerState (SimpleBlock c ext)
    -> Ticked (LedgerState (SimpleBlock c ext)))
-> LedgerState (SimpleBlock c ext)
-> LedgerResult
     (LedgerState (SimpleBlock c ext))
     (Ticked (LedgerState (SimpleBlock c ext)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerState (SimpleBlock c ext)
-> Ticked (LedgerState (SimpleBlock c ext))
forall c ext.
LedgerState (SimpleBlock c ext)
-> Ticked (LedgerState (SimpleBlock c ext))
TickedSimpleLedgerState

instance MockProtocolSpecific c ext
      => ApplyBlock (LedgerState (SimpleBlock c ext)) (SimpleBlock c ext) where
  applyBlockLedgerResult :: LedgerCfg (LedgerState (SimpleBlock c ext))
-> SimpleBlock c ext
-> Ticked (LedgerState (SimpleBlock c ext))
-> Except
     (LedgerErr (LedgerState (SimpleBlock c ext)))
     (LedgerResult
        (LedgerState (SimpleBlock c ext))
        (LedgerState (SimpleBlock c ext)))
applyBlockLedgerResult LedgerCfg (LedgerState (SimpleBlock c ext))
_ = (LedgerState (SimpleBlock c ext)
 -> LedgerResult
      (LedgerState (SimpleBlock c ext))
      (LedgerState (SimpleBlock c ext)))
-> ExceptT
     (MockError (SimpleBlock c ext))
     Identity
     (LedgerState (SimpleBlock c ext))
-> ExceptT
     (MockError (SimpleBlock c ext))
     Identity
     (LedgerResult
        (LedgerState (SimpleBlock c ext))
        (LedgerState (SimpleBlock c ext)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LedgerState (SimpleBlock c ext)
-> LedgerResult
     (LedgerState (SimpleBlock c ext)) (LedgerState (SimpleBlock c ext))
forall a l. a -> LedgerResult l a
pureLedgerResult (ExceptT
   (MockError (SimpleBlock c ext))
   Identity
   (LedgerState (SimpleBlock c ext))
 -> ExceptT
      (MockError (SimpleBlock c ext))
      Identity
      (LedgerResult
         (LedgerState (SimpleBlock c ext))
         (LedgerState (SimpleBlock c ext))))
-> (SimpleBlock c ext
    -> Ticked (LedgerState (SimpleBlock c ext))
    -> ExceptT
         (MockError (SimpleBlock c ext))
         Identity
         (LedgerState (SimpleBlock c ext)))
-> SimpleBlock c ext
-> Ticked (LedgerState (SimpleBlock c ext))
-> ExceptT
     (MockError (SimpleBlock c ext))
     Identity
     (LedgerResult
        (LedgerState (SimpleBlock c ext))
        (LedgerState (SimpleBlock c ext)))
forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z
.: SimpleBlock c ext
-> Ticked (LedgerState (SimpleBlock c ext))
-> ExceptT
     (MockError (SimpleBlock c ext))
     Identity
     (LedgerState (SimpleBlock c ext))
forall c ext.
(SimpleCrypto c, Typeable ext) =>
SimpleBlock c ext
-> TickedLedgerState (SimpleBlock c ext)
-> Except
     (MockError (SimpleBlock c ext)) (LedgerState (SimpleBlock c ext))
updateSimpleLedgerState

  reapplyBlockLedgerResult :: LedgerCfg (LedgerState (SimpleBlock c ext))
-> SimpleBlock c ext
-> Ticked (LedgerState (SimpleBlock c ext))
-> LedgerResult
     (LedgerState (SimpleBlock c ext)) (LedgerState (SimpleBlock c ext))
reapplyBlockLedgerResult =
      (Either
  (MockError (SimpleBlock c ext))
  (LedgerResult
     (LedgerState (SimpleBlock c ext))
     (LedgerState (SimpleBlock c ext)))
-> LedgerResult
     (LedgerState (SimpleBlock c ext)) (LedgerState (SimpleBlock c ext))
forall a p. Show a => Either a p -> p
mustSucceed (Either
   (MockError (SimpleBlock c ext))
   (LedgerResult
      (LedgerState (SimpleBlock c ext))
      (LedgerState (SimpleBlock c ext)))
 -> LedgerResult
      (LedgerState (SimpleBlock c ext))
      (LedgerState (SimpleBlock c ext)))
-> (ExceptT
      (MockError (SimpleBlock c ext))
      Identity
      (LedgerResult
         (LedgerState (SimpleBlock c ext))
         (LedgerState (SimpleBlock c ext)))
    -> Either
         (MockError (SimpleBlock c ext))
         (LedgerResult
            (LedgerState (SimpleBlock c ext))
            (LedgerState (SimpleBlock c ext))))
-> ExceptT
     (MockError (SimpleBlock c ext))
     Identity
     (LedgerResult
        (LedgerState (SimpleBlock c ext))
        (LedgerState (SimpleBlock c ext)))
-> LedgerResult
     (LedgerState (SimpleBlock c ext)) (LedgerState (SimpleBlock c ext))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExceptT
  (MockError (SimpleBlock c ext))
  Identity
  (LedgerResult
     (LedgerState (SimpleBlock c ext))
     (LedgerState (SimpleBlock c ext)))
-> Either
     (MockError (SimpleBlock c ext))
     (LedgerResult
        (LedgerState (SimpleBlock c ext))
        (LedgerState (SimpleBlock c ext)))
forall e a. Except e a -> Either e a
runExcept) (ExceptT
   (MockError (SimpleBlock c ext))
   Identity
   (LedgerResult
      (LedgerState (SimpleBlock c ext))
      (LedgerState (SimpleBlock c ext)))
 -> LedgerResult
      (LedgerState (SimpleBlock c ext))
      (LedgerState (SimpleBlock c ext)))
-> (SimpleLedgerConfig c ext
    -> SimpleBlock c ext
    -> Ticked (LedgerState (SimpleBlock c ext))
    -> ExceptT
         (MockError (SimpleBlock c ext))
         Identity
         (LedgerResult
            (LedgerState (SimpleBlock c ext))
            (LedgerState (SimpleBlock c ext))))
-> SimpleLedgerConfig c ext
-> SimpleBlock c ext
-> Ticked (LedgerState (SimpleBlock c ext))
-> LedgerResult
     (LedgerState (SimpleBlock c ext)) (LedgerState (SimpleBlock c ext))
forall y z x0 x1 x2.
(y -> z) -> (x0 -> x1 -> x2 -> y) -> x0 -> x1 -> x2 -> z
..: SimpleLedgerConfig c ext
-> SimpleBlock c ext
-> Ticked (LedgerState (SimpleBlock c ext))
-> ExceptT
     (MockError (SimpleBlock c ext))
     Identity
     (LedgerResult
        (LedgerState (SimpleBlock c ext))
        (LedgerState (SimpleBlock c ext)))
forall l blk.
(ApplyBlock l blk, HasCallStack) =>
LedgerCfg l
-> blk -> Ticked l -> Except (LedgerErr l) (LedgerResult l l)
applyBlockLedgerResult
    where
      mustSucceed :: Either a p -> p
mustSucceed (Left  a
err) = String -> p
forall a. HasCallStack => String -> a
error (String
"reapplyBlockLedgerResult: unexpected error: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> a -> String
forall a. Show a => a -> String
show a
err)
      mustSucceed (Right p
st)  = p
st

newtype instance LedgerState (SimpleBlock c ext) = SimpleLedgerState {
      LedgerState (SimpleBlock c ext) -> MockState (SimpleBlock c ext)
simpleLedgerState :: MockState (SimpleBlock c ext)
    }
  deriving stock   ((forall x.
 LedgerState (SimpleBlock c ext)
 -> Rep (LedgerState (SimpleBlock c ext)) x)
-> (forall x.
    Rep (LedgerState (SimpleBlock c ext)) x
    -> LedgerState (SimpleBlock c ext))
-> Generic (LedgerState (SimpleBlock c ext))
forall x.
Rep (LedgerState (SimpleBlock c ext)) x
-> LedgerState (SimpleBlock c ext)
forall x.
LedgerState (SimpleBlock c ext)
-> Rep (LedgerState (SimpleBlock c ext)) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall c ext x.
Rep (LedgerState (SimpleBlock c ext)) x
-> LedgerState (SimpleBlock c ext)
forall c ext x.
LedgerState (SimpleBlock c ext)
-> Rep (LedgerState (SimpleBlock c ext)) x
$cto :: forall c ext x.
Rep (LedgerState (SimpleBlock c ext)) x
-> LedgerState (SimpleBlock c ext)
$cfrom :: forall c ext x.
LedgerState (SimpleBlock c ext)
-> Rep (LedgerState (SimpleBlock c ext)) x
Generic, Int -> LedgerState (SimpleBlock c ext) -> ShowS
[LedgerState (SimpleBlock c ext)] -> ShowS
LedgerState (SimpleBlock c ext) -> String
(Int -> LedgerState (SimpleBlock c ext) -> ShowS)
-> (LedgerState (SimpleBlock c ext) -> String)
-> ([LedgerState (SimpleBlock c ext)] -> ShowS)
-> Show (LedgerState (SimpleBlock c ext))
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall c ext.
(SimpleCrypto c, Typeable ext) =>
Int -> LedgerState (SimpleBlock c ext) -> ShowS
forall c ext.
(SimpleCrypto c, Typeable ext) =>
[LedgerState (SimpleBlock c ext)] -> ShowS
forall c ext.
(SimpleCrypto c, Typeable ext) =>
LedgerState (SimpleBlock c ext) -> String
showList :: [LedgerState (SimpleBlock c ext)] -> ShowS
$cshowList :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
[LedgerState (SimpleBlock c ext)] -> ShowS
show :: LedgerState (SimpleBlock c ext) -> String
$cshow :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
LedgerState (SimpleBlock c ext) -> String
showsPrec :: Int -> LedgerState (SimpleBlock c ext) -> ShowS
$cshowsPrec :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
Int -> LedgerState (SimpleBlock c ext) -> ShowS
Show, LedgerState (SimpleBlock c ext)
-> LedgerState (SimpleBlock c ext) -> Bool
(LedgerState (SimpleBlock c ext)
 -> LedgerState (SimpleBlock c ext) -> Bool)
-> (LedgerState (SimpleBlock c ext)
    -> LedgerState (SimpleBlock c ext) -> Bool)
-> Eq (LedgerState (SimpleBlock c ext))
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall c ext.
(SimpleCrypto c, Typeable ext) =>
LedgerState (SimpleBlock c ext)
-> LedgerState (SimpleBlock c ext) -> Bool
/= :: LedgerState (SimpleBlock c ext)
-> LedgerState (SimpleBlock c ext) -> Bool
$c/= :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
LedgerState (SimpleBlock c ext)
-> LedgerState (SimpleBlock c ext) -> Bool
== :: LedgerState (SimpleBlock c ext)
-> LedgerState (SimpleBlock c ext) -> Bool
$c== :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
LedgerState (SimpleBlock c ext)
-> LedgerState (SimpleBlock c ext) -> Bool
Eq)
  deriving newtype (Decoder s (LedgerState (SimpleBlock c ext))
Decoder s [LedgerState (SimpleBlock c ext)]
[LedgerState (SimpleBlock c ext)] -> Encoding
LedgerState (SimpleBlock c ext) -> Encoding
(LedgerState (SimpleBlock c ext) -> Encoding)
-> (forall s. Decoder s (LedgerState (SimpleBlock c ext)))
-> ([LedgerState (SimpleBlock c ext)] -> Encoding)
-> (forall s. Decoder s [LedgerState (SimpleBlock c ext)])
-> Serialise (LedgerState (SimpleBlock c ext))
forall s. Decoder s [LedgerState (SimpleBlock c ext)]
forall s. Decoder s (LedgerState (SimpleBlock c ext))
forall a.
(a -> Encoding)
-> (forall s. Decoder s a)
-> ([a] -> Encoding)
-> (forall s. Decoder s [a])
-> Serialise a
forall c ext. [LedgerState (SimpleBlock c ext)] -> Encoding
forall c ext. LedgerState (SimpleBlock c ext) -> Encoding
forall c ext s. Decoder s [LedgerState (SimpleBlock c ext)]
forall c ext s. Decoder s (LedgerState (SimpleBlock c ext))
decodeList :: Decoder s [LedgerState (SimpleBlock c ext)]
$cdecodeList :: forall c ext s. Decoder s [LedgerState (SimpleBlock c ext)]
encodeList :: [LedgerState (SimpleBlock c ext)] -> Encoding
$cencodeList :: forall c ext. [LedgerState (SimpleBlock c ext)] -> Encoding
decode :: Decoder s (LedgerState (SimpleBlock c ext))
$cdecode :: forall c ext s. Decoder s (LedgerState (SimpleBlock c ext))
encode :: LedgerState (SimpleBlock c ext) -> Encoding
$cencode :: forall c ext. LedgerState (SimpleBlock c ext) -> Encoding
Serialise, Context -> LedgerState (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
Proxy (LedgerState (SimpleBlock c ext)) -> String
(Context
 -> LedgerState (SimpleBlock c ext) -> IO (Maybe ThunkInfo))
-> (Context
    -> LedgerState (SimpleBlock c ext) -> IO (Maybe ThunkInfo))
-> (Proxy (LedgerState (SimpleBlock c ext)) -> String)
-> NoThunks (LedgerState (SimpleBlock c ext))
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
forall c ext.
(SimpleCrypto c, Typeable ext) =>
Context -> LedgerState (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
forall c ext.
(SimpleCrypto c, Typeable ext) =>
Proxy (LedgerState (SimpleBlock c ext)) -> String
showTypeOf :: Proxy (LedgerState (SimpleBlock c ext)) -> String
$cshowTypeOf :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
Proxy (LedgerState (SimpleBlock c ext)) -> String
wNoThunks :: Context -> LedgerState (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
Context -> LedgerState (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
noThunks :: Context -> LedgerState (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
$cnoThunks :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
Context -> LedgerState (SimpleBlock c ext) -> IO (Maybe ThunkInfo)
NoThunks)

-- Ticking has no effect on the simple ledger state
newtype instance Ticked (LedgerState (SimpleBlock c ext)) = TickedSimpleLedgerState {
      Ticked (LedgerState (SimpleBlock c ext))
-> LedgerState (SimpleBlock c ext)
getTickedSimpleLedgerState :: LedgerState (SimpleBlock c ext)
    }
  deriving stock   ((forall x.
 Ticked (LedgerState (SimpleBlock c ext))
 -> Rep (Ticked (LedgerState (SimpleBlock c ext))) x)
-> (forall x.
    Rep (Ticked (LedgerState (SimpleBlock c ext))) x
    -> Ticked (LedgerState (SimpleBlock c ext)))
-> Generic (Ticked (LedgerState (SimpleBlock c ext)))
forall x.
Rep (Ticked (LedgerState (SimpleBlock c ext))) x
-> Ticked (LedgerState (SimpleBlock c ext))
forall x.
Ticked (LedgerState (SimpleBlock c ext))
-> Rep (Ticked (LedgerState (SimpleBlock c ext))) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall c ext x.
Rep (Ticked (LedgerState (SimpleBlock c ext))) x
-> Ticked (LedgerState (SimpleBlock c ext))
forall c ext x.
Ticked (LedgerState (SimpleBlock c ext))
-> Rep (Ticked (LedgerState (SimpleBlock c ext))) x
$cto :: forall c ext x.
Rep (Ticked (LedgerState (SimpleBlock c ext))) x
-> Ticked (LedgerState (SimpleBlock c ext))
$cfrom :: forall c ext x.
Ticked (LedgerState (SimpleBlock c ext))
-> Rep (Ticked (LedgerState (SimpleBlock c ext))) x
Generic, Int -> Ticked (LedgerState (SimpleBlock c ext)) -> ShowS
[Ticked (LedgerState (SimpleBlock c ext))] -> ShowS
Ticked (LedgerState (SimpleBlock c ext)) -> String
(Int -> Ticked (LedgerState (SimpleBlock c ext)) -> ShowS)
-> (Ticked (LedgerState (SimpleBlock c ext)) -> String)
-> ([Ticked (LedgerState (SimpleBlock c ext))] -> ShowS)
-> Show (Ticked (LedgerState (SimpleBlock c ext)))
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall c ext.
(SimpleCrypto c, Typeable ext) =>
Int -> Ticked (LedgerState (SimpleBlock c ext)) -> ShowS
forall c ext.
(SimpleCrypto c, Typeable ext) =>
[Ticked (LedgerState (SimpleBlock c ext))] -> ShowS
forall c ext.
(SimpleCrypto c, Typeable ext) =>
Ticked (LedgerState (SimpleBlock c ext)) -> String
showList :: [Ticked (LedgerState (SimpleBlock c ext))] -> ShowS
$cshowList :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
[Ticked (LedgerState (SimpleBlock c ext))] -> ShowS
show :: Ticked (LedgerState (SimpleBlock c ext)) -> String
$cshow :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
Ticked (LedgerState (SimpleBlock c ext)) -> String
showsPrec :: Int -> Ticked (LedgerState (SimpleBlock c ext)) -> ShowS
$cshowsPrec :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
Int -> Ticked (LedgerState (SimpleBlock c ext)) -> ShowS
Show, Ticked (LedgerState (SimpleBlock c ext))
-> Ticked (LedgerState (SimpleBlock c ext)) -> Bool
(Ticked (LedgerState (SimpleBlock c ext))
 -> Ticked (LedgerState (SimpleBlock c ext)) -> Bool)
-> (Ticked (LedgerState (SimpleBlock c ext))
    -> Ticked (LedgerState (SimpleBlock c ext)) -> Bool)
-> Eq (Ticked (LedgerState (SimpleBlock c ext)))
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall c ext.
(SimpleCrypto c, Typeable ext) =>
Ticked (LedgerState (SimpleBlock c ext))
-> Ticked (LedgerState (SimpleBlock c ext)) -> Bool
/= :: Ticked (LedgerState (SimpleBlock c ext))
-> Ticked (LedgerState (SimpleBlock c ext)) -> Bool
$c/= :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
Ticked (LedgerState (SimpleBlock c ext))
-> Ticked (LedgerState (SimpleBlock c ext)) -> Bool
== :: Ticked (LedgerState (SimpleBlock c ext))
-> Ticked (LedgerState (SimpleBlock c ext)) -> Bool
$c== :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
Ticked (LedgerState (SimpleBlock c ext))
-> Ticked (LedgerState (SimpleBlock c ext)) -> Bool
Eq)
  deriving newtype (Context
-> Ticked (LedgerState (SimpleBlock c ext)) -> IO (Maybe ThunkInfo)
Proxy (Ticked (LedgerState (SimpleBlock c ext))) -> String
(Context
 -> Ticked (LedgerState (SimpleBlock c ext))
 -> IO (Maybe ThunkInfo))
-> (Context
    -> Ticked (LedgerState (SimpleBlock c ext))
    -> IO (Maybe ThunkInfo))
-> (Proxy (Ticked (LedgerState (SimpleBlock c ext))) -> String)
-> NoThunks (Ticked (LedgerState (SimpleBlock c ext)))
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
forall c ext.
(SimpleCrypto c, Typeable ext) =>
Context
-> Ticked (LedgerState (SimpleBlock c ext)) -> IO (Maybe ThunkInfo)
forall c ext.
(SimpleCrypto c, Typeable ext) =>
Proxy (Ticked (LedgerState (SimpleBlock c ext))) -> String
showTypeOf :: Proxy (Ticked (LedgerState (SimpleBlock c ext))) -> String
$cshowTypeOf :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
Proxy (Ticked (LedgerState (SimpleBlock c ext))) -> String
wNoThunks :: Context
-> Ticked (LedgerState (SimpleBlock c ext)) -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
Context
-> Ticked (LedgerState (SimpleBlock c ext)) -> IO (Maybe ThunkInfo)
noThunks :: Context
-> Ticked (LedgerState (SimpleBlock c ext)) -> IO (Maybe ThunkInfo)
$cnoThunks :: forall c ext.
(SimpleCrypto c, Typeable ext) =>
Context
-> Ticked (LedgerState (SimpleBlock c ext)) -> IO (Maybe ThunkInfo)
NoThunks)

instance MockProtocolSpecific c ext => UpdateLedger (SimpleBlock c ext)

updateSimpleLedgerState :: (SimpleCrypto c, Typeable ext)
                        => SimpleBlock c ext
                        -> TickedLedgerState (SimpleBlock c ext)
                        -> Except (MockError (SimpleBlock c ext))
                                  (LedgerState (SimpleBlock c ext))
updateSimpleLedgerState :: SimpleBlock c ext
-> TickedLedgerState (SimpleBlock c ext)
-> Except
     (MockError (SimpleBlock c ext)) (LedgerState (SimpleBlock c ext))
updateSimpleLedgerState SimpleBlock c ext
b (TickedSimpleLedgerState (SimpleLedgerState st)) =
    MockState (SimpleBlock c ext) -> LedgerState (SimpleBlock c ext)
forall c ext.
MockState (SimpleBlock c ext) -> LedgerState (SimpleBlock c ext)
SimpleLedgerState (MockState (SimpleBlock c ext) -> LedgerState (SimpleBlock c ext))
-> ExceptT
     (MockError (SimpleBlock c ext))
     Identity
     (MockState (SimpleBlock c ext))
-> Except
     (MockError (SimpleBlock c ext)) (LedgerState (SimpleBlock c ext))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SimpleBlock c ext
-> MockState (SimpleBlock c ext)
-> ExceptT
     (MockError (SimpleBlock c ext))
     Identity
     (MockState (SimpleBlock c ext))
forall blk.
(GetPrevHash blk, HasMockTxs blk) =>
blk -> MockState blk -> Except (MockError blk) (MockState blk)
updateMockState SimpleBlock c ext
b MockState (SimpleBlock c ext)
st

updateSimpleUTxO :: Mock.HasMockTxs a
                 => SlotNo
                 -> a
                 -> TickedLedgerState (SimpleBlock c ext)
                 -> Except (MockError (SimpleBlock c ext))
                           (TickedLedgerState (SimpleBlock c ext))
updateSimpleUTxO :: SlotNo
-> a
-> TickedLedgerState (SimpleBlock c ext)
-> Except
     (MockError (SimpleBlock c ext))
     (TickedLedgerState (SimpleBlock c ext))
updateSimpleUTxO SlotNo
x a
slot (TickedSimpleLedgerState (SimpleLedgerState st)) =
    LedgerState (SimpleBlock c ext)
-> TickedLedgerState (SimpleBlock c ext)
forall c ext.
LedgerState (SimpleBlock c ext)
-> Ticked (LedgerState (SimpleBlock c ext))
TickedSimpleLedgerState (LedgerState (SimpleBlock c ext)
 -> TickedLedgerState (SimpleBlock c ext))
-> (MockState (SimpleBlock c ext)
    -> LedgerState (SimpleBlock c ext))
-> MockState (SimpleBlock c ext)
-> TickedLedgerState (SimpleBlock c ext)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MockState (SimpleBlock c ext) -> LedgerState (SimpleBlock c ext)
forall c ext.
MockState (SimpleBlock c ext) -> LedgerState (SimpleBlock c ext)
SimpleLedgerState (MockState (SimpleBlock c ext)
 -> TickedLedgerState (SimpleBlock c ext))
-> ExceptT
     (MockError (SimpleBlock c ext))
     Identity
     (MockState (SimpleBlock c ext))
-> Except
     (MockError (SimpleBlock c ext))
     (TickedLedgerState (SimpleBlock c ext))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SlotNo
-> a
-> MockState (SimpleBlock c ext)
-> ExceptT
     (MockError (SimpleBlock c ext))
     Identity
     (MockState (SimpleBlock c ext))
forall a blk.
HasMockTxs a =>
SlotNo
-> a -> MockState blk -> Except (MockError blk) (MockState blk)
updateMockUTxO SlotNo
x a
slot MockState (SimpleBlock c ext)
st

genesisSimpleLedgerState :: AddrDist -> LedgerState (SimpleBlock c ext)
genesisSimpleLedgerState :: AddrDist -> LedgerState (SimpleBlock c ext)
genesisSimpleLedgerState = MockState (SimpleBlock c ext) -> LedgerState (SimpleBlock c ext)
forall c ext.
MockState (SimpleBlock c ext) -> LedgerState (SimpleBlock c ext)
SimpleLedgerState (MockState (SimpleBlock c ext) -> LedgerState (SimpleBlock c ext))
-> (AddrDist -> MockState (SimpleBlock c ext))
-> AddrDist
-> LedgerState (SimpleBlock c ext)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AddrDist -> MockState (SimpleBlock c ext)
forall blk. AddrDist -> MockState blk
genesisMockState

-- | Dummy values
instance MockProtocolSpecific c ext => CommonProtocolParams (SimpleBlock c ext) where
  maxHeaderSize :: LedgerState (SimpleBlock c ext) -> Word32
maxHeaderSize = Word32 -> LedgerState (SimpleBlock c ext) -> Word32
forall a b. a -> b -> a
const Word32
2000000
  maxTxSize :: LedgerState (SimpleBlock c ext) -> Word32
maxTxSize     = Word32 -> LedgerState (SimpleBlock c ext) -> Word32
forall a b. a -> b -> a
const Word32
2000000

instance LedgerSupportsPeerSelection (SimpleBlock c ext) where
  getPeers :: LedgerState (SimpleBlock c ext)
-> [(PoolStake, NonEmpty StakePoolRelay)]
getPeers = [(PoolStake, NonEmpty StakePoolRelay)]
-> LedgerState (SimpleBlock c ext)
-> [(PoolStake, NonEmpty StakePoolRelay)]
forall a b. a -> b -> a
const []

{-------------------------------------------------------------------------------
  Support for the mempool
-------------------------------------------------------------------------------}

data instance GenTx (SimpleBlock c ext) = SimpleGenTx {
      GenTx (SimpleBlock c ext) -> Tx
simpleGenTx   :: !Mock.Tx
    , GenTx (SimpleBlock c ext) -> TxId
simpleGenTxId :: !Mock.TxId
    }
  deriving stock    ((forall x.
 GenTx (SimpleBlock c ext) -> Rep (GenTx (SimpleBlock c ext)) x)
-> (forall x.
    Rep (GenTx (SimpleBlock c ext)) x -> GenTx (SimpleBlock c ext))
-> Generic (GenTx (SimpleBlock c ext))
forall x.
Rep (GenTx (SimpleBlock c ext)) x -> GenTx (SimpleBlock c ext)
forall x.
GenTx (SimpleBlock c ext) -> Rep (GenTx (SimpleBlock c ext)) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall c ext x.
Rep (GenTx (SimpleBlock c ext)) x -> GenTx (SimpleBlock c ext)
forall c ext x.
GenTx (SimpleBlock c ext) -> Rep (GenTx (SimpleBlock c ext)) x
$cto :: forall c ext x.
Rep (GenTx (SimpleBlock c ext)) x -> GenTx (SimpleBlock c ext)
$cfrom :: forall c ext x.
GenTx (SimpleBlock c ext) -> Rep (GenTx (SimpleBlock c ext)) x
Generic, GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool
(GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool)
-> (GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool)
-> Eq (GenTx (SimpleBlock c ext))
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall c ext.
GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool
/= :: GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool
$c/= :: forall c ext.
GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool
== :: GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool
$c== :: forall c ext.
GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool
Eq, Eq (GenTx (SimpleBlock c ext))
Eq (GenTx (SimpleBlock c ext))
-> (GenTx (SimpleBlock c ext)
    -> GenTx (SimpleBlock c ext) -> Ordering)
-> (GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool)
-> (GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool)
-> (GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool)
-> (GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool)
-> (GenTx (SimpleBlock c ext)
    -> GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext))
-> (GenTx (SimpleBlock c ext)
    -> GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext))
-> Ord (GenTx (SimpleBlock c ext))
GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool
GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Ordering
GenTx (SimpleBlock c ext)
-> GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext)
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall c ext. Eq (GenTx (SimpleBlock c ext))
forall c ext.
GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool
forall c ext.
GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Ordering
forall c ext.
GenTx (SimpleBlock c ext)
-> GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext)
min :: GenTx (SimpleBlock c ext)
-> GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext)
$cmin :: forall c ext.
GenTx (SimpleBlock c ext)
-> GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext)
max :: GenTx (SimpleBlock c ext)
-> GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext)
$cmax :: forall c ext.
GenTx (SimpleBlock c ext)
-> GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext)
>= :: GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool
$c>= :: forall c ext.
GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool
> :: GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool
$c> :: forall c ext.
GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool
<= :: GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool
$c<= :: forall c ext.
GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool
< :: GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool
$c< :: forall c ext.
GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Bool
compare :: GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Ordering
$ccompare :: forall c ext.
GenTx (SimpleBlock c ext) -> GenTx (SimpleBlock c ext) -> Ordering
$cp1Ord :: forall c ext. Eq (GenTx (SimpleBlock c ext))
Ord)
  deriving anyclass ([GenTx (SimpleBlock c ext)] -> Encoding
GenTx (SimpleBlock c ext) -> Encoding
(GenTx (SimpleBlock c ext) -> Encoding)
-> (forall s. Decoder s (GenTx (SimpleBlock c ext)))
-> ([GenTx (SimpleBlock c ext)] -> Encoding)
-> (forall s. Decoder s [GenTx (SimpleBlock c ext)])
-> Serialise (GenTx (SimpleBlock c ext))
forall s. Decoder s [GenTx (SimpleBlock c ext)]
forall s. Decoder s (GenTx (SimpleBlock c ext))
forall a.
(a -> Encoding)
-> (forall s. Decoder s a)
-> ([a] -> Encoding)
-> (forall s. Decoder s [a])
-> Serialise a
forall c ext. [GenTx (SimpleBlock c ext)] -> Encoding
forall c ext. GenTx (SimpleBlock c ext) -> Encoding
forall c ext s. Decoder s [GenTx (SimpleBlock c ext)]
forall c ext s. Decoder s (GenTx (SimpleBlock c ext))
decodeList :: Decoder s [GenTx (SimpleBlock c ext)]
$cdecodeList :: forall c ext s. Decoder s [GenTx (SimpleBlock c ext)]
encodeList :: [GenTx (SimpleBlock c ext)] -> Encoding
$cencodeList :: forall c ext. [GenTx (SimpleBlock c ext)] -> Encoding
decode :: Decoder s (GenTx (SimpleBlock c ext))
$cdecode :: forall c ext s. Decoder s (GenTx (SimpleBlock c ext))
encode :: GenTx (SimpleBlock c ext) -> Encoding
$cencode :: forall c ext. GenTx (SimpleBlock c ext) -> Encoding
Serialise)

newtype instance Validated (GenTx (SimpleBlock c ext)) = ValidatedSimpleGenTx {
      Validated (GenTx (SimpleBlock c ext)) -> GenTx (SimpleBlock c ext)
forgetValidatedSimpleGenTx :: GenTx (SimpleBlock c ext)
    }
  deriving newtype (Rep (Validated (GenTx (SimpleBlock c ext))) x
-> Validated (GenTx (SimpleBlock c ext))
Validated (GenTx (SimpleBlock c ext))
-> Rep (Validated (GenTx (SimpleBlock c ext))) x
(forall x.
 Validated (GenTx (SimpleBlock c ext))
 -> Rep (Validated (GenTx (SimpleBlock c ext))) x)
-> (forall x.
    Rep (Validated (GenTx (SimpleBlock c ext))) x
    -> Validated (GenTx (SimpleBlock c ext)))
-> Generic (Validated (GenTx (SimpleBlock c ext)))
forall x.
Rep (Validated (GenTx (SimpleBlock c ext))) x
-> Validated (GenTx (SimpleBlock c ext))
forall x.
Validated (GenTx (SimpleBlock c ext))
-> Rep (Validated (GenTx (SimpleBlock c ext))) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall c ext x.
Rep (Validated (GenTx (SimpleBlock c ext))) x
-> Validated (GenTx (SimpleBlock c ext))
forall c ext x.
Validated (GenTx (SimpleBlock c ext))
-> Rep (Validated (GenTx (SimpleBlock c ext))) x
to :: Rep (Validated (GenTx (SimpleBlock c ext))) x
-> Validated (GenTx (SimpleBlock c ext))
$cto :: forall c ext x.
Rep (Validated (GenTx (SimpleBlock c ext))) x
-> Validated (GenTx (SimpleBlock c ext))
from :: Validated (GenTx (SimpleBlock c ext))
-> Rep (Validated (GenTx (SimpleBlock c ext))) x
$cfrom :: forall c ext x.
Validated (GenTx (SimpleBlock c ext))
-> Rep (Validated (GenTx (SimpleBlock c ext))) x
Generic, Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Bool
(Validated (GenTx (SimpleBlock c ext))
 -> Validated (GenTx (SimpleBlock c ext)) -> Bool)
-> (Validated (GenTx (SimpleBlock c ext))
    -> Validated (GenTx (SimpleBlock c ext)) -> Bool)
-> Eq (Validated (GenTx (SimpleBlock c ext)))
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall c ext.
Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Bool
/= :: Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Bool
$c/= :: forall c ext.
Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Bool
== :: Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Bool
$c== :: forall c ext.
Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Bool
Eq, Eq (Validated (GenTx (SimpleBlock c ext)))
Eq (Validated (GenTx (SimpleBlock c ext)))
-> (Validated (GenTx (SimpleBlock c ext))
    -> Validated (GenTx (SimpleBlock c ext)) -> Ordering)
-> (Validated (GenTx (SimpleBlock c ext))
    -> Validated (GenTx (SimpleBlock c ext)) -> Bool)
-> (Validated (GenTx (SimpleBlock c ext))
    -> Validated (GenTx (SimpleBlock c ext)) -> Bool)
-> (Validated (GenTx (SimpleBlock c ext))
    -> Validated (GenTx (SimpleBlock c ext)) -> Bool)
-> (Validated (GenTx (SimpleBlock c ext))
    -> Validated (GenTx (SimpleBlock c ext)) -> Bool)
-> (Validated (GenTx (SimpleBlock c ext))
    -> Validated (GenTx (SimpleBlock c ext))
    -> Validated (GenTx (SimpleBlock c ext)))
-> (Validated (GenTx (SimpleBlock c ext))
    -> Validated (GenTx (SimpleBlock c ext))
    -> Validated (GenTx (SimpleBlock c ext)))
-> Ord (Validated (GenTx (SimpleBlock c ext)))
Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Bool
Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Ordering
Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext))
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall c ext. Eq (Validated (GenTx (SimpleBlock c ext)))
forall c ext.
Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Bool
forall c ext.
Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Ordering
forall c ext.
Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext))
min :: Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext))
$cmin :: forall c ext.
Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext))
max :: Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext))
$cmax :: forall c ext.
Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext))
>= :: Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Bool
$c>= :: forall c ext.
Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Bool
> :: Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Bool
$c> :: forall c ext.
Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Bool
<= :: Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Bool
$c<= :: forall c ext.
Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Bool
< :: Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Bool
$c< :: forall c ext.
Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Bool
compare :: Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Ordering
$ccompare :: forall c ext.
Validated (GenTx (SimpleBlock c ext))
-> Validated (GenTx (SimpleBlock c ext)) -> Ordering
$cp1Ord :: forall c ext. Eq (Validated (GenTx (SimpleBlock c ext)))
Ord)

instance (Typeable c, Typeable ext)
    => ShowProxy (GenTx (SimpleBlock c ext)) where

type instance ApplyTxErr (SimpleBlock c ext) = MockError (SimpleBlock c ext)

instance MockProtocolSpecific c ext
      => LedgerSupportsMempool (SimpleBlock c ext) where
  applyTx :: LedgerConfig (SimpleBlock c ext)
-> WhetherToIntervene
-> SlotNo
-> GenTx (SimpleBlock c ext)
-> Ticked (LedgerState (SimpleBlock c ext))
-> Except
     (ApplyTxErr (SimpleBlock c ext))
     (Ticked (LedgerState (SimpleBlock c ext)),
      Validated (GenTx (SimpleBlock c ext)))
applyTx LedgerConfig (SimpleBlock c ext)
_cfg WhetherToIntervene
_wti SlotNo
slot GenTx (SimpleBlock c ext)
tx Ticked (LedgerState (SimpleBlock c ext))
st = do
      Ticked (LedgerState (SimpleBlock c ext))
st' <- SlotNo
-> GenTx (SimpleBlock c ext)
-> Ticked (LedgerState (SimpleBlock c ext))
-> Except
     (MockError (SimpleBlock c ext))
     (Ticked (LedgerState (SimpleBlock c ext)))
forall a c ext.
HasMockTxs a =>
SlotNo
-> a
-> TickedLedgerState (SimpleBlock c ext)
-> Except
     (MockError (SimpleBlock c ext))
     (TickedLedgerState (SimpleBlock c ext))
updateSimpleUTxO SlotNo
slot GenTx (SimpleBlock c ext)
tx Ticked (LedgerState (SimpleBlock c ext))
st
      (Ticked (LedgerState (SimpleBlock c ext)),
 Validated (GenTx (SimpleBlock c ext)))
-> ExceptT
     (MockError (SimpleBlock c ext))
     Identity
     (Ticked (LedgerState (SimpleBlock c ext)),
      Validated (GenTx (SimpleBlock c ext)))
forall (m :: * -> *) a. Monad m => a -> m a
return (Ticked (LedgerState (SimpleBlock c ext))
st', GenTx (SimpleBlock c ext) -> Validated (GenTx (SimpleBlock c ext))
forall c ext.
GenTx (SimpleBlock c ext) -> Validated (GenTx (SimpleBlock c ext))
ValidatedSimpleGenTx GenTx (SimpleBlock c ext)
tx)
  reapplyTx :: LedgerConfig (SimpleBlock c ext)
-> SlotNo
-> Validated (GenTx (SimpleBlock c ext))
-> Ticked (LedgerState (SimpleBlock c ext))
-> Except
     (ApplyTxErr (SimpleBlock c ext))
     (Ticked (LedgerState (SimpleBlock c ext)))
reapplyTx LedgerConfig (SimpleBlock c ext)
_cfg SlotNo
slot Validated (GenTx (SimpleBlock c ext))
vtx Ticked (LedgerState (SimpleBlock c ext))
st =
      SlotNo
-> GenTx (SimpleBlock c ext)
-> Ticked (LedgerState (SimpleBlock c ext))
-> Except
     (MockError (SimpleBlock c ext))
     (Ticked (LedgerState (SimpleBlock c ext)))
forall a c ext.
HasMockTxs a =>
SlotNo
-> a
-> TickedLedgerState (SimpleBlock c ext)
-> Except
     (MockError (SimpleBlock c ext))
     (TickedLedgerState (SimpleBlock c ext))
updateSimpleUTxO SlotNo
slot (Validated (GenTx (SimpleBlock c ext)) -> GenTx (SimpleBlock c ext)
forall c ext.
Validated (GenTx (SimpleBlock c ext)) -> GenTx (SimpleBlock c ext)
forgetValidatedSimpleGenTx Validated (GenTx (SimpleBlock c ext))
vtx) Ticked (LedgerState (SimpleBlock c ext))
st

  -- Large value so that the Mempool tests never run out of capacity when they
  -- don't override it.
  txsMaxBytes :: Ticked (LedgerState (SimpleBlock c ext)) -> Word32
txsMaxBytes   = Word32 -> Ticked (LedgerState (SimpleBlock c ext)) -> Word32
forall a b. a -> b -> a
const Word32
1000000000
  txInBlockSize :: GenTx (SimpleBlock c ext) -> Word32
txInBlockSize = GenTx (SimpleBlock c ext) -> Word32
forall c ext. GenTx (SimpleBlock c ext) -> Word32
txSize

  txForgetValidated :: Validated (GenTx (SimpleBlock c ext)) -> GenTx (SimpleBlock c ext)
txForgetValidated = Validated (GenTx (SimpleBlock c ext)) -> GenTx (SimpleBlock c ext)
forall c ext.
Validated (GenTx (SimpleBlock c ext)) -> GenTx (SimpleBlock c ext)
forgetValidatedSimpleGenTx

newtype instance TxId (GenTx (SimpleBlock c ext)) = SimpleGenTxId {
      TxId (GenTx (SimpleBlock c ext)) -> TxId
unSimpleGenTxId :: Mock.TxId
    }
  deriving stock   ((forall x.
 TxId (GenTx (SimpleBlock c ext))
 -> Rep (TxId (GenTx (SimpleBlock c ext))) x)
-> (forall x.
    Rep (TxId (GenTx (SimpleBlock c ext))) x
    -> TxId (GenTx (SimpleBlock c ext)))
-> Generic (TxId (GenTx (SimpleBlock c ext)))
forall x.
Rep (TxId (GenTx (SimpleBlock c ext))) x
-> TxId (GenTx (SimpleBlock c ext))
forall x.
TxId (GenTx (SimpleBlock c ext))
-> Rep (TxId (GenTx (SimpleBlock c ext))) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall c ext x.
Rep (TxId (GenTx (SimpleBlock c ext))) x
-> TxId (GenTx (SimpleBlock c ext))
forall c ext x.
TxId (GenTx (SimpleBlock c ext))
-> Rep (TxId (GenTx (SimpleBlock c ext))) x
$cto :: forall c ext x.
Rep (TxId (GenTx (SimpleBlock c ext))) x
-> TxId (GenTx (SimpleBlock c ext))
$cfrom :: forall c ext x.
TxId (GenTx (SimpleBlock c ext))
-> Rep (TxId (GenTx (SimpleBlock c ext))) x
Generic)
  deriving newtype (Int -> TxId (GenTx (SimpleBlock c ext)) -> ShowS
[TxId (GenTx (SimpleBlock c ext))] -> ShowS
TxId (GenTx (SimpleBlock c ext)) -> String
(Int -> TxId (GenTx (SimpleBlock c ext)) -> ShowS)
-> (TxId (GenTx (SimpleBlock c ext)) -> String)
-> ([TxId (GenTx (SimpleBlock c ext))] -> ShowS)
-> Show (TxId (GenTx (SimpleBlock c ext)))
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall c ext. Int -> TxId (GenTx (SimpleBlock c ext)) -> ShowS
forall c ext. [TxId (GenTx (SimpleBlock c ext))] -> ShowS
forall c ext. TxId (GenTx (SimpleBlock c ext)) -> String
showList :: [TxId (GenTx (SimpleBlock c ext))] -> ShowS
$cshowList :: forall c ext. [TxId (GenTx (SimpleBlock c ext))] -> ShowS
show :: TxId (GenTx (SimpleBlock c ext)) -> String
$cshow :: forall c ext. TxId (GenTx (SimpleBlock c ext)) -> String
showsPrec :: Int -> TxId (GenTx (SimpleBlock c ext)) -> ShowS
$cshowsPrec :: forall c ext. Int -> TxId (GenTx (SimpleBlock c ext)) -> ShowS
Show, TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Bool
(TxId (GenTx (SimpleBlock c ext))
 -> TxId (GenTx (SimpleBlock c ext)) -> Bool)
-> (TxId (GenTx (SimpleBlock c ext))
    -> TxId (GenTx (SimpleBlock c ext)) -> Bool)
-> Eq (TxId (GenTx (SimpleBlock c ext)))
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall c ext.
TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Bool
/= :: TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Bool
$c/= :: forall c ext.
TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Bool
== :: TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Bool
$c== :: forall c ext.
TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Bool
Eq, Eq (TxId (GenTx (SimpleBlock c ext)))
Eq (TxId (GenTx (SimpleBlock c ext)))
-> (TxId (GenTx (SimpleBlock c ext))
    -> TxId (GenTx (SimpleBlock c ext)) -> Ordering)
-> (TxId (GenTx (SimpleBlock c ext))
    -> TxId (GenTx (SimpleBlock c ext)) -> Bool)
-> (TxId (GenTx (SimpleBlock c ext))
    -> TxId (GenTx (SimpleBlock c ext)) -> Bool)
-> (TxId (GenTx (SimpleBlock c ext))
    -> TxId (GenTx (SimpleBlock c ext)) -> Bool)
-> (TxId (GenTx (SimpleBlock c ext))
    -> TxId (GenTx (SimpleBlock c ext)) -> Bool)
-> (TxId (GenTx (SimpleBlock c ext))
    -> TxId (GenTx (SimpleBlock c ext))
    -> TxId (GenTx (SimpleBlock c ext)))
-> (TxId (GenTx (SimpleBlock c ext))
    -> TxId (GenTx (SimpleBlock c ext))
    -> TxId (GenTx (SimpleBlock c ext)))
-> Ord (TxId (GenTx (SimpleBlock c ext)))
TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Bool
TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Ordering
TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext))
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall c ext. Eq (TxId (GenTx (SimpleBlock c ext)))
forall c ext.
TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Bool
forall c ext.
TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Ordering
forall c ext.
TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext))
min :: TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext))
$cmin :: forall c ext.
TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext))
max :: TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext))
$cmax :: forall c ext.
TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext))
>= :: TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Bool
$c>= :: forall c ext.
TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Bool
> :: TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Bool
$c> :: forall c ext.
TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Bool
<= :: TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Bool
$c<= :: forall c ext.
TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Bool
< :: TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Bool
$c< :: forall c ext.
TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Bool
compare :: TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Ordering
$ccompare :: forall c ext.
TxId (GenTx (SimpleBlock c ext))
-> TxId (GenTx (SimpleBlock c ext)) -> Ordering
$cp1Ord :: forall c ext. Eq (TxId (GenTx (SimpleBlock c ext)))
Ord, Decoder s (TxId (GenTx (SimpleBlock c ext)))
Decoder s [TxId (GenTx (SimpleBlock c ext))]
[TxId (GenTx (SimpleBlock c ext))] -> Encoding
TxId (GenTx (SimpleBlock c ext)) -> Encoding
(TxId (GenTx (SimpleBlock c ext)) -> Encoding)
-> (forall s. Decoder s (TxId (GenTx (SimpleBlock c ext))))
-> ([TxId (GenTx (SimpleBlock c ext))] -> Encoding)
-> (forall s. Decoder s [TxId (GenTx (SimpleBlock c ext))])
-> Serialise (TxId (GenTx (SimpleBlock c ext)))
forall s. Decoder s [TxId (GenTx (SimpleBlock c ext))]
forall s. Decoder s (TxId (GenTx (SimpleBlock c ext)))
forall a.
(a -> Encoding)
-> (forall s. Decoder s a)
-> ([a] -> Encoding)
-> (forall s. Decoder s [a])
-> Serialise a
forall c ext. [TxId (GenTx (SimpleBlock c ext))] -> Encoding
forall c ext. TxId (GenTx (SimpleBlock c ext)) -> Encoding
forall c ext s. Decoder s [TxId (GenTx (SimpleBlock c ext))]
forall c ext s. Decoder s (TxId (GenTx (SimpleBlock c ext)))
decodeList :: Decoder s [TxId (GenTx (SimpleBlock c ext))]
$cdecodeList :: forall c ext s. Decoder s [TxId (GenTx (SimpleBlock c ext))]
encodeList :: [TxId (GenTx (SimpleBlock c ext))] -> Encoding
$cencodeList :: forall c ext. [TxId (GenTx (SimpleBlock c ext))] -> Encoding
decode :: Decoder s (TxId (GenTx (SimpleBlock c ext)))
$cdecode :: forall c ext s. Decoder s (TxId (GenTx (SimpleBlock c ext)))
encode :: TxId (GenTx (SimpleBlock c ext)) -> Encoding
$cencode :: forall c ext. TxId (GenTx (SimpleBlock c ext)) -> Encoding
Serialise, Context -> TxId (GenTx (SimpleBlock c ext)) -> IO (Maybe ThunkInfo)
Proxy (TxId (GenTx (SimpleBlock c ext))) -> String
(Context
 -> TxId (GenTx (SimpleBlock c ext)) -> IO (Maybe ThunkInfo))
-> (Context
    -> TxId (GenTx (SimpleBlock c ext)) -> IO (Maybe ThunkInfo))
-> (Proxy (TxId (GenTx (SimpleBlock c ext))) -> String)
-> NoThunks (TxId (GenTx (SimpleBlock c ext)))
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
forall c ext.
Context -> TxId (GenTx (SimpleBlock c ext)) -> IO (Maybe ThunkInfo)
forall c ext. Proxy (TxId (GenTx (SimpleBlock c ext))) -> String
showTypeOf :: Proxy (TxId (GenTx (SimpleBlock c ext))) -> String
$cshowTypeOf :: forall c ext. Proxy (TxId (GenTx (SimpleBlock c ext))) -> String
wNoThunks :: Context -> TxId (GenTx (SimpleBlock c ext)) -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall c ext.
Context -> TxId (GenTx (SimpleBlock c ext)) -> IO (Maybe ThunkInfo)
noThunks :: Context -> TxId (GenTx (SimpleBlock c ext)) -> IO (Maybe ThunkInfo)
$cnoThunks :: forall c ext.
Context -> TxId (GenTx (SimpleBlock c ext)) -> IO (Maybe ThunkInfo)
NoThunks)

instance (Typeable c, Typeable ext)
    => ShowProxy (TxId (GenTx (SimpleBlock c ext))) where

instance HasTxId (GenTx (SimpleBlock c ext)) where
  txId :: GenTx (SimpleBlock c ext) -> TxId (GenTx (SimpleBlock c ext))
txId = TxId -> TxId (GenTx (SimpleBlock c ext))
forall c ext. TxId -> TxId (GenTx (SimpleBlock c ext))
SimpleGenTxId (TxId -> TxId (GenTx (SimpleBlock c ext)))
-> (GenTx (SimpleBlock c ext) -> TxId)
-> GenTx (SimpleBlock c ext)
-> TxId (GenTx (SimpleBlock c ext))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenTx (SimpleBlock c ext) -> TxId
forall c ext. GenTx (SimpleBlock c ext) -> TxId
simpleGenTxId

instance (Typeable p, Typeable c) => NoThunks (GenTx (SimpleBlock p c)) where
  showTypeOf :: Proxy (GenTx (SimpleBlock p c)) -> String
showTypeOf Proxy (GenTx (SimpleBlock p c))
_ = TypeRep -> String
forall a. Show a => a -> String
show (TypeRep -> String) -> TypeRep -> String
forall a b. (a -> b) -> a -> b
$ Proxy (GenTx (SimpleBlock p c)) -> TypeRep
forall k (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (Proxy (GenTx (SimpleBlock p c))
forall k (t :: k). Proxy t
Proxy @(GenTx (SimpleBlock p c)))

instance (Typeable p, Typeable c) => NoThunks (Validated (GenTx (SimpleBlock p c))) where
  showTypeOf :: Proxy (Validated (GenTx (SimpleBlock p c))) -> String
showTypeOf Proxy (Validated (GenTx (SimpleBlock p c)))
_ = TypeRep -> String
forall a. Show a => a -> String
show (TypeRep -> String) -> TypeRep -> String
forall a b. (a -> b) -> a -> b
$ Proxy (Validated (GenTx (SimpleBlock p c))) -> TypeRep
forall k (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (Proxy (Validated (GenTx (SimpleBlock p c)))
forall k (t :: k). Proxy t
Proxy @(Validated (GenTx (SimpleBlock p c))))

instance HasTxs (SimpleBlock c ext) where
  extractTxs :: SimpleBlock c ext -> [GenTx (SimpleBlock c ext)]
extractTxs = (Tx -> GenTx (SimpleBlock c ext))
-> [Tx] -> [GenTx (SimpleBlock c ext)]
forall a b. (a -> b) -> [a] -> [b]
map Tx -> GenTx (SimpleBlock c ext)
forall c ext. Tx -> GenTx (SimpleBlock c ext)
mkSimpleGenTx ([Tx] -> [GenTx (SimpleBlock c ext)])
-> (SimpleBlock c ext -> [Tx])
-> SimpleBlock c ext
-> [GenTx (SimpleBlock c ext)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimpleBody -> [Tx]
simpleTxs (SimpleBody -> [Tx])
-> (SimpleBlock c ext -> SimpleBody) -> SimpleBlock c ext -> [Tx]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimpleBlock c ext -> SimpleBody
forall c ext ext'. SimpleBlock' c ext ext' -> SimpleBody
simpleBody

instance Mock.HasMockTxs (GenTx (SimpleBlock p c)) where
  getMockTxs :: GenTx (SimpleBlock p c) -> [Tx]
getMockTxs = Tx -> [Tx]
forall a. HasMockTxs a => a -> [Tx]
Mock.getMockTxs (Tx -> [Tx])
-> (GenTx (SimpleBlock p c) -> Tx)
-> GenTx (SimpleBlock p c)
-> [Tx]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenTx (SimpleBlock p c) -> Tx
forall c ext. GenTx (SimpleBlock c ext) -> Tx
simpleGenTx

instance Condense (GenTx (SimpleBlock p c)) where
    condense :: GenTx (SimpleBlock p c) -> String
condense = Tx -> String
forall a. Condense a => a -> String
condense (Tx -> String)
-> (GenTx (SimpleBlock p c) -> Tx)
-> GenTx (SimpleBlock p c)
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenTx (SimpleBlock p c) -> Tx
forall c ext. GenTx (SimpleBlock c ext) -> Tx
simpleGenTx

instance Show (GenTx (SimpleBlock p c)) where
    show :: GenTx (SimpleBlock p c) -> String
show = Tx -> String
forall a. Show a => a -> String
show (Tx -> String)
-> (GenTx (SimpleBlock p c) -> Tx)
-> GenTx (SimpleBlock p c)
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenTx (SimpleBlock p c) -> Tx
forall c ext. GenTx (SimpleBlock c ext) -> Tx
simpleGenTx

instance Show (Validated (GenTx (SimpleBlock p c))) where
    show :: Validated (GenTx (SimpleBlock p c)) -> String
show = GenTx (SimpleBlock p c) -> String
forall a. Show a => a -> String
show (GenTx (SimpleBlock p c) -> String)
-> (Validated (GenTx (SimpleBlock p c)) -> GenTx (SimpleBlock p c))
-> Validated (GenTx (SimpleBlock p c))
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Validated (GenTx (SimpleBlock p c)) -> GenTx (SimpleBlock p c)
forall c ext.
Validated (GenTx (SimpleBlock c ext)) -> GenTx (SimpleBlock c ext)
forgetValidatedSimpleGenTx

instance Condense (GenTxId (SimpleBlock p c)) where
    condense :: GenTxId (SimpleBlock p c) -> String
condense = TxId -> String
forall a. Condense a => a -> String
condense (TxId -> String)
-> (GenTxId (SimpleBlock p c) -> TxId)
-> GenTxId (SimpleBlock p c)
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenTxId (SimpleBlock p c) -> TxId
forall c ext. TxId (GenTx (SimpleBlock c ext)) -> TxId
unSimpleGenTxId

mkSimpleGenTx :: Mock.Tx -> GenTx (SimpleBlock c ext)
mkSimpleGenTx :: Tx -> GenTx (SimpleBlock c ext)
mkSimpleGenTx Tx
tx = SimpleGenTx :: forall c ext. Tx -> TxId -> GenTx (SimpleBlock c ext)
SimpleGenTx
    { simpleGenTx :: Tx
simpleGenTx   = Tx
tx
    , simpleGenTxId :: TxId
simpleGenTxId = (Tx -> Encoding) -> Tx -> TxId
forall h a. HashAlgorithm h => (a -> Encoding) -> a -> Hash h a
Hash.hashWithSerialiser Tx -> Encoding
forall a. ToCBOR a => a -> Encoding
toCBOR Tx
tx
    }

txSize :: GenTx (SimpleBlock c ext) -> Word32
txSize :: GenTx (SimpleBlock c ext) -> Word32
txSize = Int64 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Word32)
-> (GenTx (SimpleBlock c ext) -> Int64)
-> GenTx (SimpleBlock c ext)
-> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Int64
Lazy.length (ByteString -> Int64)
-> (GenTx (SimpleBlock c ext) -> ByteString)
-> GenTx (SimpleBlock c ext)
-> Int64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenTx (SimpleBlock c ext) -> ByteString
forall a. Serialise a => a -> ByteString
serialise

{-------------------------------------------------------------------------------
  Support for QueryLedger
-------------------------------------------------------------------------------}

data instance BlockQuery (SimpleBlock c ext) result where
    QueryLedgerTip :: BlockQuery (SimpleBlock c ext) (Point (SimpleBlock c ext))

instance MockProtocolSpecific c ext => QueryLedger (SimpleBlock c ext) where
  answerBlockQuery :: ExtLedgerCfg (SimpleBlock c ext)
-> BlockQuery (SimpleBlock c ext) result
-> ExtLedgerState (SimpleBlock c ext)
-> result
answerBlockQuery ExtLedgerCfg (SimpleBlock c ext)
_cfg BlockQuery (SimpleBlock c ext) result
QueryLedgerTip =
        Point (SimpleBlock c ext) -> Point (SimpleBlock c ext)
forall b b'.
Coercible (HeaderHash b) (HeaderHash b') =>
Point b -> Point b'
castPoint
      (Point (SimpleBlock c ext) -> Point (SimpleBlock c ext))
-> (ExtLedgerState (SimpleBlock c ext)
    -> Point (SimpleBlock c ext))
-> ExtLedgerState (SimpleBlock c ext)
-> Point (SimpleBlock c ext)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy (SimpleBlock c ext)
-> LedgerState (SimpleBlock c ext) -> Point (SimpleBlock c ext)
forall blk.
UpdateLedger blk =>
Proxy blk -> LedgerState blk -> Point blk
ledgerTipPoint (Proxy (SimpleBlock c ext)
forall k (t :: k). Proxy t
Proxy @(SimpleBlock c ext))
      (LedgerState (SimpleBlock c ext) -> Point (SimpleBlock c ext))
-> (ExtLedgerState (SimpleBlock c ext)
    -> LedgerState (SimpleBlock c ext))
-> ExtLedgerState (SimpleBlock c ext)
-> Point (SimpleBlock c ext)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExtLedgerState (SimpleBlock c ext)
-> LedgerState (SimpleBlock c ext)
forall blk. ExtLedgerState blk -> LedgerState blk
ledgerState

instance SameDepIndex (BlockQuery (SimpleBlock c ext)) where
  sameDepIndex :: BlockQuery (SimpleBlock c ext) a
-> BlockQuery (SimpleBlock c ext) b -> Maybe (a :~: b)
sameDepIndex BlockQuery (SimpleBlock c ext) a
QueryLedgerTip BlockQuery (SimpleBlock c ext) b
QueryLedgerTip = (a :~: a) -> Maybe (a :~: a)
forall a. a -> Maybe a
Just a :~: a
forall k (a :: k). a :~: a
Refl

deriving instance Show (BlockQuery (SimpleBlock c ext) result)

instance (Typeable c, Typeable ext)
    => ShowProxy (BlockQuery (SimpleBlock c ext)) where

instance (SimpleCrypto c, Typeable ext)
      => ShowQuery (BlockQuery (SimpleBlock c ext)) where
  showResult :: BlockQuery (SimpleBlock c ext) result -> result -> String
showResult BlockQuery (SimpleBlock c ext) result
QueryLedgerTip = result -> String
forall a. Show a => a -> String
show

{-------------------------------------------------------------------------------
  Inspection
-------------------------------------------------------------------------------}

instance InspectLedger (SimpleBlock c ext) where
  -- Use defaults

{-------------------------------------------------------------------------------
  Crypto needed for simple blocks
-------------------------------------------------------------------------------}

class (HashAlgorithm (SimpleHash c), Typeable c) => SimpleCrypto c where
  type family SimpleHash c :: Type

data SimpleStandardCrypto
data SimpleMockCrypto

instance SimpleCrypto SimpleStandardCrypto where
  type SimpleHash SimpleStandardCrypto = SHA256

instance SimpleCrypto SimpleMockCrypto where
  type SimpleHash SimpleMockCrypto = ShortHash

{-------------------------------------------------------------------------------
  Condense instances
-------------------------------------------------------------------------------}

instance Condense ext' => Condense (Header (SimpleBlock' c ext ext')) where
  condense :: Header (SimpleBlock' c ext ext') -> String
condense SimpleHeader{..} = Context -> String
forall a. Monoid a => [a] -> a
mconcat [
        String
"("
      , ChainHash (SimpleBlock c ext) -> String
forall a. Condense a => a -> String
condense ChainHash (SimpleBlock c ext)
simplePrev
      , String
"->"
      , Hash (SimpleHash c) (Header (SimpleBlock' c ext ext')) -> String
forall a. Condense a => a -> String
condense HeaderHash (SimpleBlock' c ext ext')
Hash (SimpleHash c) (Header (SimpleBlock' c ext ext'))
simpleHeaderHash
      , String
","
      , SlotNo -> String
forall a. Condense a => a -> String
condense SlotNo
simpleSlotNo
      , String
","
      , ext' -> String
forall a. Condense a => a -> String
condense ext'
simpleHeaderExt
      , String
")"
      ]
    where
      SimpleStdHeader{Word32
SlotNo
BlockNo
ChainHash (SimpleBlock c ext)
Hash (SimpleHash c) SimpleBody
simpleBodySize :: Word32
simpleBodyHash :: Hash (SimpleHash c) SimpleBody
simpleBlockNo :: BlockNo
simpleSlotNo :: SlotNo
simplePrev :: ChainHash (SimpleBlock c ext)
simpleBodySize :: forall c ext. SimpleStdHeader c ext -> Word32
simpleBodyHash :: forall c ext.
SimpleStdHeader c ext -> Hash (SimpleHash c) SimpleBody
simpleBlockNo :: forall c ext. SimpleStdHeader c ext -> BlockNo
simpleSlotNo :: forall c ext. SimpleStdHeader c ext -> SlotNo
simplePrev :: forall c ext.
SimpleStdHeader c ext -> ChainHash (SimpleBlock c ext)
..} = SimpleStdHeader c ext
simpleHeaderStd

instance Condense ext' => Condense (SimpleBlock' c ext ext') where
  condense :: SimpleBlock' c ext ext' -> String
condense SimpleBlock{Header (SimpleBlock' c ext ext')
SimpleBody
simpleBody :: SimpleBody
simpleHeader :: Header (SimpleBlock' c ext ext')
simpleBody :: forall c ext ext'. SimpleBlock' c ext ext' -> SimpleBody
simpleHeader :: forall c ext ext'.
SimpleBlock' c ext ext' -> Header (SimpleBlock' c ext ext')
..} = Context -> String
forall a. Monoid a => [a] -> a
mconcat [
        String
"("
      , ChainHash (SimpleBlock c ext) -> String
forall a. Condense a => a -> String
condense ChainHash (SimpleBlock c ext)
simplePrev
      , String
"->"
      , Hash (SimpleHash c) (Header (SimpleBlock' c ext ext')) -> String
forall a. Condense a => a -> String
condense HeaderHash (SimpleBlock' c ext ext')
Hash (SimpleHash c) (Header (SimpleBlock' c ext ext'))
simpleHeaderHash
      , String
","
      , SlotNo -> String
forall a. Condense a => a -> String
condense SlotNo
simpleSlotNo
      , String
","
      , ext' -> String
forall a. Condense a => a -> String
condense ext'
simpleHeaderExt
      , String
","
      , [Tx] -> String
forall a. Condense a => a -> String
condense [Tx]
simpleTxs
      , String
")"
      ]
    where
      SimpleHeader{..}    = Header (SimpleBlock' c ext ext')
simpleHeader
      SimpleStdHeader{Word32
SlotNo
BlockNo
ChainHash (SimpleBlock c ext)
Hash (SimpleHash c) SimpleBody
simpleBodySize :: Word32
simpleBodyHash :: Hash (SimpleHash c) SimpleBody
simpleBlockNo :: BlockNo
simpleSlotNo :: SlotNo
simplePrev :: ChainHash (SimpleBlock c ext)
simpleBodySize :: forall c ext. SimpleStdHeader c ext -> Word32
simpleBodyHash :: forall c ext.
SimpleStdHeader c ext -> Hash (SimpleHash c) SimpleBody
simpleBlockNo :: forall c ext. SimpleStdHeader c ext -> BlockNo
simpleSlotNo :: forall c ext. SimpleStdHeader c ext -> SlotNo
simplePrev :: forall c ext.
SimpleStdHeader c ext -> ChainHash (SimpleBlock c ext)
..} = SimpleStdHeader c ext
simpleHeaderStd
      SimpleBody{[Tx]
simpleTxs :: [Tx]
simpleTxs :: SimpleBody -> [Tx]
..}      = SimpleBody
simpleBody

{-------------------------------------------------------------------------------
  Serialisation
-------------------------------------------------------------------------------}

instance ToCBOR SimpleBody where
  toCBOR :: SimpleBody -> Encoding
toCBOR = SimpleBody -> Encoding
forall a. Serialise a => a -> Encoding
encode

encodeSimpleHeader :: (ext' -> CBOR.Encoding)
                   -> Header (SimpleBlock' c ext ext')
                   -> CBOR.Encoding
encodeSimpleHeader :: (ext' -> Encoding) -> Header (SimpleBlock' c ext ext') -> Encoding
encodeSimpleHeader ext' -> Encoding
encodeExt SimpleHeader{..} =  [Encoding] -> Encoding
forall a. Monoid a => [a] -> a
mconcat [
      Word -> Encoding
CBOR.encodeListLen Word
2
    , SimpleStdHeader c ext -> Encoding
forall a. Serialise a => a -> Encoding
encode SimpleStdHeader c ext
simpleHeaderStd
    , ext' -> Encoding
encodeExt ext'
simpleHeaderExt
    ]

decodeSimpleHeader :: SimpleCrypto c
                   => (ext' -> CBOR.Encoding)
                   -> (forall s. CBOR.Decoder s ext')
                   -> forall s. CBOR.Decoder s (Header (SimpleBlock' c ext ext'))
decodeSimpleHeader :: (ext' -> Encoding)
-> (forall s. Decoder s ext')
-> forall s. Decoder s (Header (SimpleBlock' c ext ext'))
decodeSimpleHeader ext' -> Encoding
encodeExt forall s. Decoder s ext'
decodeExt = do
    Int -> Decoder s ()
forall s. Int -> Decoder s ()
CBOR.decodeListLenOf Int
2
    (ext' -> Encoding)
-> SimpleStdHeader c ext
-> ext'
-> Header (SimpleBlock' c ext ext')
forall c ext' ext.
SimpleCrypto c =>
(ext' -> Encoding)
-> SimpleStdHeader c ext
-> ext'
-> Header (SimpleBlock' c ext ext')
mkSimpleHeader ext' -> Encoding
encodeExt (SimpleStdHeader c ext -> ext' -> Header (SimpleBlock' c ext ext'))
-> Decoder s (SimpleStdHeader c ext)
-> Decoder s (ext' -> Header (SimpleBlock' c ext ext'))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (SimpleStdHeader c ext)
forall a s. Serialise a => Decoder s a
decode Decoder s (ext' -> Header (SimpleBlock' c ext ext'))
-> Decoder s ext' -> Decoder s (Header (SimpleBlock' c ext ext'))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s ext'
forall s. Decoder s ext'
decodeExt

-- | Custom 'Serialise' instance that doesn't serialise the hash
instance (SimpleCrypto c, Serialise ext')
      => Serialise (Header (SimpleBlock' c ext ext')) where
  encode :: Header (SimpleBlock' c ext ext') -> Encoding
encode = (ext' -> Encoding) -> Header (SimpleBlock' c ext ext') -> Encoding
forall ext' c ext.
(ext' -> Encoding) -> Header (SimpleBlock' c ext ext') -> Encoding
encodeSimpleHeader ext' -> Encoding
forall a. Serialise a => a -> Encoding
encode
  decode :: Decoder s (Header (SimpleBlock' c ext ext'))
decode = (ext' -> Encoding)
-> (forall s. Decoder s ext')
-> forall s. Decoder s (Header (SimpleBlock' c ext ext'))
forall c ext' ext.
SimpleCrypto c =>
(ext' -> Encoding)
-> (forall s. Decoder s ext')
-> forall s. Decoder s (Header (SimpleBlock' c ext ext'))
decodeSimpleHeader ext' -> Encoding
forall a. Serialise a => a -> Encoding
encode forall s. Decoder s ext'
forall a s. Serialise a => Decoder s a
decode

simpleBlockBinaryBlockInfo ::
     (SimpleCrypto c, Serialise ext', Typeable ext, Typeable ext')
  => SimpleBlock' c ext ext' -> BinaryBlockInfo
simpleBlockBinaryBlockInfo :: SimpleBlock' c ext ext' -> BinaryBlockInfo
simpleBlockBinaryBlockInfo SimpleBlock' c ext ext'
b = BinaryBlockInfo :: Word16 -> Word16 -> BinaryBlockInfo
BinaryBlockInfo
    { headerOffset :: Word16
headerOffset = Word16
1 -- For the 'encodeListLen'
    , headerSize :: Word16
headerSize   = Int64 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Word16) -> Int64 -> Word16
forall a b. (a -> b) -> a -> b
$ ByteString -> Int64
Lazy.length (ByteString -> Int64) -> ByteString -> Int64
forall a b. (a -> b) -> a -> b
$ Header (SimpleBlock' c ext ext') -> ByteString
forall a. Serialise a => a -> ByteString
serialise (SimpleBlock' c ext ext' -> Header (SimpleBlock' c ext ext')
forall blk. GetHeader blk => blk -> Header blk
getHeader SimpleBlock' c ext ext'
b)
    }