Skip to content

Commit

Permalink
Added SomeBlockType and reflBlockType
Browse files Browse the repository at this point in the history
  • Loading branch information
bolt12 committed Jun 23, 2023
1 parent d6cd23b commit ea93da5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cardano-api/internal/Cardano/Api/Protocol.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}

module Cardano.Api.Protocol
( BlockType(..)
, SomeBlockType (..)
, reflBlockType
, Protocol(..)
, ProtocolInfoArgs(..)
, ProtocolClient(..)
Expand Down Expand Up @@ -36,6 +39,8 @@ import Ouroboros.Consensus.Shelley.Node.Praos
import Ouroboros.Consensus.Shelley.ShelleyHFC (ShelleyBlockHFC)
import Ouroboros.Consensus.Util.IOLike (IOLike)

import Type.Reflection ((:~:) (..))

class (RunNode blk, IOLike m) => Protocol m blk where
data ProtocolInfoArgs blk
protocolInfo :: ProtocolInfoArgs blk -> (ProtocolInfo blk, m [BlockForging m blk])
Expand Down Expand Up @@ -147,3 +152,14 @@ data BlockType blk where
deriving instance Eq (BlockType blk)
deriving instance Show (BlockType blk)

reflBlockType :: BlockType blk -> BlockType blk' -> Maybe (blk :~: blk')
reflBlockType ByronBlockType ByronBlockType = Just Refl
reflBlockType ShelleyBlockType ShelleyBlockType = Just Refl
reflBlockType CardanoBlockType CardanoBlockType = Just Refl
reflBlockType _ _ = Nothing


data SomeBlockType where
SomeBlockType :: BlockType blk -> SomeBlockType

deriving instance Show SomeBlockType
2 changes: 2 additions & 0 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,8 @@ module Cardano.Api (

-- ** Protocol related types
BlockType(..),
SomeBlockType (..),
reflBlockType,
Protocol(..),
ProtocolInfoArgs(..),

Expand Down

0 comments on commit ea93da5

Please sign in to comment.