-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | The instantation of the Ouroboros consensus layer used by Cardano
--   
--   The instantation of the Ouroboros consensus layer used by Cardano
@package ouroboros-consensus-cardano
@version 0.1.0.0

module Ouroboros.Consensus.Cardano.Block

-- | The eras in the Cardano blockchain.
--   
--   We parameterise over the crypto used in the post-Byron eras:
--   <tt>c</tt>.
--   
--   TODO: parameterise ByronBlock over crypto too
type CardanoEras c = '[ByronBlock, ShelleyBlock (ShelleyEra c), ShelleyBlock (AllegraEra c), ShelleyBlock (MaryEra c)]

-- | <i>The</i> Cardano block.
--   
--   Thanks to the pattern synonyms, you can treat this as a sum type with
--   constructors <a>BlockByron</a> and <a>BlockShelley</a>.
--   
--   <pre>
--   f :: CardanoBlock c -&gt; _
--   f (BlockByron   b) = _
--   f (BlockShelley s) = _
--   f (BlockAllegra a) = _
--   f (BlockMary    m) = _
--   </pre>
type CardanoBlock c = HardForkBlock (CardanoEras c)
data HardForkBlock (xs :: [Type])
pattern BlockByron :: ByronBlock -> CardanoBlock c
pattern BlockShelley :: ShelleyBlock (ShelleyEra c) -> CardanoBlock c
pattern BlockAllegra :: ShelleyBlock (AllegraEra c) -> CardanoBlock c
pattern BlockMary :: ShelleyBlock (MaryEra c) -> CardanoBlock c

-- | The Cardano header.
type CardanoHeader c = Header (CardanoBlock c)
data family Header blk
pattern HeaderByron :: Header ByronBlock -> CardanoHeader c
pattern HeaderShelley :: Header (ShelleyBlock (ShelleyEra c)) -> CardanoHeader c
pattern HeaderAllegra :: Header (ShelleyBlock (AllegraEra c)) -> CardanoHeader c
pattern HeaderMary :: Header (ShelleyBlock (MaryEra c)) -> CardanoHeader c

-- | The Cardano transaction.
type CardanoGenTx c = GenTx (CardanoBlock c)

-- | Generalized transaction
--   
--   The mempool (and, accordingly, blocks) consist of "generalized
--   transactions"; this could be "proper" transactions (transferring
--   funds) but also other kinds of things such as update proposals,
--   delegations, etc.
data family GenTx blk
pattern GenTxByron :: GenTx ByronBlock -> CardanoGenTx c
pattern GenTxShelley :: GenTx (ShelleyBlock (ShelleyEra c)) -> CardanoGenTx c
pattern GenTxAllegra :: GenTx (ShelleyBlock (AllegraEra c)) -> CardanoGenTx c
pattern GenTxMary :: GenTx (ShelleyBlock (MaryEra c)) -> CardanoGenTx c

-- | The ID of a Cardano transaction.
type CardanoGenTxId c = GenTxId (CardanoBlock c)

-- | A generalized transaction, <a>GenTx</a>, identifier.
data family TxId tx
pattern GenTxIdByron :: GenTxId ByronBlock -> CardanoGenTxId c
pattern GenTxIdShelley :: GenTxId (ShelleyBlock (ShelleyEra c)) -> CardanoGenTxId c
pattern GenTxIdAllegra :: GenTxId (ShelleyBlock (AllegraEra c)) -> CardanoGenTxId c
pattern GenTxIdMary :: GenTxId (ShelleyBlock (MaryEra c)) -> CardanoGenTxId c

-- | An error resulting from applying a <a>CardanoGenTx</a> to the ledger.
--   
--   Thanks to the pattern synonyms, you can treat this as a sum type with
--   constructors <tt>ApplyTxByronErr</tt>, <a>ApplyTxErrShelley</a>, and
--   <a>ApplyTxErrWrongEra</a>.
--   
--   <pre>
--   toText :: CardanoApplyTxErr c -&gt; Text
--   toText (ApplyTxErrByron b) = byronApplyTxErrToText b
--   toText (ApplyTxErrShelley s) = shelleyApplyTxErrToText s
--   toText (ApplyTxErrAllegra a) = allegraApplyTxErrToText a
--   toText (ApplyTxErrMary m) = maryApplyTxErrToText m
--   toText (ApplyTxErrWrongEra eraMismatch) =
--     "Transaction from the " &lt;&gt; otherEraName eraMismatch &lt;&gt;
--     " era applied to a ledger from the " &lt;&gt;
--     ledgerEraName eraMismatch &lt;&gt; " era"
--   </pre>
type CardanoApplyTxErr c = HardForkApplyTxErr (CardanoEras c)
data HardForkApplyTxErr (xs :: [Type])
pattern ApplyTxErrByron :: ApplyTxErr ByronBlock -> CardanoApplyTxErr c
pattern ApplyTxErrShelley :: ApplyTxErr (ShelleyBlock (ShelleyEra c)) -> CardanoApplyTxErr c
pattern ApplyTxErrAllegra :: ApplyTxErr (ShelleyBlock (AllegraEra c)) -> CardanoApplyTxErr c
pattern ApplyTxErrMary :: ApplyTxErr (ShelleyBlock (MaryEra c)) -> CardanoApplyTxErr c
pattern ApplyTxErrWrongEra :: EraMismatch -> CardanoApplyTxErr c

