{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DisambiguateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}

module Test.Consensus.Byron.Examples
  ( -- * Setup
    topLevelConfig
  , blockConfig
  , codecConfig
  , leaderCredentials
  , ledgerConfig
  , secParam
  , windowSize

    -- * Examples
  , exampleApplyTxErr
  , exampleChainDepState
  , exampleExtLedgerState
  , exampleGenTx
  , exampleGenTxId
  , exampleHeaderHash
  , exampleHeaderState
  , exampleLedgerState
  , examples
  ) where

import qualified Cardano.Chain.Block as CC.Block
import qualified Cardano.Chain.Byron.API as CC
import qualified Cardano.Chain.Common as CC
import qualified Cardano.Chain.UTxO as CC
import qualified Cardano.Chain.Update.Validation.Interface as CC.UPI
import Cardano.Ledger.BaseTypes (knownNonZeroBounded)
import Control.Monad.Except (runExcept)
import qualified Data.Map.Strict as Map
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Byron.Crypto.DSIGN (SignKeyDSIGN (..))
import Ouroboros.Consensus.Byron.Ledger
import Ouroboros.Consensus.Byron.Node
  ( ByronLeaderCredentials (..)
  )
import Ouroboros.Consensus.Config
import Ouroboros.Consensus.HeaderValidation
import Ouroboros.Consensus.Ledger.Abstract
import Ouroboros.Consensus.Ledger.Extended
import Ouroboros.Consensus.Ledger.Peras (initPerasState)
import Ouroboros.Consensus.Ledger.Query
import Ouroboros.Consensus.Ledger.Tables.Utils
import Ouroboros.Consensus.Node.ProtocolInfo
  ( NumCoreNodes (NumCoreNodes)
  )
import Ouroboros.Consensus.NodeId
import Ouroboros.Consensus.Protocol.Abstract
import Ouroboros.Consensus.Protocol.PBFT
import qualified Ouroboros.Consensus.Protocol.PBFT.State as S
import Ouroboros.Consensus.Storage.Serialisation
import Ouroboros.Network.Block (Serialised (..))
import qualified Test.Cardano.Chain.Common.Example as CC
import qualified Test.Cardano.Chain.Genesis.Dummy as CC
import qualified Test.Cardano.Chain.UTxO.Example as CC
import qualified Test.Cardano.Chain.Update.Example as CC
import Test.ThreadNet.Infra.Byron.Genesis (byronPBftParams)
import Test.ThreadNet.Infra.Byron.ProtocolInfo (mkLeaderCredentials)
import Test.Util.Serialisation.Examples
  ( Examples (Examples)
  , Labelled
  , labelled
  , unlabelled
  )
import qualified Test.Util.Serialisation.Examples as Examples
import Test.Util.Serialisation.SomeResult (SomeResult (..))

{-------------------------------------------------------------------------------
  Setup
-------------------------------------------------------------------------------}

-- | Note that we must use the same value for the 'SecurityParam' as for the
-- 'S.WindowSize', because 'decodeByronChainDepState' only takes the
-- 'SecurityParam' and uses it as the basis for the 'S.WindowSize'.
secParam :: SecurityParam
secParam :: SecurityParam
secParam = NonZero Word64 -> SecurityParam
SecurityParam (NonZero Word64 -> SecurityParam)
-> NonZero Word64 -> SecurityParam
forall a b. (a -> b) -> a -> b
$ forall (n :: Natural) a.
(KnownNat n, 1 <= n, WithinBounds n a, Num a) =>
NonZero a
knownNonZeroBounded @2

windowSize :: S.WindowSize
windowSize :: WindowSize
windowSize = Word64 -> WindowSize
S.WindowSize Word64
2

topLevelConfig :: TopLevelConfig ByronBlock
topLevelConfig :: TopLevelConfig ByronBlock
topLevelConfig =
  TopLevelConfig
    { topLevelConfigProtocol :: ConsensusConfig (BlockProtocol ByronBlock)
topLevelConfigProtocol = ConsensusConfig (BlockProtocol ByronBlock)
ConsensusConfig (PBft PBftByronCrypto)
forall c. ConsensusConfig (PBft c)
pbftConfig
    , topLevelConfigLedger :: LedgerConfig ByronBlock
topLevelConfigLedger = Config
LedgerConfig ByronBlock
CC.dummyConfig
    , topLevelConfigBlock :: BlockConfig ByronBlock
topLevelConfigBlock = BlockConfig ByronBlock
blockConfig
    , topLevelConfigCodec :: CodecConfig ByronBlock
topLevelConfigCodec = CodecConfig ByronBlock
codecConfig
    , topLevelConfigStorage :: StorageConfig ByronBlock
topLevelConfigStorage = BlockConfig ByronBlock -> StorageConfig ByronBlock
ByronStorageConfig BlockConfig ByronBlock
blockConfig
    , topLevelConfigCheckpoints :: CheckpointsMap ByronBlock
topLevelConfigCheckpoints = CheckpointsMap ByronBlock
forall blk. CheckpointsMap blk
emptyCheckpointsMap
    }

