{-# LANGUAGE EmptyDataDeriving #-}

-- TODO DUPLICATE? -- as-if adapted? from: cardano-node/src/Cardano/Node/Protocol/Conway.hs

module Cardano.Node.Protocol.Conway (
    ConwayProtocolInstantiationError
    -- * Reusable parts
  , readGenesis
  , validateGenesis
  ) where

import qualified Cardano.Ledger.Conway.Genesis as Conway
import qualified Cardano.Ledger.Crypto as Crypto
import           Cardano.Node.Protocol.Shelley (GenesisReadError,
                     readGenesisAny)
import           Cardano.Node.Types
import           Cardano.Prelude

--
-- Conway genesis
--

readGenesis :: Crypto.Crypto c
            => GenesisFile
            -> Maybe GenesisHash
            -> ExceptT GenesisReadError IO
                       (Conway.ConwayGenesis c, GenesisHash)
readGenesis :: forall c.
Crypto c =>
GenesisFile
-> Maybe GenesisHash
-> ExceptT GenesisReadError IO (ConwayGenesis c, GenesisHash)
readGenesis = GenesisFile
-> Maybe GenesisHash
-> ExceptT GenesisReadError IO (ConwayGenesis c, GenesisHash)
forall genesis.
FromJSON genesis =>
GenesisFile
-> Maybe GenesisHash
-> ExceptT GenesisReadError IO (genesis, GenesisHash)
readGenesisAny

validateGenesis :: Conway.ConwayGenesis c
                -> ExceptT ConwayProtocolInstantiationError IO ()
validateGenesis :: forall c.
ConwayGenesis c -> ExceptT ConwayProtocolInstantiationError IO ()
validateGenesis ConwayGenesis c
_ = () -> ExceptT ConwayProtocolInstantiationError IO ()
forall a. a -> ExceptT ConwayProtocolInstantiationError IO a
forall (m :: * -> *) a. Monad m => a -> m a
return () --TODO conway: do the validation

data ConwayProtocolInstantiationError
{- TODO
  = InvalidCostModelError !FilePath
  | CostModelExtractionError !FilePath
  | ConwayCostModelFileError !(FileError ())
  | ConwayCostModelDecodeError !FilePath !String
-}
  deriving Int -> ConwayProtocolInstantiationError -> ShowS
[ConwayProtocolInstantiationError] -> ShowS
ConwayProtocolInstantiationError -> String
(Int -> ConwayProtocolInstantiationError -> ShowS)
-> (ConwayProtocolInstantiationError -> String)
-> ([ConwayProtocolInstantiationError] -> ShowS)
-> Show ConwayProtocolInstantiationError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ConwayProtocolInstantiationError -> ShowS
showsPrec :: Int -> ConwayProtocolInstantiationError -> ShowS
$cshow :: ConwayProtocolInstantiationError -> String
show :: ConwayProtocolInstantiationError -> String
$cshowList :: [ConwayProtocolInstantiationError] -> ShowS
showList :: [ConwayProtocolInstantiationError] -> ShowS
Show

{- TODO
instance Error ConwayProtocolInstantiationError where
  displayError (InvalidCostModelError fp) =
    "Invalid cost model: " <> show fp
  displayError (CostModelExtractionError fp) =
    "Error extracting the cost model at: " <> show fp
  displayError (ConwayCostModelFileError err) =
    displayError err
  displayError (ConwayCostModelDecodeError fp err) =
    "Error decoding cost model at: " <> show fp <> " Error: " <> err

-}