-- | An error resulting from applying a <a>CardanoBlock</a> to the ledger.
--   
--   Thanks to the pattern synonyms, you can treat this as a sum type with
--   constructors <a>LedgerErrorByron</a>, <a>LedgerErrorShelley</a>, and
--   <a>LedgerErrorWrongEra</a>.
--   
--   <pre>
--   toText :: CardanoLedgerError c -&gt; Text
--   toText (LedgerErrorByron b) = byronLedgerErrorToText b
--   toText (LedgerErrorShelley s) = shelleyLedgerErrorToText s
--   toText (LedgerErrorAllegra a) = allegraLedgerErrorToText a
--   toText (LedgerErrorMary m) = maryLedgerErrorToText m
--   toText (LedgerErrorWrongEra eraMismatch) =
--     "Block from the " &lt;&gt; otherEraName eraMismatch &lt;&gt;
--     " era applied to a ledger from the " &lt;&gt;
--     ledgerEraName eraMismatch &lt;&gt; " era"
--   </pre>
type CardanoLedgerError c = HardForkLedgerError (CardanoEras c)
data HardForkLedgerError (xs :: [Type])
pattern LedgerErrorByron :: LedgerError ByronBlock -> CardanoLedgerError c
pattern LedgerErrorShelley :: LedgerError (ShelleyBlock (ShelleyEra c)) -> CardanoLedgerError c
pattern LedgerErrorAllegra :: LedgerError (ShelleyBlock (AllegraEra c)) -> CardanoLedgerError c
pattern LedgerErrorMary :: LedgerError (ShelleyBlock (MaryEra c)) -> CardanoLedgerError c
pattern LedgerErrorWrongEra :: EraMismatch -> CardanoLedgerError c

-- | An error resulting from validating a <a>CardanoHeader</a>.
type CardanoOtherHeaderEnvelopeError c = HardForkEnvelopeErr (CardanoEras c)
data HardForkEnvelopeErr (xs :: [Type])
pattern OtherHeaderEnvelopeErrorByron :: OtherHeaderEnvelopeError ByronBlock -> CardanoOtherHeaderEnvelopeError c
pattern OtherHeaderEnvelopeErrorShelley :: OtherHeaderEnvelopeError (ShelleyBlock (ShelleyEra c)) -> CardanoOtherHeaderEnvelopeError c
pattern OtherHeaderEnvelopeErrorAllegra :: OtherHeaderEnvelopeError (ShelleyBlock (AllegraEra c)) -> CardanoOtherHeaderEnvelopeError c
pattern OtherHeaderEnvelopeErrorMary :: OtherHeaderEnvelopeError (ShelleyBlock (MaryEra c)) -> CardanoOtherHeaderEnvelopeError c
pattern OtherHeaderEnvelopeErrorWrongEra :: EraMismatch -> CardanoOtherHeaderEnvelopeError c

-- | The <a>TipInfo</a> of the Cardano chain.
type CardanoTipInfo c = OneEraTipInfo (CardanoEras c)
data OneEraTipInfo (xs :: [Type])
pattern TipInfoByron :: TipInfo ByronBlock -> CardanoTipInfo c
pattern TipInfoShelley :: TipInfo (ShelleyBlock (ShelleyEra c)) -> CardanoTipInfo c
pattern TipInfoAllegra :: TipInfo (ShelleyBlock (AllegraEra c)) -> CardanoTipInfo c
pattern TipInfoMary :: TipInfo (ShelleyBlock (MaryEra c)) -> CardanoTipInfo c

-- | The <a>Query</a> of Cardano chain.
type CardanoQuery c = Query (CardanoBlock c)

-- | Different queries supported by the ledger, indexed by the result type.
data family Query blk :: Type -> Type

-- | Byron-specific query that can only be answered when the ledger is in
--   the Byron era.
pattern QueryIfCurrentByron :: () => CardanoQueryResult c result ~ a => Query ByronBlock result -> CardanoQuery c a

-- | Shelley-specific query that can only be answered when the ledger is in
--   the Shelley era.
pattern QueryIfCurrentShelley :: () => CardanoQueryResult c result ~ a => Query (ShelleyBlock (ShelleyEra c)) result -> CardanoQuery c a

-- | Allegra-specific query that can only be answered when the ledger is in
--   the Allegra era.
pattern QueryIfCurrentAllegra :: () => CardanoQueryResult c result ~ a => Query (ShelleyBlock (AllegraEra c)) result -> CardanoQuery c a

-- | Mary-specific query that can only be answered when the ledger is in
--   the Mary era.
pattern QueryIfCurrentMary :: () => CardanoQueryResult c result ~ a => Query (ShelleyBlock (MaryEra c)) result -> CardanoQuery c a

-- | Query about the Byron era that can be answered anytime, i.e.,
--   independent from where the tip of the ledger is.
--   
--   For example, to ask for the start of the Byron era (whether the tip of
--   the ledger is in the Byron, Shelley, ... era), use:
--   
--   <pre>
--   QueryAnytimeByron EraStart
--   </pre>
pattern QueryAnytimeByron :: QueryAnytime result -> CardanoQuery c result

-- | Query about the Shelley era that can be answered anytime, i.e.,
--   independent from where the tip of the ledger is.
--   
--   For example, to ask for the start of the Shelley era (whether the tip
--   of the ledger is in the Byron, Shelley, ... era), use:
--   
--   <pre>
--   QueryAnytimeShelley EraStart
--   </pre>
pattern QueryAnytimeShelley :: QueryAnytime result -> CardanoQuery c result

-- | Query about the Allegra era that can be answered anytime, i.e.,
--   independent from where the tip of the ledger is.
--   
--   For example, to ask for the start of the Allegra era (whether the tip
--   of the ledger is in the Byron, Shelley, ... era), use:
--   
--   <pre>
--   QueryAnytimeAllegra EraStart
--   </pre>
pattern QueryAnytimeAllegra :: QueryAnytime result -> CardanoQuery c result

-- | Query about the Mary era that can be answered anytime, i.e.,
--   independent from where the tip of the ledger is.
--   
--   For example, to ask for the start of the Mary era (whether the tip of
--   the ledger is in the Byron, Shelley, ... era), use:
--   
--   <pre>
--   QueryAnytimeMary EraStart
--   </pre>
pattern QueryAnytimeMary :: QueryAnytime result -> CardanoQuery c result