pbftConfig :: ConsensusConfig (PBft c)
pbftConfig :: forall c. ConsensusConfig (PBft c)
pbftConfig = PBftConfig{pbftParams :: PBftParams
pbftParams = SecurityParam -> NumCoreNodes -> PBftParams
byronPBftParams SecurityParam
secParam (Word64 -> NumCoreNodes
NumCoreNodes Word64
1)}

blockConfig :: BlockConfig ByronBlock
blockConfig :: BlockConfig ByronBlock
blockConfig =
  ByronConfig
    { byronGenesisConfig :: Config
byronGenesisConfig = Config
CC.dummyConfig
    , byronProtocolVersion :: ProtocolVersion
byronProtocolVersion = ProtocolVersion
CC.exampleProtocolVersion
    , byronSoftwareVersion :: SoftwareVersion
byronSoftwareVersion = SoftwareVersion
CC.exampleSoftwareVersion
    }

codecConfig :: CodecConfig ByronBlock
codecConfig :: CodecConfig ByronBlock
codecConfig = Config -> CodecConfig ByronBlock
mkByronCodecConfig Config
CC.dummyConfig

ledgerConfig :: LedgerConfig ByronBlock
ledgerConfig :: LedgerConfig ByronBlock
ledgerConfig = Config
LedgerConfig ByronBlock
CC.dummyConfig

leaderCredentials :: ByronLeaderCredentials
leaderCredentials :: ByronLeaderCredentials
leaderCredentials =
  HasCallStack =>
Config -> GeneratedSecrets -> CoreNodeId -> ByronLeaderCredentials
Config -> GeneratedSecrets -> CoreNodeId -> ByronLeaderCredentials
mkLeaderCredentials
    Config
CC.dummyConfig
    GeneratedSecrets
CC.dummyGeneratedSecrets
    (Word64 -> CoreNodeId
CoreNodeId Word64
0)

{-------------------------------------------------------------------------------
  Examples
-------------------------------------------------------------------------------}

