1
{-# LANGUAGE ConstraintKinds #-}
2
{-# LANGUAGE ExistentialQuantification #-}
3
{-# LANGUAGE FlexibleContexts #-}
4
{-# LANGUAGE FlexibleInstances #-}
6
{-# LANGUAGE MultiParamTypeClasses #-}
7
{-# LANGUAGE StandaloneDeriving #-}
8
{-# LANGUAGE TypeFamilies #-}
10
module Cardano.Api.Protocol.Types
13
, ProtocolInfoArgs(..)
15
, ProtocolClientInfoArgs(..)
16
, SomeNodeClientProtocol(..)
19
import Cardano.Prelude
21
import Cardano.Chain.Slotting (EpochSlots)
23
import Ouroboros.Consensus.Byron.Ledger (ByronBlock)
24
import Ouroboros.Consensus.Cardano
25
import Ouroboros.Consensus.Cardano.Node
26
import Ouroboros.Consensus.Cardano.Block
27
import Ouroboros.Consensus.Cardano.ByronHFC (ByronBlockHFC)
28
import Ouroboros.Consensus.HardFork.Combinator.Embed.Unary
29
import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolClientInfo(..), ProtocolInfo(..))
30
import Ouroboros.Consensus.Node.Run (RunNode)
31
import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock)
32
import Ouroboros.Consensus.Shelley.ShelleyHFC (ShelleyBlockHFC)
33
import Ouroboros.Consensus.Util.IOLike (IOLike)
35
class (RunNode blk, IOLike m) => Protocol m blk where
36
data ProtocolInfoArgs m blk
37
protocolInfo :: ProtocolInfoArgs m blk -> ProtocolInfo m blk
39
-- | Node client support for each consensus protocol.
41
-- This is like 'Protocol' but for clients of the node, so with less onerous
42
-- requirements than to run a node.
44
class (RunNode blk) => ProtocolClient blk where
45
data ProtocolClientInfoArgs blk
46
protocolClientInfo :: ProtocolClientInfoArgs blk -> ProtocolClientInfo blk
49
-- | Run PBFT against the Byron ledger
50
instance IOLike m => Protocol m ByronBlockHFC where
51
data ProtocolInfoArgs m ByronBlockHFC = ProtocolInfoArgsByron ProtocolParamsByron
52
protocolInfo (ProtocolInfoArgsByron params) = inject $ protocolInfoByron params
54
instance IOLike m => Protocol m (CardanoBlock StandardCrypto) where
55
data ProtocolInfoArgs m (CardanoBlock StandardCrypto) = ProtocolInfoArgsCardano
57
(ProtocolParamsShelleyBased StandardShelley)
61
(ProtocolParamsTransition ByronBlock (ShelleyBlock StandardShelley))
62
(ProtocolParamsTransition (ShelleyBlock StandardShelley) (ShelleyBlock StandardAllegra))
63
(ProtocolParamsTransition (ShelleyBlock StandardAllegra) (ShelleyBlock StandardMary))
64
protocolInfo (ProtocolInfoArgsCardano
83
instance ProtocolClient ByronBlockHFC where
84
data ProtocolClientInfoArgs ByronBlockHFC =
85
ProtocolClientInfoArgsByron EpochSlots
86
protocolClientInfo (ProtocolClientInfoArgsByron epochSlots) =
87
inject $ protocolClientInfoByron epochSlots
89
instance ProtocolClient (CardanoBlock StandardCrypto) where
90
data ProtocolClientInfoArgs (CardanoBlock StandardCrypto) =
91
ProtocolClientInfoArgsCardano EpochSlots
92
protocolClientInfo (ProtocolClientInfoArgsCardano epochSlots) =
93
protocolClientInfoCardano epochSlots
95
instance IOLike m => Protocol m (ShelleyBlockHFC StandardShelley) where
96
data ProtocolInfoArgs m (ShelleyBlockHFC StandardShelley) = ProtocolInfoArgsShelley
97
(ProtocolParamsShelleyBased StandardShelley)
99
protocolInfo (ProtocolInfoArgsShelley paramsShelleyBased paramsShelley) =
100
inject $ protocolInfoShelley paramsShelleyBased paramsShelley
102
instance ProtocolClient (ShelleyBlockHFC StandardShelley) where
103
data ProtocolClientInfoArgs (ShelleyBlockHFC StandardShelley) =
104
ProtocolClientInfoArgsShelley
105
protocolClientInfo ProtocolClientInfoArgsShelley =
106
inject protocolClientInfoShelley
108
data BlockType blk where
109
ByronBlockType :: BlockType ByronBlockHFC
110
ShelleyBlockType :: BlockType (ShelleyBlockHFC StandardShelley)
111
CardanoBlockType :: BlockType (CardanoBlock StandardCrypto)
113
deriving instance Eq (BlockType blk)
114
deriving instance Show (BlockType blk)
116
data SomeNodeClientProtocol where
118
SomeNodeClientProtocol
119
:: (RunNode blk, ProtocolClient blk)
120
=> ProtocolClientInfoArgs blk
121
-> SomeNodeClientProtocol