-- | The result of a <a>CardanoQuery</a>
--   
--   Thanks to the pattern synonyms, you can treat this as a sum type with
--   constructors <a>QueryResultSuccess</a> and
--   <a>QueryResultEraMismatch</a>.
type CardanoQueryResult c = HardForkQueryResult (CardanoEras c)

-- | The <a>Either</a> type represents values with two possibilities: a
--   value of type <tt><a>Either</a> a b</tt> is either <tt><a>Left</a>
--   a</tt> or <tt><a>Right</a> b</tt>.
--   
--   The <a>Either</a> type is sometimes used to represent a value which is
--   either correct or an error; by convention, the <a>Left</a> constructor
--   is used to hold an error value and the <a>Right</a> constructor is
--   used to hold a correct value (mnemonic: "right" also means "correct").
--   
--   <h4><b>Examples</b></h4>
--   
--   The type <tt><a>Either</a> <a>String</a> <a>Int</a></tt> is the type
--   of values which can be either a <a>String</a> or an <a>Int</a>. The
--   <a>Left</a> constructor can be used only on <a>String</a>s, and the
--   <a>Right</a> constructor can be used only on <a>Int</a>s:
--   
--   <pre>
--   &gt;&gt;&gt; let s = Left "foo" :: Either String Int
--   
--   &gt;&gt;&gt; s
--   Left "foo"
--   
--   &gt;&gt;&gt; let n = Right 3 :: Either String Int
--   
--   &gt;&gt;&gt; n
--   Right 3
--   
--   &gt;&gt;&gt; :type s
--   s :: Either String Int
--   
--   &gt;&gt;&gt; :type n
--   n :: Either String Int
--   </pre>
--   
--   The <a>fmap</a> from our <a>Functor</a> instance will ignore
--   <a>Left</a> values, but will apply the supplied function to values
--   contained in a <a>Right</a>:
--   
--   <pre>
--   &gt;&gt;&gt; let s = Left "foo" :: Either String Int
--   
--   &gt;&gt;&gt; let n = Right 3 :: Either String Int
--   
--   &gt;&gt;&gt; fmap (*2) s
--   Left "foo"
--   
--   &gt;&gt;&gt; fmap (*2) n
--   Right 6
--   </pre>
--   
--   The <a>Monad</a> instance for <a>Either</a> allows us to chain
--   together multiple actions which may fail, and fail overall if any of
--   the individual steps failed. First we'll write a function that can
--   either parse an <a>Int</a> from a <a>Char</a>, or fail.
--   
--   <pre>
--   &gt;&gt;&gt; import Data.Char ( digitToInt, isDigit )
--   
--   &gt;&gt;&gt; :{
--       let parseEither :: Char -&gt; Either String Int
--           parseEither c
--             | isDigit c = Right (digitToInt c)
--             | otherwise = Left "parse error"
--   
--   &gt;&gt;&gt; :}
--   </pre>
--   
--   The following should work, since both <tt>'1'</tt> and <tt>'2'</tt>
--   can be parsed as <a>Int</a>s.
--   
--   <pre>
--   &gt;&gt;&gt; :{
--       let parseMultiple :: Either String Int
--           parseMultiple = do
--             x &lt;- parseEither '1'
--             y &lt;- parseEither '2'
--             return (x + y)
--   
--   &gt;&gt;&gt; :}
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; parseMultiple
--   Right 3
--   </pre>
--   
--   But the following should fail overall, since the first operation where
--   we attempt to parse <tt>'m'</tt> as an <a>Int</a> will fail:
--   
--   <pre>
--   &gt;&gt;&gt; :{
--       let parseMultiple :: Either String Int
--           parseMultiple = do
--             x &lt;- parseEither 'm'
--             y &lt;- parseEither '2'
--             return (x + y)
--   
--   &gt;&gt;&gt; :}
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; parseMultiple
--   Left "parse error"
--   </pre>
data Either a b
pattern QueryResultSuccess :: result -> CardanoQueryResult c result

-- | A query from a different era than the ledger's era was sent.
pattern QueryResultEraMismatch :: EraMismatch -> CardanoQueryResult c result

-- | The <a>CodecConfig</a> for <a>CardanoBlock</a>.
--   
--   Thanks to the pattern synonyms, you can treat this as the product of
--   the Byron, Shelley, ... <a>CodecConfig</a>s.
type CardanoCodecConfig c = CodecConfig (CardanoBlock c)

-- | Static configuration required for serialisation and deserialisation of
--   types pertaining to this type of block.
--   
--   Data family instead of type family to get better type inference.
data family CodecConfig blk
pattern CardanoCodecConfig :: CodecConfig ByronBlock -> CodecConfig (ShelleyBlock (ShelleyEra c)) -> CodecConfig (ShelleyBlock (AllegraEra c)) -> CodecConfig (ShelleyBlock (MaryEra c)) -> CardanoCodecConfig c

-- | The <a>BlockConfig</a> for <a>CardanoBlock</a>.
--   
--   Thanks to the pattern synonyms, you can treat this as the product of
--   the Byron, Shelley, ... <a>BlockConfig</a>s.
type CardanoBlockConfig c = BlockConfig (CardanoBlock c)

-- | Static configuration required to work with this type of blocks
data family BlockConfig blk
pattern CardanoBlockConfig :: BlockConfig ByronBlock -> BlockConfig (ShelleyBlock (ShelleyEra c)) -> BlockConfig (ShelleyBlock (AllegraEra c)) -> BlockConfig (ShelleyBlock (MaryEra c)) -> CardanoBlockConfig c

-- | The <a>StorageConfig</a> for <a>CardanoBlock</a>.
--   
--   Thanks to the pattern synonyms, you can treat this as the product of
--   the Byron, Shelley, ... <a>StorageConfig</a>s.
type CardanoStorageConfig c = StorageConfig (CardanoBlock c)