examples :: Examples ByronBlock
examples :: Examples ByronBlock
examples =
  Examples
    { exampleBlock :: Labelled ByronBlock
exampleBlock = ByronBlock -> ByronBlock -> Labelled ByronBlock
forall a. a -> a -> Labelled a
regularAndEBB ByronBlock
exampleBlock ByronBlock
exampleEBB
    , exampleSerialisedBlock :: Labelled (Serialised ByronBlock)
exampleSerialisedBlock = Serialised ByronBlock
-> Serialised ByronBlock -> Labelled (Serialised ByronBlock)
forall a. a -> a -> Labelled a
regularAndEBB Serialised ByronBlock
exampleSerialisedBlock Serialised ByronBlock
exampleSerialisedEBB
    , exampleHeader :: Labelled (Header ByronBlock)
exampleHeader = Header ByronBlock
-> Header ByronBlock -> Labelled (Header ByronBlock)
forall a. a -> a -> Labelled a
regularAndEBB Header ByronBlock
exampleHeader Header ByronBlock
exampleEBBHeader
    , exampleSerialisedHeader :: Labelled (SerialisedHeader ByronBlock)
exampleSerialisedHeader = SerialisedHeader ByronBlock
-> SerialisedHeader ByronBlock
-> Labelled (SerialisedHeader ByronBlock)
forall a. a -> a -> Labelled a
regularAndEBB SerialisedHeader ByronBlock
exampleSerialisedHeader SerialisedHeader ByronBlock
exampleSerialisedEBBHeader
    , exampleHeaderHash :: Labelled (HeaderHash ByronBlock)
exampleHeaderHash = ByronHash -> Labelled ByronHash
forall a. a -> Labelled a
unlabelled ByronHash
exampleHeaderHash
    , exampleGenTx :: Labelled (GenTx ByronBlock)
exampleGenTx = GenTx ByronBlock -> Labelled (GenTx ByronBlock)
forall a. a -> Labelled a
unlabelled GenTx ByronBlock
exampleGenTx
    , exampleGenTxId :: Labelled (GenTxId ByronBlock)
exampleGenTxId = GenTxId ByronBlock -> Labelled (GenTxId ByronBlock)
forall a. a -> Labelled a
unlabelled GenTxId ByronBlock
exampleGenTxId
    , exampleApplyTxErr :: Labelled (ApplyTxErr ByronBlock)
exampleApplyTxErr = ApplyMempoolPayloadErr -> Labelled ApplyMempoolPayloadErr
forall a. a -> Labelled a
unlabelled ApplyMempoolPayloadErr
exampleApplyTxErr
    , exampleQuery :: Labelled (SomeBlockQuery (BlockQuery ByronBlock))
exampleQuery = SomeBlockQuery (BlockQuery ByronBlock)
-> Labelled (SomeBlockQuery (BlockQuery ByronBlock))
forall a. a -> Labelled a
unlabelled SomeBlockQuery (BlockQuery ByronBlock)
exampleQuery
    , exampleResult :: Labelled (SomeResult ByronBlock)
exampleResult = SomeResult ByronBlock -> Labelled (SomeResult ByronBlock)
forall a. a -> Labelled a
unlabelled SomeResult ByronBlock
exampleResult
    , exampleAnnTip :: Labelled (AnnTip ByronBlock)
exampleAnnTip = AnnTip ByronBlock -> Labelled (AnnTip ByronBlock)
forall a. a -> Labelled a
unlabelled AnnTip ByronBlock
exampleAnnTip
    , exampleLedgerConfig :: Labelled (LedgerConfig ByronBlock)
exampleLedgerConfig = Config -> Labelled Config
forall a. a -> Labelled a
unlabelled Config
LedgerConfig ByronBlock
ledgerConfig
    , exampleLedgerState :: Labelled (LedgerState ByronBlock EmptyMK)
exampleLedgerState = LedgerState ByronBlock EmptyMK
-> Labelled (LedgerState ByronBlock EmptyMK)
forall a. a -> Labelled a
unlabelled (LedgerState ByronBlock EmptyMK
 -> Labelled (LedgerState ByronBlock EmptyMK))
-> LedgerState ByronBlock EmptyMK
-> Labelled (LedgerState ByronBlock EmptyMK)
forall a b. (a -> b) -> a -> b
$ LedgerState ByronBlock ValuesMK -> LedgerState ByronBlock EmptyMK
forall (l :: StateKind) blk (mk :: MapKind).
HasLedgerTables l blk =>
l blk mk -> l blk EmptyMK
forgetLedgerTables LedgerState ByronBlock ValuesMK
exampleLedgerState
    , exampleChainDepState :: Labelled (ChainDepState (BlockProtocol ByronBlock))
exampleChainDepState = PBftState PBftByronCrypto -> Labelled (PBftState PBftByronCrypto)
forall a. a -> Labelled a
unlabelled ChainDepState (BlockProtocol ByronBlock)
PBftState PBftByronCrypto
exampleChainDepState
    , exampleExtLedgerState :: Labelled (ExtLedgerState ByronBlock EmptyMK)
exampleExtLedgerState = ExtLedgerState ByronBlock EmptyMK
-> Labelled (ExtLedgerState ByronBlock EmptyMK)
forall a. a -> Labelled a
unlabelled (ExtLedgerState ByronBlock EmptyMK
 -> Labelled (ExtLedgerState ByronBlock EmptyMK))
-> ExtLedgerState ByronBlock EmptyMK
-> Labelled (ExtLedgerState ByronBlock EmptyMK)
forall a b. (a -> b) -> a -> b
$ ExtLedgerState ByronBlock ValuesMK
-> ExtLedgerState ByronBlock EmptyMK
forall (l :: StateKind) blk (mk :: MapKind).
HasLedgerTables l blk =>
l blk mk -> l blk EmptyMK
forgetLedgerTables ExtLedgerState ByronBlock ValuesMK
exampleExtLedgerState
    , exampleSlotNo :: Labelled SlotNo
exampleSlotNo = SlotNo -> Labelled SlotNo
forall a. a -> Labelled a
unlabelled SlotNo
exampleSlotNo
    }
 where
  regularAndEBB :: a -> a -> Labelled a
  regularAndEBB :: forall a. a -> a -> Labelled a
regularAndEBB a
regular a
ebb = [(String, a)] -> Labelled a
forall a. [(String, a)] -> Labelled a
labelled [(String
"regular", a
regular), (String
"EBB", a
ebb)]

  exampleQuery :: SomeBlockQuery (BlockQuery ByronBlock)
exampleQuery = BlockQuery ByronBlock 'QFNoTables State
-> SomeBlockQuery (BlockQuery ByronBlock)
forall (q :: QueryFootprint -> * -> *)
       (footprint :: QueryFootprint) result.
SingI footprint =>
q footprint result -> SomeBlockQuery q
SomeBlockQuery BlockQuery ByronBlock 'QFNoTables State
GetUpdateInterfaceState
  exampleResult :: SomeResult ByronBlock
exampleResult = BlockQuery ByronBlock 'QFNoTables State
-> State -> SomeResult ByronBlock
forall result blk (fp :: QueryFootprint).
(Eq result, Show result, Typeable result) =>
BlockQuery blk fp result -> result -> SomeResult blk
SomeResult BlockQuery ByronBlock 'QFNoTables State
GetUpdateInterfaceState State
exampleUPIState

exampleBlock :: ByronBlock
exampleBlock :: ByronBlock
exampleBlock =
  HasCallStack => ForgeBlockArgs ByronBlock -> ByronBlock