-- | Config needed for the <a>NodeInitStorage</a> class. Defined here to
--   avoid circular dependencies.
data family StorageConfig blk
pattern CardanoStorageConfig :: StorageConfig ByronBlock -> StorageConfig (ShelleyBlock (ShelleyEra c)) -> StorageConfig (ShelleyBlock (AllegraEra c)) -> StorageConfig (ShelleyBlock (MaryEra c)) -> CardanoStorageConfig c

-- | The <a>ConsensusConfig</a> for <a>CardanoBlock</a>.
--   
--   Thanks to the pattern synonyms, you can treat this as the product of
--   the Byron, Shelley, ... <a>PartialConsensusConfig</a>s.
--   
--   NOTE: not <a>ConsensusConfig</a>, but <a>PartialConsensusConfig</a>.
type CardanoConsensusConfig c = ConsensusConfig (HardForkProtocol (CardanoEras c))

-- | Static configuration required to run the consensus protocol
--   
--   Every method in the <a>ConsensusProtocol</a> class takes the consensus
--   configuration as a parameter, so having this as a data family rather
--   than a type family resolves most ambiguity.
--   
--   Defined out of the class so that protocols can define this type
--   without having to define the entire protocol at the same time (or
--   indeed in the same module).
data family ConsensusConfig p
pattern CardanoConsensusConfig :: PartialConsensusConfig (BlockProtocol ByronBlock) -> PartialConsensusConfig (BlockProtocol (ShelleyBlock (ShelleyEra c))) -> PartialConsensusConfig (BlockProtocol (ShelleyBlock (AllegraEra c))) -> PartialConsensusConfig (BlockProtocol (ShelleyBlock (MaryEra c))) -> CardanoConsensusConfig c

-- | The <tt>LedgerConfig</tt> for <a>CardanoBlock</a>.
--   
--   Thanks to the pattern synonyms, you can treat this as the product of
--   the Byron, Shelley, ... <a>PartialLedgerConfig</a>s.
--   
--   NOTE: not <tt>LedgerConfig</tt>, but <a>PartialLedgerConfig</a>.
type CardanoLedgerConfig c = HardForkLedgerConfig (CardanoEras c)
data HardForkLedgerConfig (xs :: [Type])
pattern CardanoLedgerConfig :: PartialLedgerConfig ByronBlock -> PartialLedgerConfig (ShelleyBlock (ShelleyEra c)) -> PartialLedgerConfig (ShelleyBlock (AllegraEra c)) -> PartialLedgerConfig (ShelleyBlock (MaryEra c)) -> CardanoLedgerConfig c

-- | The <a>LedgerState</a> for <a>CardanoBlock</a>.
--   
--   NOTE: the <a>CardanoLedgerState</a> contains more than just the
--   current era's <a>LedgerState</a>. We don't give access to those
--   internal details through the pattern synonyms. This is also the reason
--   the pattern synonyms are not bidirectional.
type CardanoLedgerState c = LedgerState (CardanoBlock c)

-- | Ledger state associated with a block
data family LedgerState blk
pattern LedgerStateByron :: LedgerState ByronBlock -> CardanoLedgerState c
pattern LedgerStateShelley :: LedgerState (ShelleyBlock (ShelleyEra c)) -> CardanoLedgerState c
pattern LedgerStateAllegra :: LedgerState (ShelleyBlock (AllegraEra c)) -> CardanoLedgerState c
pattern LedgerStateMary :: LedgerState (ShelleyBlock (MaryEra c)) -> CardanoLedgerState c

-- | The <a>ChainDepState</a> for <a>CardanoBlock</a>.
--   
--   NOTE: the <a>CardanoChainDepState</a> contains more than just the
--   current era's <a>ChainDepState</a>. We don't give access to those
--   internal details through the pattern synonyms. This is also the reason
--   the pattern synonyms are not bidirectional.
type CardanoChainDepState c = HardForkChainDepState (CardanoEras c)

-- | Generic hard fork state
--   
--   This is used both for the consensus state and the ledger state.
data HardForkState (f :: Type -> Type) (xs :: [Type])
pattern ChainDepStateByron :: ChainDepState (BlockProtocol ByronBlock) -> CardanoChainDepState c
pattern ChainDepStateShelley :: ChainDepState (BlockProtocol (ShelleyBlock (ShelleyEra c))) -> CardanoChainDepState c
pattern ChainDepStateAllegra :: ChainDepState (BlockProtocol (ShelleyBlock (AllegraEra c))) -> CardanoChainDepState c
pattern ChainDepStateMary :: ChainDepState (BlockProtocol (ShelleyBlock (MaryEra c))) -> CardanoChainDepState c

-- | Extra info for errors caused by applying a block, header, transaction,
--   or query from one era to a ledger from a different era.
data EraMismatch
EraMismatch :: !Text -> !Text -> EraMismatch

-- | Name of the era of the ledger (<a>Byron</a> or <a>Shelley</a>).
[ledgerEraName] :: EraMismatch -> !Text

-- | Era of the block, header, transaction, or query.
[otherEraName] :: EraMismatch -> !Text

module Ouroboros.Consensus.Cardano.CanHardFork

-- | The trigger condition that will cause the hard fork transition.
data TriggerHardFork

-- | Trigger the transition when the on-chain protocol major version (from
--   the ledger state) reaches this number.
TriggerHardForkAtVersion :: !Word16 -> TriggerHardFork

-- | For testing only, trigger the transition at a specific hard-coded
--   epoch, irrespective of the ledger state.
TriggerHardForkAtEpoch :: !EpochNo -> TriggerHardFork

-- | Never trigger a hard fork
TriggerHardForkNever :: TriggerHardFork

-- | When Byron is part of the hard-fork combinator, we use the partial
--   ledger config. Standalone Byron uses the regular ledger config. This
--   means that the partial ledger config is the perfect place to store the
--   trigger condition for the hard fork to Shelley, as we don't have to
--   modify the ledger config for standalone Byron.
data ByronPartialLedgerConfig
ByronPartialLedgerConfig :: !LedgerConfig ByronBlock -> !TriggerHardFork -> ByronPartialLedgerConfig
[byronLedgerConfig] :: ByronPartialLedgerConfig -> !LedgerConfig ByronBlock
[byronTriggerHardFork] :: ByronPartialLedgerConfig -> !TriggerHardFork
data ShelleyPartialLedgerConfig era
ShelleyPartialLedgerConfig :: !ShelleyLedgerConfig era -> !TriggerHardFork -> ShelleyPartialLedgerConfig era

-- | We cache the non-partial ledger config containing a dummy
--   <a>EpochInfo</a> that needs to be replaced with the correct one.
--   
--   We do this to avoid recomputing the ledger config each time
--   <a>completeLedgerConfig</a> is called, as <a>mkShelleyLedgerConfig</a>
--   does some rather expensive computations that shouldn't be repeated too
--   often (e.g., <tt>sgActiveSlotCoeff</tt>).
[shelleyLedgerConfig] :: ShelleyPartialLedgerConfig era -> !ShelleyLedgerConfig era
[shelleyTriggerHardFork] :: ShelleyPartialLedgerConfig era -> !TriggerHardFork
type CardanoHardForkConstraints c = (PraosCrypto c, ShelleyBasedEra (ShelleyEra c), ShelleyBasedEra (AllegraEra c), ShelleyBasedEra (MaryEra c), HASH c ~ Blake2b_256, ADDRHASH c ~ Blake2b_224, DSIGN c ~ Ed25519DSIGN)
instance NoThunks.Class.NoThunks Ouroboros.Consensus.Cardano.CanHardFork.TriggerHardFork
instance GHC.Generics.Generic Ouroboros.Consensus.Cardano.CanHardFork.TriggerHardFork
instance GHC.Show.Show Ouroboros.Consensus.Cardano.CanHardFork.TriggerHardFork
instance NoThunks.Class.NoThunks Ouroboros.Consensus.Cardano.CanHardFork.ByronPartialLedgerConfig
instance GHC.Generics.Generic Ouroboros.Consensus.Cardano.CanHardFork.ByronPartialLedgerConfig
instance Shelley.Spec.Ledger.API.ShelleyBasedEra era => NoThunks.Class.NoThunks (Ouroboros.Consensus.Cardano.CanHardFork.ShelleyPartialLedgerConfig era)
instance GHC.Generics.Generic (Ouroboros.Consensus.Cardano.CanHardFork.ShelleyPartialLedgerConfig era)
instance Ouroboros.Consensus.Cardano.CanHardFork.CardanoHardForkConstraints c => Ouroboros.Consensus.HardFork.Combinator.Abstract.CanHardFork.CanHardFork (Ouroboros.Consensus.Cardano.Block.CardanoEras c)
instance Shelley.Spec.Ledger.API.ShelleyBasedEra era => Ouroboros.Consensus.HardFork.Combinator.Abstract.SingleEraBlock.SingleEraBlock (Ouroboros.Consensus.Shelley.Ledger.Block.ShelleyBlock era)
instance Shelley.Spec.Ledger.API.ShelleyBasedEra era => Ouroboros.Consensus.HardFork.Combinator.PartialConfig.HasPartialLedgerConfig (Ouroboros.Consensus.Shelley.Ledger.Block.ShelleyBlock era)
instance Ouroboros.Consensus.HardFork.Combinator.Abstract.SingleEraBlock.SingleEraBlock Ouroboros.Consensus.Byron.Ledger.Block.ByronBlock
instance Ouroboros.Consensus.HardFork.Combinator.PartialConfig.HasPartialLedgerConfig Ouroboros.Consensus.Byron.Ledger.Block.ByronBlock
instance Ouroboros.Consensus.Protocol.PBFT.Crypto.PBftCrypto bc => Ouroboros.Consensus.HardFork.Combinator.PartialConfig.HasPartialConsensusConfig (Ouroboros.Consensus.Protocol.PBFT.PBft bc)
instance Shelley.Spec.Ledger.API.Protocol.PraosCrypto c => Ouroboros.Consensus.HardFork.Combinator.PartialConfig.HasPartialConsensusConfig (Ouroboros.Consensus.Shelley.Protocol.TPraos c)
instance (Shelley.Spec.Ledger.API.ShelleyBasedEra era, Shelley.Spec.Ledger.API.ShelleyBasedEra (Cardano.Ledger.Era.PreviousEra era), Ouroboros.Consensus.Shelley.Eras.EraCrypto (Cardano.Ledger.Era.PreviousEra era) GHC.Types.~ Ouroboros.Consensus.Shelley.Eras.EraCrypto era) => Cardano.Ledger.Era.TranslateEra era Ouroboros.Consensus.Shelley.Ledger.Ledger.ShelleyTip
instance (Shelley.Spec.Ledger.API.ShelleyBasedEra era, Cardano.Ledger.Era.TranslateEra era Ouroboros.Consensus.Shelley.Ledger.Ledger.ShelleyTip, Cardano.Ledger.Era.TranslateEra era Shelley.Spec.Ledger.LedgerState.NewEpochState, Cardano.Ledger.Era.TranslationError era Shelley.Spec.Ledger.LedgerState.NewEpochState GHC.Types.~ Data.Void.Void) => Cardano.Ledger.Era.TranslateEra era (Ouroboros.Consensus.Ledger.Basics.LedgerState Data.SOP.BasicFunctors.:.: Ouroboros.Consensus.Shelley.Ledger.Block.ShelleyBlock)
instance (Shelley.Spec.Ledger.API.ShelleyBasedEra era, Cardano.Ledger.Era.TranslateEra era Shelley.Spec.Ledger.Tx.Tx) => Cardano.Ledger.Era.TranslateEra era (Ouroboros.Consensus.Ledger.SupportsMempool.GenTx Data.SOP.BasicFunctors.:.: Ouroboros.Consensus.Shelley.Ledger.Block.ShelleyBlock)