ForgeBlockArgs ByronBlock -> ByronBlock
forgeRegularBlock (ForgeBlockArgs ByronBlock -> ByronBlock)
-> ForgeBlockArgs ByronBlock -> ByronBlock
forall a b. (a -> b) -> a -> b
$
    ForgeBlockArgs
      { fbConfig :: TopLevelConfig ByronBlock
fbConfig = TopLevelConfig ByronBlock
topLevelConfig
      , fbCurrentBlockNo :: BlockNo
fbCurrentBlockNo = Word64 -> BlockNo
BlockNo Word64
1
      , fbCurrentSlotNo :: SlotNo
fbCurrentSlotNo = Word64 -> SlotNo
SlotNo Word64
1
      , fbPerasCert :: Maybe (PerasCert ByronBlock)
fbPerasCert = Maybe (VoidPerasCert ByronBlock)
Maybe (PerasCert ByronBlock)
forall a. Maybe a
Nothing -- Doesn't support Peras
      , fbCurrentTickedLedgerState :: TickedLedgerState ByronBlock EmptyMK
fbCurrentTickedLedgerState =
          Ticked LedgerState ByronBlock DiffMK
-> TickedLedgerState ByronBlock EmptyMK
forall (l :: StateKind) blk (mk :: MapKind).
HasLedgerTables l blk =>
l blk mk -> l blk EmptyMK
forgetLedgerTables (Ticked LedgerState ByronBlock DiffMK
 -> TickedLedgerState ByronBlock EmptyMK)
-> Ticked LedgerState ByronBlock DiffMK
-> TickedLedgerState ByronBlock EmptyMK
forall a b. (a -> b) -> a -> b
$
            ComputeLedgerEvents
-> LedgerConfig ByronBlock
-> SlotNo
-> LedgerState ByronBlock EmptyMK
-> Ticked LedgerState ByronBlock DiffMK
forall (l :: StateKind) blk.
IsLedger l blk =>
ComputeLedgerEvents
-> LedgerCfg l blk
-> SlotNo
-> l blk EmptyMK
-> Ticked l blk DiffMK
applyChainTick ComputeLedgerEvents
OmitLedgerEvents LedgerConfig ByronBlock
ledgerConfig (Word64 -> SlotNo
SlotNo Word64
1) (LedgerState ByronBlock ValuesMK -> LedgerState ByronBlock EmptyMK
forall (l :: StateKind) blk (mk :: MapKind).
HasLedgerTables l blk =>
l blk mk -> l blk EmptyMK
forgetLedgerTables LedgerState ByronBlock ValuesMK
ledgerStateAfterEBB)
      , fbTxs :: [Validated (GenTx ByronBlock)]
fbTxs = [GenTx ByronBlock -> Validated (GenTx ByronBlock)
ValidatedByronTx GenTx ByronBlock
exampleGenTx]
      , fbIsLeader :: IsLeader (BlockProtocol ByronBlock)
fbIsLeader = ByronLeaderCredentials -> PBftIsLeader PBftByronCrypto
fakeMkIsLeader ByronLeaderCredentials
leaderCredentials
      }
 where
  -- \| Normally, we'd have to use 'checkIsLeader' to produce this proof.
  fakeMkIsLeader :: ByronLeaderCredentials -> PBftIsLeader PBftByronCrypto
fakeMkIsLeader (ByronLeaderCredentials SigningKey
signKey Certificate
dlgCert CoreNodeId
_ Text
_) =
    PBftIsLeader
      { pbftIsLeaderSignKey :: SignKeyDSIGN (PBftDSIGN PBftByronCrypto)
pbftIsLeaderSignKey = SigningKey -> SignKeyDSIGN ByronDSIGN
SignKeyByronDSIGN SigningKey
signKey
      , pbftIsLeaderDlgCert :: PBftDelegationCert PBftByronCrypto
pbftIsLeaderDlgCert = Certificate
PBftDelegationCert PBftByronCrypto
dlgCert
      }

exampleEBB :: ByronBlock
exampleEBB :: ByronBlock
exampleEBB = BlockConfig ByronBlock
-> SlotNo -> BlockNo -> ChainHash ByronBlock -> ByronBlock
forgeEBB BlockConfig ByronBlock
blockConfig (Word64 -> SlotNo
SlotNo Word64
0) (Word64 -> BlockNo
BlockNo Word64
0) ChainHash ByronBlock
forall {k} (b :: k). ChainHash b
GenesisHash

exampleSerialisedBlock :: Serialised ByronBlock
exampleSerialisedBlock :: Serialised ByronBlock
exampleSerialisedBlock = ByteString -> Serialised ByronBlock
forall {k} (a :: k). ByteString -> Serialised a
Serialised ByteString
"<BLOCK>"

exampleSerialisedEBB :: Serialised ByronBlock
exampleSerialisedEBB :: Serialised ByronBlock
exampleSerialisedEBB = ByteString -> Serialised ByronBlock
forall {k} (a :: k). ByteString -> Serialised a
Serialised ByteString
"<EBB>"