module Ouroboros.Consensus.Cardano.Condense
instance Ouroboros.Consensus.HardFork.Combinator.Condense.CondenseConstraints Ouroboros.Consensus.Byron.Ledger.Block.ByronBlock
instance Shelley.Spec.Ledger.API.ShelleyBasedEra era => Ouroboros.Consensus.HardFork.Combinator.Condense.CondenseConstraints (Ouroboros.Consensus.Shelley.Ledger.Block.ShelleyBlock era)
instance Ouroboros.Consensus.Cardano.CanHardFork.CardanoHardForkConstraints c => Ouroboros.Consensus.HardFork.Combinator.Condense.CondenseConstraints (Ouroboros.Consensus.Cardano.Block.CardanoBlock c)

module Ouroboros.Consensus.Cardano.Node
protocolInfoCardano :: forall c m. (IOLike m, CardanoHardForkConstraints c) => ProtocolParamsByron -> ProtocolParamsShelley c Maybe -> ProtocolParamsAllegra c Maybe -> ProtocolParamsMary c Maybe -> ProtocolParamsTransition ByronBlock (ShelleyBlock (ShelleyEra c)) -> ProtocolParamsTransition (ShelleyBlock (ShelleyEra c)) (ShelleyBlock (AllegraEra c)) -> ProtocolParamsTransition (ShelleyBlock (AllegraEra c)) (ShelleyBlock (MaryEra c)) -> ProtocolInfo m (CardanoBlock c)

-- | Parameters needed to transition between two eras.
--   
--   The two eras are phantom type parameters of this type to avoid mixing
--   up multiple <a>ProtocolParamsTransition</a>s
data ProtocolParamsTransition eraFrom eraTo
ProtocolParamsTransition :: Maybe EpochNo -> TriggerHardFork -> ProtocolParamsTransition eraFrom eraTo

-- | Lower bound on first epoch of <tt>eraTo</tt>
--   
--   Setting this to <tt>Just</tt> when a true lower bound is known may
--   particularly improve performance of bulk syncing. For example, for the
--   transition from Byron to Shelley, <tt>Just 208</tt> would be sound for
--   the Cardano mainnet, since we know now that the Shelley era began in
--   epoch 208.
--   
--   The <tt>Nothing</tt> case is useful for test and possible alternative
--   nets.
[transitionLowerBound] :: ProtocolParamsTransition eraFrom eraTo -> Maybe EpochNo
[transitionTrigger] :: ProtocolParamsTransition eraFrom eraTo -> TriggerHardFork

-- | Parameters needed to run Allegra
data ProtocolParamsAllegra c (f :: Type -> Type)
ProtocolParamsAllegra :: ProtVer -> f (TPraosLeaderCredentials c) -> ProtocolParamsAllegra c (f :: Type -> Type)
[$sel:allegraProtVer:ProtocolParamsAllegra] :: ProtocolParamsAllegra c (f :: Type -> Type) -> ProtVer
[$sel:allegraLeaderCredentials:ProtocolParamsAllegra] :: ProtocolParamsAllegra c (f :: Type -> Type) -> f (TPraosLeaderCredentials c)

-- | Parameters needed to run Mary
data ProtocolParamsMary c (f :: Type -> Type)
ProtocolParamsMary :: ProtVer -> f (TPraosLeaderCredentials c) -> ProtocolParamsMary c (f :: Type -> Type)
[$sel:maryProtVer:ProtocolParamsMary] :: ProtocolParamsMary c (f :: Type -> Type) -> ProtVer
[$sel:maryLeaderCredentials:ProtocolParamsMary] :: ProtocolParamsMary c (f :: Type -> Type) -> f (TPraosLeaderCredentials c)
protocolClientInfoCardano :: forall c. EpochSlots -> ProtocolClientInfo (CardanoBlock c)
type CardanoHardForkConstraints c = (PraosCrypto c, ShelleyBasedEra (ShelleyEra c), ShelleyBasedEra (AllegraEra c), ShelleyBasedEra (MaryEra c), HASH c ~ Blake2b_256, ADDRHASH c ~ Blake2b_224, DSIGN c ~ Ed25519DSIGN)

-- | The maximum major protocol version.
--   
--   Must be at least the current major protocol version. For Cardano
--   mainnet, the Shelley era has major protocol verison <b>2</b>.
newtype MaxMajorProtVer
MaxMajorProtVer :: Natural -> MaxMajorProtVer
[getMaxMajorProtVer] :: MaxMajorProtVer -> Natural

-- | The trigger condition that will cause the hard fork transition.
data TriggerHardFork

-- | Trigger the transition when the on-chain protocol major version (from
--   the ledger state) reaches this number.
TriggerHardForkAtVersion :: !Word16 -> TriggerHardFork

-- | For testing only, trigger the transition at a specific hard-coded
--   epoch, irrespective of the ledger state.
TriggerHardForkAtEpoch :: !EpochNo -> TriggerHardFork

-- | Never trigger a hard fork
TriggerHardForkNever :: TriggerHardFork

-- | We support only Byron V1 with the hard fork disabled, as no other
--   versions have been released before the hard fork
pattern CardanoNodeToNodeVersion1 :: BlockNodeToNodeVersion (CardanoBlock c)

-- | The hard fork enabled with the latest Byron version and the Shelley
--   era enabled.
pattern CardanoNodeToNodeVersion2 :: BlockNodeToNodeVersion (CardanoBlock c)

-- | The hard fork enabled with the latest Byron version, the Shelley and
--   Allegra eras enabled.
pattern CardanoNodeToNodeVersion3 :: BlockNodeToNodeVersion (CardanoBlock c)

-- | The hard fork enabled with the latest Byron version, the Shelley,
--   Allegra, and Mary eras enabled.
pattern CardanoNodeToNodeVersion4 :: BlockNodeToNodeVersion (CardanoBlock c)

-- | We support the sole Byron version with the hard fork disabled.
pattern CardanoNodeToClientVersion1 :: BlockNodeToClientVersion (CardanoBlock c)

-- | The hard fork enabled and the Shelley era enabled.
pattern CardanoNodeToClientVersion2 :: BlockNodeToClientVersion (CardanoBlock c)

-- | The hard fork enabled and the Shelley era enabled, but using
--   <a>ShelleyNodeToClientVersion2</a> and
--   <a>HardForkSpecificNodeToClientVersion2</a>.
pattern CardanoNodeToClientVersion3 :: BlockNodeToClientVersion (CardanoBlock c)

-- | The hard fork enabled, and the Shelley and Allegra eras enabled.
--   
--   We don't bother with <a>ShelleyNodeToClientVersion1</a> and
--   <a>HardForkSpecificNodeToClientVersion1</a>.
pattern CardanoNodeToClientVersion4 :: BlockNodeToClientVersion (CardanoBlock c)

-- | The hard fork enabled, and the Shelley, Allegra, and Mary eras
--   enabled.
--   
--   We don't bother with <a>ShelleyNodeToClientVersion1</a>.
pattern CardanoNodeToClientVersion5 :: BlockNodeToClientVersion (CardanoBlock c)
instance Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common.SerialiseConstraintsHFC Ouroboros.Consensus.Byron.Ledger.Block.ByronBlock
instance Shelley.Spec.Ledger.API.ShelleyBasedEra era => Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common.SerialiseConstraintsHFC (Ouroboros.Consensus.Shelley.Ledger.Block.ShelleyBlock era)
instance Ouroboros.Consensus.Cardano.CanHardFork.CardanoHardForkConstraints c => Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common.SerialiseHFC (Ouroboros.Consensus.Cardano.Block.CardanoEras c)
instance Ouroboros.Consensus.Cardano.CanHardFork.CardanoHardForkConstraints c => Ouroboros.Consensus.Node.NetworkProtocolVersion.SupportedNetworkProtocolVersion (Ouroboros.Consensus.Cardano.Block.CardanoBlock c)

module Ouroboros.Consensus.Cardano.ByronHFC

-- | Byron as the single era in the hard fork combinator
type ByronBlockHFC = HardForkBlock '[ByronBlock]
instance Ouroboros.Consensus.Node.NetworkProtocolVersion.SupportedNetworkProtocolVersion Ouroboros.Consensus.Cardano.ByronHFC.ByronBlockHFC
instance Ouroboros.Consensus.HardFork.Combinator.Abstract.NoHardForks.NoHardForks Ouroboros.Consensus.Byron.Ledger.Block.ByronBlock
instance Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common.SerialiseHFC '[Ouroboros.Consensus.Byron.Ledger.Block.ByronBlock]

module Ouroboros.Consensus.Cardano.ShelleyHFC

-- | Shelley as the single era in the hard fork combinator
type ShelleyBlockHFC era = HardForkBlock '[ShelleyBlock era]
instance Shelley.Spec.Ledger.API.ShelleyBasedEra era => Ouroboros.Consensus.Node.NetworkProtocolVersion.SupportedNetworkProtocolVersion (Ouroboros.Consensus.Cardano.ShelleyHFC.ShelleyBlockHFC era)
instance Shelley.Spec.Ledger.API.ShelleyBasedEra era => Ouroboros.Consensus.HardFork.Combinator.Abstract.NoHardForks.NoHardForks (Ouroboros.Consensus.Shelley.Ledger.Block.ShelleyBlock era)
instance Shelley.Spec.Ledger.API.ShelleyBasedEra era => Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common.SerialiseHFC '[Ouroboros.Consensus.Shelley.Ledger.Block.ShelleyBlock era]

module Ouroboros.Consensus.Cardano

-- | <i>The</i> Cardano block.
--   
--   Thanks to the pattern synonyms, you can treat this as a sum type with
--   constructors <a>BlockByron</a> and <a>BlockShelley</a>.
--   
--   <pre>
--   f :: CardanoBlock c -&gt; _
--   f (BlockByron   b) = _
--   f (BlockShelley s) = _
--   f (BlockAllegra a) = _
--   f (BlockMary    m) = _
--   </pre>
type CardanoBlock c = HardForkBlock (CardanoEras c)
type ProtocolByron = HardForkProtocol '[ByronBlock]
type ProtocolShelley = HardForkProtocol '[ShelleyBlock StandardShelley]
type ProtocolCardano = HardForkProtocol '[ByronBlock, ShelleyBlock StandardShelley, ShelleyBlock StandardAllegra, ShelleyBlock StandardMary]

-- | Parameters needed to run Byron
data ProtocolParamsByron
ProtocolParamsByron :: Config -> Maybe PBftSignatureThreshold -> ProtocolVersion -> SoftwareVersion -> Maybe ByronLeaderCredentials -> ProtocolParamsByron
[$sel:byronGenesis:ProtocolParamsByron] :: ProtocolParamsByron -> Config
[$sel:byronPbftSignatureThreshold:ProtocolParamsByron] :: ProtocolParamsByron -> Maybe PBftSignatureThreshold
[$sel:byronProtocolVersion:ProtocolParamsByron] :: ProtocolParamsByron -> ProtocolVersion
[$sel:byronSoftwareVersion:ProtocolParamsByron] :: ProtocolParamsByron -> SoftwareVersion
[$sel:byronLeaderCredentials:ProtocolParamsByron] :: ProtocolParamsByron -> Maybe ByronLeaderCredentials