exampleHeader :: Header ByronBlock
exampleHeader :: Header ByronBlock
exampleHeader = ByronBlock -> Header ByronBlock
forall blk. GetHeader blk => blk -> Header blk
getHeader ByronBlock
exampleBlock

exampleEBBHeader :: Header ByronBlock
exampleEBBHeader :: Header ByronBlock
exampleEBBHeader = ByronBlock -> Header ByronBlock
forall blk. GetHeader blk => blk -> Header blk
getHeader ByronBlock
exampleEBB

exampleSerialisedHeader :: SerialisedHeader ByronBlock
exampleSerialisedHeader :: SerialisedHeader ByronBlock
exampleSerialisedHeader =
  GenDepPair Serialised (NestedCtxt Header ByronBlock)
-> SerialisedHeader ByronBlock
forall blk.
GenDepPair Serialised (NestedCtxt Header blk)
-> SerialisedHeader blk
SerialisedHeaderFromDepPair (GenDepPair Serialised (NestedCtxt Header ByronBlock)
 -> SerialisedHeader ByronBlock)
-> GenDepPair Serialised (NestedCtxt Header ByronBlock)
-> SerialisedHeader ByronBlock
forall a b. (a -> b) -> a -> b
$
    NestedCtxt Header ByronBlock (AHeader ByteString)
-> Serialised (AHeader ByteString)
-> GenDepPair Serialised (NestedCtxt Header ByronBlock)
forall {k} (f :: k -> *) (a :: k) (g :: k -> *).
f a -> g a -> GenDepPair g f
GenDepPair (NestedCtxt_ ByronBlock Header (AHeader ByteString)
-> NestedCtxt Header ByronBlock (AHeader ByteString)
forall (f :: * -> *) blk a.
NestedCtxt_ blk f a -> NestedCtxt f blk a
NestedCtxt (SizeInBytes -> NestedCtxt_ ByronBlock Header (AHeader ByteString)
CtxtByronRegular SizeInBytes
100)) (ByteString -> Serialised (AHeader ByteString)
forall {k} (a :: k). ByteString -> Serialised a
Serialised ByteString
"<HEADER>")

exampleSerialisedEBBHeader :: SerialisedHeader ByronBlock
exampleSerialisedEBBHeader :: SerialisedHeader ByronBlock
exampleSerialisedEBBHeader =
  GenDepPair Serialised (NestedCtxt Header ByronBlock)
-> SerialisedHeader ByronBlock
forall blk.
GenDepPair Serialised (NestedCtxt Header blk)
-> SerialisedHeader blk
SerialisedHeaderFromDepPair (GenDepPair Serialised (NestedCtxt Header ByronBlock)
 -> SerialisedHeader ByronBlock)
-> GenDepPair Serialised (NestedCtxt Header ByronBlock)
-> SerialisedHeader ByronBlock
forall a b. (a -> b) -> a -> b
$
    NestedCtxt Header ByronBlock (SlotNo, RawBoundaryHeader)
-> Serialised (SlotNo, RawBoundaryHeader)
-> GenDepPair Serialised (NestedCtxt Header ByronBlock)
forall {k} (f :: k -> *) (a :: k) (g :: k -> *).
f a -> g a -> GenDepPair g f
GenDepPair (NestedCtxt_ ByronBlock Header (SlotNo, RawBoundaryHeader)
-> NestedCtxt Header ByronBlock (SlotNo, RawBoundaryHeader)
forall (f :: * -> *) blk a.
NestedCtxt_ blk f a -> NestedCtxt f blk a
NestedCtxt (SizeInBytes
-> NestedCtxt_ ByronBlock Header (SlotNo, RawBoundaryHeader)
CtxtByronBoundary SizeInBytes
100)) (ByteString -> Serialised (SlotNo, RawBoundaryHeader)
forall {k} (a :: k). ByteString -> Serialised a
Serialised ByteString
"<EBB_HEADER>")

exampleAnnTip :: AnnTip ByronBlock
exampleAnnTip :: AnnTip ByronBlock
exampleAnnTip =
  AnnTip
    { annTipSlotNo :: SlotNo
annTipSlotNo = Word64 -> SlotNo
SlotNo Word64
37
    , annTipBlockNo :: BlockNo
annTipBlockNo = Word64 -> BlockNo
BlockNo Word64
23
    , annTipInfo :: TipInfo ByronBlock
annTipInfo = HeaderHash ByronBlock -> IsEBB -> TipInfoIsEBB ByronBlock
forall blk. HeaderHash blk -> IsEBB -> TipInfoIsEBB blk
TipInfoIsEBB HeaderHash ByronBlock
ByronHash
exampleHeaderHash IsEBB
IsNotEBB
    }

exampleChainDepState :: ChainDepState (BlockProtocol ByronBlock)
exampleChainDepState :: ChainDepState (BlockProtocol ByronBlock)
exampleChainDepState = [PBftSigner PBftByronCrypto] -> PBftState PBftByronCrypto
forall c. PBftCrypto c => [PBftSigner c] -> PBftState c
S.fromList [PBftSigner PBftByronCrypto]
signers
 where
  signers :: [PBftSigner PBftByronCrypto]
signers = (SlotNo -> PBftSigner PBftByronCrypto)
-> [SlotNo] -> [PBftSigner PBftByronCrypto]
forall a b. (a -> b) -> [a] -> [b]
map (SlotNo
-> PBftVerKeyHash PBftByronCrypto -> PBftSigner PBftByronCrypto
forall c. SlotNo -> PBftVerKeyHash c -> PBftSigner c
`S.PBftSigner` KeyHash
PBftVerKeyHash PBftByronCrypto
CC.exampleKeyHash) [SlotNo
1 .. SlotNo
4]

emptyLedgerState :: LedgerState ByronBlock ValuesMK
emptyLedgerState :: LedgerState ByronBlock ValuesMK
emptyLedgerState =
  ByronLedgerState
    { byronLedgerTipBlockNo :: WithOrigin BlockNo
byronLedgerTipBlockNo = WithOrigin BlockNo
forall t. WithOrigin t
Origin
    , byronLedgerState :: ChainValidationState
byronLedgerState = ChainValidationState
initState
    , byronLedgerTransition :: ByronTransition
byronLedgerTransition = Map ProtocolVersion BlockNo -> ByronTransition
ByronTransitionInfo Map ProtocolVersion BlockNo
forall k a. Map k a
Map.empty
    }
 where
  initState :: CC.Block.ChainValidationState
  Right ChainValidationState
initState =
    Except Error ChainValidationState
-> Either Error ChainValidationState
forall e a. Except e a -> Either e a
runExcept (Except Error ChainValidationState
 -> Either Error ChainValidationState)
-> Except Error ChainValidationState
-> Either Error ChainValidationState
forall a b. (a -> b) -> a -> b
$
      Config -> Except Error ChainValidationState
forall (m :: * -> *).
MonadError Error m =>
Config -> m ChainValidationState
CC.Block.initialChainValidationState Config
LedgerConfig ByronBlock
ledgerConfig

ledgerStateAfterEBB :: LedgerState ByronBlock ValuesMK
ledgerStateAfterEBB :: LedgerState ByronBlock ValuesMK
ledgerStateAfterEBB =
  LedgerState ByronBlock ValuesMK