-- | Parameters needed to run Shelley
data ProtocolParamsShelley c (f :: Type -> Type)
ProtocolParamsShelley :: ShelleyGenesis (ShelleyEra c) -> Nonce -> ProtVer -> f (TPraosLeaderCredentials c) -> ProtocolParamsShelley c (f :: Type -> Type)
[$sel:shelleyGenesis:ProtocolParamsShelley] :: ProtocolParamsShelley c (f :: Type -> Type) -> ShelleyGenesis (ShelleyEra c)

-- | The initial nonce, typically derived from the hash of Genesis config
--   JSON file.
--   
--   WARNING: chains using different values of this parameter will be
--   mutually incompatible.
[$sel:shelleyInitialNonce:ProtocolParamsShelley] :: ProtocolParamsShelley c (f :: Type -> Type) -> Nonce
[$sel:shelleyProtVer:ProtocolParamsShelley] :: ProtocolParamsShelley c (f :: Type -> Type) -> ProtVer
[$sel:shelleyLeaderCredentials:ProtocolParamsShelley] :: ProtocolParamsShelley c (f :: Type -> Type) -> f (TPraosLeaderCredentials c)

-- | Parameters needed to run Allegra
data ProtocolParamsAllegra c (f :: Type -> Type)
ProtocolParamsAllegra :: ProtVer -> f (TPraosLeaderCredentials c) -> ProtocolParamsAllegra c (f :: Type -> Type)
[$sel:allegraProtVer:ProtocolParamsAllegra] :: ProtocolParamsAllegra c (f :: Type -> Type) -> ProtVer
[$sel:allegraLeaderCredentials:ProtocolParamsAllegra] :: ProtocolParamsAllegra c (f :: Type -> Type) -> f (TPraosLeaderCredentials c)

-- | Parameters needed to run Mary
data ProtocolParamsMary c (f :: Type -> Type)
ProtocolParamsMary :: ProtVer -> f (TPraosLeaderCredentials c) -> ProtocolParamsMary c (f :: Type -> Type)
[$sel:maryProtVer:ProtocolParamsMary] :: ProtocolParamsMary c (f :: Type -> Type) -> ProtVer
[$sel:maryLeaderCredentials:ProtocolParamsMary] :: ProtocolParamsMary c (f :: Type -> Type) -> f (TPraosLeaderCredentials c)

-- | Parameters needed to transition between two eras.
--   
--   The two eras are phantom type parameters of this type to avoid mixing
--   up multiple <a>ProtocolParamsTransition</a>s
data ProtocolParamsTransition eraFrom eraTo
ProtocolParamsTransition :: Maybe EpochNo -> TriggerHardFork -> ProtocolParamsTransition eraFrom eraTo

-- | Lower bound on first epoch of <tt>eraTo</tt>
--   
--   Setting this to <tt>Just</tt> when a true lower bound is known may
--   particularly improve performance of bulk syncing. For example, for the
--   transition from Byron to Shelley, <tt>Just 208</tt> would be sound for
--   the Cardano mainnet, since we know now that the Shelley era began in
--   epoch 208.
--   
--   The <tt>Nothing</tt> case is useful for test and possible alternative
--   nets.
[transitionLowerBound] :: ProtocolParamsTransition eraFrom eraTo -> Maybe EpochNo
[transitionTrigger] :: ProtocolParamsTransition eraFrom eraTo -> TriggerHardFork

-- | Consensus protocol to use
data Protocol (m :: Type -> Type) blk p

-- | Run PBFT against the real Byron ledger
[ProtocolByron] :: ProtocolParamsByron -> Protocol m ByronBlockHFC ProtocolByron

-- | Run TPraos against the real Shelley ledger
[ProtocolShelley] :: ProtocolParamsShelley StandardCrypto [] -> Protocol m (ShelleyBlockHFC StandardShelley) ProtocolShelley

-- | Run the protocols of <i>the</i> Cardano block
[ProtocolCardano] :: ProtocolParamsByron -> ProtocolParamsShelley StandardCrypto Maybe -> ProtocolParamsAllegra StandardCrypto Maybe -> ProtocolParamsMary StandardCrypto Maybe -> ProtocolParamsTransition ByronBlock (ShelleyBlock StandardShelley) -> ProtocolParamsTransition (ShelleyBlock StandardShelley) (ShelleyBlock StandardAllegra) -> ProtocolParamsTransition (ShelleyBlock StandardAllegra) (ShelleyBlock StandardMary) -> Protocol m (CardanoBlock StandardCrypto) ProtocolCardano
verifyProtocol :: Protocol m blk p -> p :~: BlockProtocol blk

-- | Data required to run the selected protocol
protocolInfo :: forall m blk p. IOLike m => Protocol m blk p -> ProtocolInfo m blk
runProtocol :: Protocol m blk p -> Dict (RunNode blk)

-- | Node client support for each consensus protocol.
--   
--   This is like <a>Protocol</a> but for clients of the node, so with less
--   onerous requirements than to run a node.
data ProtocolClient blk p
[ProtocolClientByron] :: EpochSlots -> ProtocolClient ByronBlockHFC ProtocolByron
[ProtocolClientShelley] :: ProtocolClient (ShelleyBlockHFC StandardShelley) ProtocolShelley
[ProtocolClientCardano] :: EpochSlots -> ProtocolClient (CardanoBlock StandardCrypto) ProtocolCardano

-- | Data required by clients of a node running the specified protocol.
protocolClientInfo :: ProtocolClient blk p -> ProtocolClientInfo blk

-- | Sanity check that we have the right class instances available
runProtocolClient :: ProtocolClient blk p -> Dict (RunNode blk)

-- | Sanity check that we have the right type combinations
verifyProtocolClient :: ProtocolClient blk p -> p :~: BlockProtocol blk