-> LedgerState ByronBlock DiffMK -> LedgerState ByronBlock ValuesMK
forall (l :: StateKind) blk (l' :: StateKind).
(HasLedgerTables l blk, HasLedgerTables l' blk) =>
l blk ValuesMK -> l' blk DiffMK -> l' blk ValuesMK
applyDiffs LedgerState ByronBlock ValuesMK
emptyLedgerState
    (LedgerState ByronBlock DiffMK -> LedgerState ByronBlock ValuesMK)
-> (LedgerState ByronBlock ValuesMK
    -> LedgerState ByronBlock DiffMK)
-> LedgerState ByronBlock ValuesMK
-> LedgerState ByronBlock ValuesMK
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ComputeLedgerEvents
-> LedgerConfig ByronBlock
-> ByronBlock
-> Ticked LedgerState ByronBlock ValuesMK
-> LedgerState ByronBlock DiffMK
forall (l :: StateKind) blk.
(ApplyBlock l blk, HasCallStack) =>
ComputeLedgerEvents
-> LedgerCfg l blk -> blk -> Ticked l blk ValuesMK -> l blk DiffMK
reapplyLedgerBlock ComputeLedgerEvents
OmitLedgerEvents LedgerConfig ByronBlock
ledgerConfig ByronBlock
exampleEBB
    (Ticked LedgerState ByronBlock ValuesMK
 -> LedgerState ByronBlock DiffMK)
-> (LedgerState ByronBlock ValuesMK
    -> Ticked LedgerState ByronBlock ValuesMK)
-> LedgerState ByronBlock ValuesMK
-> LedgerState ByronBlock DiffMK
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerState ByronBlock ValuesMK
-> Ticked LedgerState ByronBlock DiffMK
-> Ticked LedgerState ByronBlock ValuesMK
forall (l :: StateKind) blk (l' :: StateKind).
(HasLedgerTables l blk, HasLedgerTables l' blk) =>
l blk ValuesMK -> l' blk DiffMK -> l' blk ValuesMK
applyDiffs LedgerState ByronBlock ValuesMK
emptyLedgerState
    (Ticked LedgerState ByronBlock DiffMK
 -> Ticked LedgerState ByronBlock ValuesMK)
-> (LedgerState ByronBlock ValuesMK
    -> Ticked LedgerState ByronBlock DiffMK)
-> LedgerState ByronBlock ValuesMK
-> Ticked LedgerState ByronBlock ValuesMK
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ComputeLedgerEvents
-> LedgerConfig ByronBlock
-> SlotNo
-> LedgerState ByronBlock EmptyMK
-> Ticked LedgerState ByronBlock DiffMK
forall (l :: StateKind) blk.
IsLedger l blk =>
ComputeLedgerEvents
-> LedgerCfg l blk
-> SlotNo
-> l blk EmptyMK
-> Ticked l blk DiffMK
applyChainTick ComputeLedgerEvents
OmitLedgerEvents LedgerConfig ByronBlock
ledgerConfig (Word64 -> SlotNo
SlotNo Word64
0)
    (LedgerState ByronBlock EmptyMK
 -> Ticked LedgerState ByronBlock DiffMK)
-> (LedgerState ByronBlock ValuesMK
    -> LedgerState ByronBlock EmptyMK)
-> LedgerState ByronBlock ValuesMK
-> Ticked LedgerState ByronBlock DiffMK
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerState ByronBlock ValuesMK -> LedgerState ByronBlock EmptyMK
forall (l :: StateKind) blk (mk :: MapKind).
HasLedgerTables l blk =>
l blk mk -> l blk EmptyMK
forgetLedgerTables
    (LedgerState ByronBlock ValuesMK
 -> LedgerState ByronBlock ValuesMK)
-> LedgerState ByronBlock ValuesMK
-> LedgerState ByronBlock ValuesMK
forall a b. (a -> b) -> a -> b
$ LedgerState ByronBlock ValuesMK
emptyLedgerState

exampleLedgerState :: LedgerState ByronBlock ValuesMK
exampleLedgerState :: LedgerState ByronBlock ValuesMK
exampleLedgerState =
  LedgerState ByronBlock ValuesMK
-> LedgerState ByronBlock DiffMK -> LedgerState ByronBlock ValuesMK
forall (l :: StateKind) blk (l' :: StateKind).
(HasLedgerTables l blk, HasLedgerTables l' blk) =>
l blk ValuesMK -> l' blk DiffMK -> l' blk ValuesMK
applyDiffs LedgerState ByronBlock ValuesMK
emptyLedgerState
    (LedgerState ByronBlock DiffMK -> LedgerState ByronBlock ValuesMK)
-> (LedgerState ByronBlock ValuesMK
    -> LedgerState ByronBlock DiffMK)
-> LedgerState ByronBlock ValuesMK
-> LedgerState ByronBlock ValuesMK
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ComputeLedgerEvents
-> LedgerConfig ByronBlock
-> ByronBlock
-> Ticked LedgerState ByronBlock ValuesMK
-> LedgerState ByronBlock DiffMK
forall (l :: StateKind) blk.
(ApplyBlock l blk, HasCallStack) =>
ComputeLedgerEvents
-> LedgerCfg l blk -> blk -> Ticked l blk ValuesMK -> l blk DiffMK
reapplyLedgerBlock ComputeLedgerEvents
OmitLedgerEvents LedgerConfig ByronBlock
ledgerConfig ByronBlock
exampleBlock
    (Ticked LedgerState ByronBlock ValuesMK
 -> LedgerState ByronBlock DiffMK)
-> (LedgerState ByronBlock ValuesMK
    -> Ticked LedgerState ByronBlock ValuesMK)
-> LedgerState ByronBlock ValuesMK
-> LedgerState ByronBlock DiffMK
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerState ByronBlock ValuesMK
-> Ticked LedgerState ByronBlock DiffMK
-> Ticked LedgerState ByronBlock ValuesMK
forall (l :: StateKind) blk (l' :: StateKind).
(HasLedgerTables l blk, HasLedgerTables l' blk) =>
l blk ValuesMK -> l' blk DiffMK -> l' blk ValuesMK
applyDiffs LedgerState ByronBlock ValuesMK
ledgerStateAfterEBB
    (Ticked LedgerState ByronBlock DiffMK
 -> Ticked LedgerState ByronBlock ValuesMK)
-> (LedgerState ByronBlock ValuesMK
    -> Ticked LedgerState ByronBlock DiffMK)
-> LedgerState ByronBlock ValuesMK
-> Ticked LedgerState ByronBlock ValuesMK
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ComputeLedgerEvents
-> LedgerConfig ByronBlock
-> SlotNo
-> LedgerState ByronBlock EmptyMK
-> Ticked LedgerState ByronBlock DiffMK
forall (l :: StateKind) blk.
IsLedger l blk =>
ComputeLedgerEvents
-> LedgerCfg l blk
-> SlotNo
-> l blk EmptyMK
-> Ticked l blk DiffMK
applyChainTick ComputeLedgerEvents
OmitLedgerEvents LedgerConfig ByronBlock
ledgerConfig (Word64 -> SlotNo
SlotNo Word64
1)
    (LedgerState ByronBlock EmptyMK
 -> Ticked LedgerState ByronBlock DiffMK)
-> (LedgerState ByronBlock ValuesMK
    -> LedgerState ByronBlock EmptyMK)
-> LedgerState ByronBlock ValuesMK
-> Ticked LedgerState ByronBlock DiffMK
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerState ByronBlock ValuesMK -> LedgerState ByronBlock EmptyMK
forall (l :: StateKind) blk (mk :: MapKind).
HasLedgerTables l blk =>
l blk mk -> l blk EmptyMK
forgetLedgerTables
    (LedgerState ByronBlock ValuesMK
 -> LedgerState ByronBlock ValuesMK)
-> LedgerState ByronBlock ValuesMK
-> LedgerState ByronBlock ValuesMK
forall a b. (a -> b) -> a -> b
$ LedgerState ByronBlock ValuesMK
ledgerStateAfterEBB

exampleHeaderState :: HeaderState ByronBlock
exampleHeaderState :: HeaderState ByronBlock
exampleHeaderState = WithOrigin (AnnTip ByronBlock)
-> ChainDepState (BlockProtocol ByronBlock)
-> HeaderState ByronBlock
forall blk.
WithOrigin (AnnTip blk)
-> ChainDepState (BlockProtocol blk) -> HeaderState blk
HeaderState (AnnTip ByronBlock -> WithOrigin (AnnTip ByronBlock)
forall t. t -> WithOrigin t
NotOrigin AnnTip ByronBlock
exampleAnnTip) ChainDepState (BlockProtocol ByronBlock)
exampleChainDepState

exampleExtLedgerState :: ExtLedgerState ByronBlock ValuesMK
exampleExtLedgerState :: ExtLedgerState ByronBlock ValuesMK
exampleExtLedgerState =
  let ledgerState :: LedgerState ByronBlock ValuesMK
ledgerState = LedgerState ByronBlock ValuesMK
exampleLedgerState
      headerState :: HeaderState ByronBlock
headerState = HeaderState ByronBlock
exampleHeaderState
      perasState :: PerasState ByronBlock
perasState = LedgerConfig ByronBlock
-> LedgerState ByronBlock ValuesMK
-> HeaderState ByronBlock
-> PerasState ByronBlock
forall blk (mk :: MapKind).
(All Top (HardForkIndices blk), StateSupportsPerasEpochContext blk,
 HasLedgerTables LedgerState blk) =>
LedgerCfg LedgerState blk
-> LedgerState blk mk -> HeaderState blk -> PerasState blk
initPerasState LedgerConfig ByronBlock
ledgerConfig LedgerState ByronBlock ValuesMK
ledgerState HeaderState ByronBlock
headerState
   in ExtLedgerState
        { LedgerState ByronBlock ValuesMK
ledgerState :: LedgerState ByronBlock ValuesMK
ledgerState :: LedgerState ByronBlock ValuesMK
ledgerState
        , HeaderState ByronBlock
headerState :: HeaderState ByronBlock
headerState :: HeaderState ByronBlock
headerState
        , PerasState ByronBlock
perasState :: PerasState ByronBlock
perasState :: PerasState ByronBlock
perasState
        }

exampleHeaderHash :: ByronHash
exampleHeaderHash :: ByronHash
exampleHeaderHash = ByronBlock -> HeaderHash ByronBlock
forall b. HasHeader b => b -> HeaderHash b
blockHash ByronBlock
exampleBlock

exampleGenTx :: GenTx ByronBlock
exampleGenTx :: GenTx ByronBlock
exampleGenTx = TxId -> ATxAux ByteString -> GenTx ByronBlock
ByronTx TxId
CC.exampleTxId (TxAux -> ATxAux ByteString
CC.annotateTxAux TxAux
CC.exampleTxAux)

exampleGenTxId :: TxId (GenTx ByronBlock)
exampleGenTxId :: GenTxId ByronBlock
exampleGenTxId = TxId -> GenTxId ByronBlock
ByronTxId TxId
CC.exampleTxId

exampleUPIState :: CC.UPI.State
exampleUPIState :: State
exampleUPIState = Config -> State
CC.UPI.initialState Config
LedgerConfig ByronBlock
ledgerConfig

exampleApplyTxErr :: CC.ApplyMempoolPayloadErr
exampleApplyTxErr :: ApplyMempoolPayloadErr
exampleApplyTxErr =
  UTxOValidationError -> ApplyMempoolPayloadErr
CC.MempoolTxErr (UTxOValidationError -> ApplyMempoolPayloadErr)
-> UTxOValidationError -> ApplyMempoolPayloadErr
forall a b. (a -> b) -> a -> b
$
    TxValidationError -> UTxOValidationError
CC.UTxOValidationTxValidationError (TxValidationError -> UTxOValidationError)
-> TxValidationError -> UTxOValidationError
forall a b. (a -> b) -> a -> b
$
      Text -> LovelaceError -> TxValidationError
CC.TxValidationLovelaceError Text
"a" (LovelaceError -> TxValidationError)
-> LovelaceError -> TxValidationError
forall a b. (a -> b) -> a -> b
$
        Word64 -> LovelaceError
CC.LovelaceOverflow Word64
0

exampleSlotNo :: SlotNo
exampleSlotNo :: SlotNo
exampleSlotNo = Word64 -> SlotNo
SlotNo Word64
42