{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}

module Cardano.Node.Types
  ( -- * Configuration
    AdjustFilePaths(..)
  , ConfigError(..)
  , ConfigYamlFilePath(..)
  , DbFile(..)
  , GenesisFile(..)
  , ProtocolFilepaths (..)
  , GenesisHash(..)
  , MaxConcurrencyBulkSync(..)
  , MaxConcurrencyDeadline(..)
    -- * Networking
  , TopologyFile(..)
  , NodeDiffusionMode (..)
    -- * Consensus protocol configuration
  , NodeByronProtocolConfiguration(..)
  , NodeHardForkProtocolConfiguration(..)
  , NodeProtocolConfiguration(..)
  , NodeShelleyProtocolConfiguration(..)
  , NodeAlonzoProtocolConfiguration(..)
  , VRFPrivateKeyFilePermissionError(..)
  , renderVRFPrivateKeyFilePermissionError
  ) where

import           Cardano.Prelude
import           Prelude (fail)

import           Data.Aeson
import qualified Data.Text as Text

import           Cardano.Api
import qualified Cardano.Chain.Update as Byron
import           Cardano.Crypto (RequiresNetworkMagic (..))
import qualified Cardano.Crypto.Hash as Crypto
import           Cardano.Node.Configuration.NodeAddress
import           Cardano.Node.Configuration.Socket (SocketConfig (..))

--TODO: things will probably be clearer if we don't use these newtype wrappers and instead
-- use records with named fields in the CLI code.
import           Ouroboros.Network.NodeToNode (DiffusionMode (..))

-- | Errors for the cardano-config module.
data ConfigError =
    ConfigErrorFileNotFound FilePath
  | ConfigErrorNoEKG
    deriving Int -> ConfigError -> ShowS
[ConfigError] -> ShowS
ConfigError -> String
(Int -> ConfigError -> ShowS)
-> (ConfigError -> String)
-> ([ConfigError] -> ShowS)
-> Show ConfigError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConfigError] -> ShowS
$cshowList :: [ConfigError] -> ShowS
show :: ConfigError -> String
$cshow :: ConfigError -> String
showsPrec :: Int -> ConfigError -> ShowS
$cshowsPrec :: Int -> ConfigError -> ShowS
Show

-- | Filepath of the configuration yaml file. This file determines
-- all the configuration settings required for the cardano node
-- (logging, tracing, protocol, slot length etc)
newtype ConfigYamlFilePath = ConfigYamlFilePath
  { ConfigYamlFilePath -> String
unConfigPath :: FilePath }
  deriving newtype (ConfigYamlFilePath -> ConfigYamlFilePath -> Bool
(ConfigYamlFilePath -> ConfigYamlFilePath -> Bool)
-> (ConfigYamlFilePath -> ConfigYamlFilePath -> Bool)
-> Eq ConfigYamlFilePath
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConfigYamlFilePath -> ConfigYamlFilePath -> Bool
$c/= :: ConfigYamlFilePath -> ConfigYamlFilePath -> Bool
== :: ConfigYamlFilePath -> ConfigYamlFilePath -> Bool
$c== :: ConfigYamlFilePath -> ConfigYamlFilePath -> Bool
Eq, Int -> ConfigYamlFilePath -> ShowS
[ConfigYamlFilePath] -> ShowS
ConfigYamlFilePath -> String
(Int -> ConfigYamlFilePath -> ShowS)
-> (ConfigYamlFilePath -> String)
-> ([ConfigYamlFilePath] -> ShowS)
-> Show ConfigYamlFilePath
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConfigYamlFilePath] -> ShowS
$cshowList :: [ConfigYamlFilePath] -> ShowS
show :: ConfigYamlFilePath -> String
$cshow :: ConfigYamlFilePath -> String
showsPrec :: Int -> ConfigYamlFilePath -> ShowS
$cshowsPrec :: Int -> ConfigYamlFilePath -> ShowS
Show)

newtype DbFile = DbFile
  { DbFile -> String
unDB :: FilePath }
  deriving newtype (DbFile -> DbFile -> Bool
(DbFile -> DbFile -> Bool)
-> (DbFile -> DbFile -> Bool) -> Eq DbFile
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DbFile -> DbFile -> Bool
$c/= :: DbFile -> DbFile -> Bool
== :: DbFile -> DbFile -> Bool
$c== :: DbFile -> DbFile -> Bool
Eq, Int -> DbFile -> ShowS
[DbFile] -> ShowS
DbFile -> String
(Int -> DbFile -> ShowS)
-> (DbFile -> String) -> ([DbFile] -> ShowS) -> Show DbFile
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DbFile] -> ShowS
$cshowList :: [DbFile] -> ShowS
show :: DbFile -> String
$cshow :: DbFile -> String
showsPrec :: Int -> DbFile -> ShowS
$cshowsPrec :: Int -> DbFile -> ShowS
Show)

newtype GenesisFile = GenesisFile
  { GenesisFile -> String
unGenesisFile :: FilePath }
  deriving stock (GenesisFile -> GenesisFile -> Bool
(GenesisFile -> GenesisFile -> Bool)
-> (GenesisFile -> GenesisFile -> Bool) -> Eq GenesisFile
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GenesisFile -> GenesisFile -> Bool
$c/= :: GenesisFile -> GenesisFile -> Bool
== :: GenesisFile -> GenesisFile -> Bool
$c== :: GenesisFile -> GenesisFile -> Bool
Eq, Eq GenesisFile
Eq GenesisFile
-> (GenesisFile -> GenesisFile -> Ordering)
-> (GenesisFile -> GenesisFile -> Bool)
-> (GenesisFile -> GenesisFile -> Bool)
-> (GenesisFile -> GenesisFile -> Bool)
-> (GenesisFile -> GenesisFile -> Bool)
-> (GenesisFile -> GenesisFile -> GenesisFile)
-> (GenesisFile -> GenesisFile -> GenesisFile)
-> Ord GenesisFile
GenesisFile -> GenesisFile -> Bool
GenesisFile -> GenesisFile -> Ordering
GenesisFile -> GenesisFile -> GenesisFile
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: GenesisFile -> GenesisFile -> GenesisFile
$cmin :: GenesisFile -> GenesisFile -> GenesisFile
max :: GenesisFile -> GenesisFile -> GenesisFile
$cmax :: GenesisFile -> GenesisFile -> GenesisFile
>= :: GenesisFile -> GenesisFile -> Bool
$c>= :: GenesisFile -> GenesisFile -> Bool
> :: GenesisFile -> GenesisFile -> Bool
$c> :: GenesisFile -> GenesisFile -> Bool
<= :: GenesisFile -> GenesisFile -> Bool
$c<= :: GenesisFile -> GenesisFile -> Bool
< :: GenesisFile -> GenesisFile -> Bool
$c< :: GenesisFile -> GenesisFile -> Bool
compare :: GenesisFile -> GenesisFile -> Ordering
$ccompare :: GenesisFile -> GenesisFile -> Ordering
$cp1Ord :: Eq GenesisFile
Ord)
  deriving newtype (String -> GenesisFile
(String -> GenesisFile) -> IsString GenesisFile
forall a. (String -> a) -> IsString a
fromString :: String -> GenesisFile
$cfromString :: String -> GenesisFile
IsString, Int -> GenesisFile -> ShowS
[GenesisFile] -> ShowS
GenesisFile -> String
(Int -> GenesisFile -> ShowS)
-> (GenesisFile -> String)
-> ([GenesisFile] -> ShowS)
-> Show GenesisFile
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GenesisFile] -> ShowS
$cshowList :: [GenesisFile] -> ShowS
show :: GenesisFile -> String
$cshow :: GenesisFile -> String
showsPrec :: Int -> GenesisFile -> ShowS
$cshowsPrec :: Int -> GenesisFile -> ShowS
Show)

instance FromJSON GenesisFile where
  parseJSON :: Value -> Parser GenesisFile
parseJSON (String Text
genFp) = GenesisFile -> Parser GenesisFile
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GenesisFile -> Parser GenesisFile)
-> (String -> GenesisFile) -> String -> Parser GenesisFile
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. String -> GenesisFile
GenesisFile (String -> Parser GenesisFile) -> String -> Parser GenesisFile
forall a b. (a -> b) -> a -> b
$ Text -> String
Text.unpack Text
genFp
  parseJSON Value
invalid = String -> Parser GenesisFile
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser GenesisFile) -> String -> Parser GenesisFile
forall a b. (a -> b) -> a -> b
$ String
"Parsing of GenesisFile failed due to type mismatch. "
                          String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"Encountered: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Value -> String
forall a b. (Show a, ConvertText String b) => a -> b
show Value
invalid

newtype MaxConcurrencyBulkSync = MaxConcurrencyBulkSync
  { MaxConcurrencyBulkSync -> Word
unMaxConcurrencyBulkSync :: Word }
  deriving stock (MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool
(MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool)
-> (MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool)
-> Eq MaxConcurrencyBulkSync
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool
$c/= :: MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool
== :: MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool
$c== :: MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool
Eq, Eq MaxConcurrencyBulkSync
Eq MaxConcurrencyBulkSync
-> (MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Ordering)
-> (MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool)
-> (MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool)
-> (MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool)
-> (MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool)
-> (MaxConcurrencyBulkSync
    -> MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync)
-> (MaxConcurrencyBulkSync
    -> MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync)
-> Ord MaxConcurrencyBulkSync
MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool
MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Ordering
MaxConcurrencyBulkSync
-> MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: MaxConcurrencyBulkSync
-> MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync
$cmin :: MaxConcurrencyBulkSync
-> MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync
max :: MaxConcurrencyBulkSync
-> MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync
$cmax :: MaxConcurrencyBulkSync
-> MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync
>= :: MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool
$c>= :: MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool
> :: MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool
$c> :: MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool
<= :: MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool
$c<= :: MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool
< :: MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool
$c< :: MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Bool
compare :: MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Ordering
$ccompare :: MaxConcurrencyBulkSync -> MaxConcurrencyBulkSync -> Ordering
$cp1Ord :: Eq MaxConcurrencyBulkSync
Ord)
  deriving newtype (Value -> Parser [MaxConcurrencyBulkSync]
Value -> Parser MaxConcurrencyBulkSync
(Value -> Parser MaxConcurrencyBulkSync)
-> (Value -> Parser [MaxConcurrencyBulkSync])
-> FromJSON MaxConcurrencyBulkSync
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [MaxConcurrencyBulkSync]
$cparseJSONList :: Value -> Parser [MaxConcurrencyBulkSync]
parseJSON :: Value -> Parser MaxConcurrencyBulkSync
$cparseJSON :: Value -> Parser MaxConcurrencyBulkSync
FromJSON, Int -> MaxConcurrencyBulkSync -> ShowS
[MaxConcurrencyBulkSync] -> ShowS
MaxConcurrencyBulkSync -> String
(Int -> MaxConcurrencyBulkSync -> ShowS)
-> (MaxConcurrencyBulkSync -> String)
-> ([MaxConcurrencyBulkSync] -> ShowS)
-> Show MaxConcurrencyBulkSync
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MaxConcurrencyBulkSync] -> ShowS
$cshowList :: [MaxConcurrencyBulkSync] -> ShowS
show :: MaxConcurrencyBulkSync -> String
$cshow :: MaxConcurrencyBulkSync -> String
showsPrec :: Int -> MaxConcurrencyBulkSync -> ShowS
$cshowsPrec :: Int -> MaxConcurrencyBulkSync -> ShowS
Show)

newtype MaxConcurrencyDeadline = MaxConcurrencyDeadline
  { MaxConcurrencyDeadline -> Word
unMaxConcurrencyDeadline :: Word }
  deriving stock (MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool
(MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool)
-> (MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool)
-> Eq MaxConcurrencyDeadline
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool
$c/= :: MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool
== :: MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool
$c== :: MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool
Eq, Eq MaxConcurrencyDeadline
Eq MaxConcurrencyDeadline
-> (MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Ordering)
-> (MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool)
-> (MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool)
-> (MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool)
-> (MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool)
-> (MaxConcurrencyDeadline
    -> MaxConcurrencyDeadline -> MaxConcurrencyDeadline)
-> (MaxConcurrencyDeadline
    -> MaxConcurrencyDeadline -> MaxConcurrencyDeadline)
-> Ord MaxConcurrencyDeadline
MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool
MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Ordering
MaxConcurrencyDeadline
-> MaxConcurrencyDeadline -> MaxConcurrencyDeadline
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: MaxConcurrencyDeadline
-> MaxConcurrencyDeadline -> MaxConcurrencyDeadline
$cmin :: MaxConcurrencyDeadline
-> MaxConcurrencyDeadline -> MaxConcurrencyDeadline
max :: MaxConcurrencyDeadline
-> MaxConcurrencyDeadline -> MaxConcurrencyDeadline
$cmax :: MaxConcurrencyDeadline
-> MaxConcurrencyDeadline -> MaxConcurrencyDeadline
>= :: MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool
$c>= :: MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool
> :: MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool
$c> :: MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool
<= :: MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool
$c<= :: MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool
< :: MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool
$c< :: MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Bool
compare :: MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Ordering
$ccompare :: MaxConcurrencyDeadline -> MaxConcurrencyDeadline -> Ordering
$cp1Ord :: Eq MaxConcurrencyDeadline
Ord)
  deriving newtype (Value -> Parser [MaxConcurrencyDeadline]
Value -> Parser MaxConcurrencyDeadline
(Value -> Parser MaxConcurrencyDeadline)
-> (Value -> Parser [MaxConcurrencyDeadline])
-> FromJSON MaxConcurrencyDeadline
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [MaxConcurrencyDeadline]
$cparseJSONList :: Value -> Parser [MaxConcurrencyDeadline]
parseJSON :: Value -> Parser MaxConcurrencyDeadline
$cparseJSON :: Value -> Parser MaxConcurrencyDeadline
FromJSON, Int -> MaxConcurrencyDeadline -> ShowS
[MaxConcurrencyDeadline] -> ShowS
MaxConcurrencyDeadline -> String
(Int -> MaxConcurrencyDeadline -> ShowS)
-> (MaxConcurrencyDeadline -> String)
-> ([MaxConcurrencyDeadline] -> ShowS)
-> Show MaxConcurrencyDeadline
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MaxConcurrencyDeadline] -> ShowS
$cshowList :: [MaxConcurrencyDeadline] -> ShowS
show :: MaxConcurrencyDeadline -> String
$cshow :: MaxConcurrencyDeadline -> String
showsPrec :: Int -> MaxConcurrencyDeadline -> ShowS
$cshowsPrec :: Int -> MaxConcurrencyDeadline -> ShowS
Show)


-- | Newtype wrapper which provides 'FromJSON' instance for 'DiffusionMode'.
--
newtype NodeDiffusionMode
  = NodeDiffusionMode { NodeDiffusionMode -> DiffusionMode
getDiffusionMode :: DiffusionMode }
  deriving newtype Int -> NodeDiffusionMode -> ShowS
[NodeDiffusionMode] -> ShowS
NodeDiffusionMode -> String
(Int -> NodeDiffusionMode -> ShowS)
-> (NodeDiffusionMode -> String)
-> ([NodeDiffusionMode] -> ShowS)
-> Show NodeDiffusionMode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NodeDiffusionMode] -> ShowS
$cshowList :: [NodeDiffusionMode] -> ShowS
show :: NodeDiffusionMode -> String
$cshow :: NodeDiffusionMode -> String
showsPrec :: Int -> NodeDiffusionMode -> ShowS
$cshowsPrec :: Int -> NodeDiffusionMode -> ShowS
Show

instance FromJSON NodeDiffusionMode where
    parseJSON :: Value -> Parser NodeDiffusionMode
parseJSON (String Text
str) =
      case Text
str of
        Text
"InitiatorOnly"
          -> NodeDiffusionMode -> Parser NodeDiffusionMode
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NodeDiffusionMode -> Parser NodeDiffusionMode)
-> NodeDiffusionMode -> Parser NodeDiffusionMode
forall a b. (a -> b) -> a -> b
$ DiffusionMode -> NodeDiffusionMode
NodeDiffusionMode DiffusionMode
InitiatorOnlyDiffusionMode
        Text
"InitiatorAndResponder"
          -> NodeDiffusionMode -> Parser NodeDiffusionMode
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NodeDiffusionMode -> Parser NodeDiffusionMode)
-> NodeDiffusionMode -> Parser NodeDiffusionMode
forall a b. (a -> b) -> a -> b
$ DiffusionMode -> NodeDiffusionMode
NodeDiffusionMode DiffusionMode
InitiatorAndResponderDiffusionMode
        Text
_ -> String -> Parser NodeDiffusionMode
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Parsing NodeDiffusionMode failed: can be either 'InitiatorOnly' or 'InitiatorAndResponder'"
    parseJSON Value
_ = String -> Parser NodeDiffusionMode
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Parsing NodeDiffusionMode failed"

class AdjustFilePaths a where
  adjustFilePaths :: (FilePath -> FilePath) -> a -> a


data ProtocolFilepaths =
     ProtocolFilepaths {
       ProtocolFilepaths -> Maybe String
byronCertFile        :: !(Maybe FilePath)
     , ProtocolFilepaths -> Maybe String
byronKeyFile         :: !(Maybe FilePath)
     , ProtocolFilepaths -> Maybe String
shelleyKESFile       :: !(Maybe FilePath)
     , ProtocolFilepaths -> Maybe String
shelleyVRFFile       :: !(Maybe FilePath)
     , ProtocolFilepaths -> Maybe String
shelleyCertFile      :: !(Maybe FilePath)
     , ProtocolFilepaths -> Maybe String
shelleyBulkCredsFile :: !(Maybe FilePath)
     } deriving (ProtocolFilepaths -> ProtocolFilepaths -> Bool
(ProtocolFilepaths -> ProtocolFilepaths -> Bool)
-> (ProtocolFilepaths -> ProtocolFilepaths -> Bool)
-> Eq ProtocolFilepaths
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProtocolFilepaths -> ProtocolFilepaths -> Bool
$c/= :: ProtocolFilepaths -> ProtocolFilepaths -> Bool
== :: ProtocolFilepaths -> ProtocolFilepaths -> Bool
$c== :: ProtocolFilepaths -> ProtocolFilepaths -> Bool
Eq, Int -> ProtocolFilepaths -> ShowS
[ProtocolFilepaths] -> ShowS
ProtocolFilepaths -> String
(Int -> ProtocolFilepaths -> ShowS)
-> (ProtocolFilepaths -> String)
-> ([ProtocolFilepaths] -> ShowS)
-> Show ProtocolFilepaths
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProtocolFilepaths] -> ShowS
$cshowList :: [ProtocolFilepaths] -> ShowS
show :: ProtocolFilepaths -> String
$cshow :: ProtocolFilepaths -> String
showsPrec :: Int -> ProtocolFilepaths -> ShowS
$cshowsPrec :: Int -> ProtocolFilepaths -> ShowS
Show)

newtype GenesisHash = GenesisHash (Crypto.Hash Crypto.Blake2b_256 ByteString)
  deriving newtype (GenesisHash -> GenesisHash -> Bool
(GenesisHash -> GenesisHash -> Bool)
-> (GenesisHash -> GenesisHash -> Bool) -> Eq GenesisHash
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GenesisHash -> GenesisHash -> Bool
$c/= :: GenesisHash -> GenesisHash -> Bool
== :: GenesisHash -> GenesisHash -> Bool
$c== :: GenesisHash -> GenesisHash -> Bool
Eq, Int -> GenesisHash -> ShowS
[GenesisHash] -> ShowS
GenesisHash -> String
(Int -> GenesisHash -> ShowS)
-> (GenesisHash -> String)
-> ([GenesisHash] -> ShowS)
-> Show GenesisHash
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GenesisHash] -> ShowS
$cshowList :: [GenesisHash] -> ShowS
show :: GenesisHash -> String
$cshow :: GenesisHash -> String
showsPrec :: Int -> GenesisHash -> ShowS
$cshowsPrec :: Int -> GenesisHash -> ShowS
Show, [GenesisHash] -> Encoding
[GenesisHash] -> Value
GenesisHash -> Encoding
GenesisHash -> Value
(GenesisHash -> Value)
-> (GenesisHash -> Encoding)
-> ([GenesisHash] -> Value)
-> ([GenesisHash] -> Encoding)
-> ToJSON GenesisHash
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [GenesisHash] -> Encoding
$ctoEncodingList :: [GenesisHash] -> Encoding
toJSONList :: [GenesisHash] -> Value
$ctoJSONList :: [GenesisHash] -> Value
toEncoding :: GenesisHash -> Encoding
$ctoEncoding :: GenesisHash -> Encoding
toJSON :: GenesisHash -> Value
$ctoJSON :: GenesisHash -> Value
ToJSON, Value -> Parser [GenesisHash]
Value -> Parser GenesisHash
(Value -> Parser GenesisHash)
-> (Value -> Parser [GenesisHash]) -> FromJSON GenesisHash
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [GenesisHash]
$cparseJSONList :: Value -> Parser [GenesisHash]
parseJSON :: Value -> Parser GenesisHash
$cparseJSON :: Value -> Parser GenesisHash
FromJSON)

data NodeProtocolConfiguration =
       NodeProtocolConfigurationByron   NodeByronProtocolConfiguration
     | NodeProtocolConfigurationShelley NodeShelleyProtocolConfiguration
     | NodeProtocolConfigurationCardano NodeByronProtocolConfiguration
                                        NodeShelleyProtocolConfiguration
                                        NodeAlonzoProtocolConfiguration
                                        NodeHardForkProtocolConfiguration
  deriving (NodeProtocolConfiguration -> NodeProtocolConfiguration -> Bool
(NodeProtocolConfiguration -> NodeProtocolConfiguration -> Bool)
-> (NodeProtocolConfiguration -> NodeProtocolConfiguration -> Bool)
-> Eq NodeProtocolConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NodeProtocolConfiguration -> NodeProtocolConfiguration -> Bool
$c/= :: NodeProtocolConfiguration -> NodeProtocolConfiguration -> Bool
== :: NodeProtocolConfiguration -> NodeProtocolConfiguration -> Bool
$c== :: NodeProtocolConfiguration -> NodeProtocolConfiguration -> Bool
Eq, Int -> NodeProtocolConfiguration -> ShowS
[NodeProtocolConfiguration] -> ShowS
NodeProtocolConfiguration -> String
(Int -> NodeProtocolConfiguration -> ShowS)
-> (NodeProtocolConfiguration -> String)
-> ([NodeProtocolConfiguration] -> ShowS)
-> Show NodeProtocolConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NodeProtocolConfiguration] -> ShowS
$cshowList :: [NodeProtocolConfiguration] -> ShowS
show :: NodeProtocolConfiguration -> String
$cshow :: NodeProtocolConfiguration -> String
showsPrec :: Int -> NodeProtocolConfiguration -> ShowS
$cshowsPrec :: Int -> NodeProtocolConfiguration -> ShowS
Show)

data NodeShelleyProtocolConfiguration =
     NodeShelleyProtocolConfiguration {
       NodeShelleyProtocolConfiguration -> GenesisFile
npcShelleyGenesisFile     :: !GenesisFile
     , NodeShelleyProtocolConfiguration -> Maybe GenesisHash
npcShelleyGenesisFileHash :: !(Maybe GenesisHash)
     }
  deriving (NodeShelleyProtocolConfiguration
-> NodeShelleyProtocolConfiguration -> Bool
(NodeShelleyProtocolConfiguration
 -> NodeShelleyProtocolConfiguration -> Bool)
-> (NodeShelleyProtocolConfiguration
    -> NodeShelleyProtocolConfiguration -> Bool)
-> Eq NodeShelleyProtocolConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NodeShelleyProtocolConfiguration
-> NodeShelleyProtocolConfiguration -> Bool
$c/= :: NodeShelleyProtocolConfiguration
-> NodeShelleyProtocolConfiguration -> Bool
== :: NodeShelleyProtocolConfiguration
-> NodeShelleyProtocolConfiguration -> Bool
$c== :: NodeShelleyProtocolConfiguration
-> NodeShelleyProtocolConfiguration -> Bool
Eq, Int -> NodeShelleyProtocolConfiguration -> ShowS
[NodeShelleyProtocolConfiguration] -> ShowS
NodeShelleyProtocolConfiguration -> String
(Int -> NodeShelleyProtocolConfiguration -> ShowS)
-> (NodeShelleyProtocolConfiguration -> String)
-> ([NodeShelleyProtocolConfiguration] -> ShowS)
-> Show NodeShelleyProtocolConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NodeShelleyProtocolConfiguration] -> ShowS
$cshowList :: [NodeShelleyProtocolConfiguration] -> ShowS
show :: NodeShelleyProtocolConfiguration -> String
$cshow :: NodeShelleyProtocolConfiguration -> String
showsPrec :: Int -> NodeShelleyProtocolConfiguration -> ShowS
$cshowsPrec :: Int -> NodeShelleyProtocolConfiguration -> ShowS
Show)

data NodeAlonzoProtocolConfiguration =
     NodeAlonzoProtocolConfiguration {
       NodeAlonzoProtocolConfiguration -> GenesisFile
npcAlonzoGenesisFile     :: !GenesisFile
     , NodeAlonzoProtocolConfiguration -> Maybe GenesisHash
npcAlonzoGenesisFileHash :: !(Maybe GenesisHash)
     }
  deriving (NodeAlonzoProtocolConfiguration
-> NodeAlonzoProtocolConfiguration -> Bool
(NodeAlonzoProtocolConfiguration
 -> NodeAlonzoProtocolConfiguration -> Bool)
-> (NodeAlonzoProtocolConfiguration
    -> NodeAlonzoProtocolConfiguration -> Bool)
-> Eq NodeAlonzoProtocolConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NodeAlonzoProtocolConfiguration
-> NodeAlonzoProtocolConfiguration -> Bool
$c/= :: NodeAlonzoProtocolConfiguration
-> NodeAlonzoProtocolConfiguration -> Bool
== :: NodeAlonzoProtocolConfiguration
-> NodeAlonzoProtocolConfiguration -> Bool
$c== :: NodeAlonzoProtocolConfiguration
-> NodeAlonzoProtocolConfiguration -> Bool
Eq, Int -> NodeAlonzoProtocolConfiguration -> ShowS
[NodeAlonzoProtocolConfiguration] -> ShowS
NodeAlonzoProtocolConfiguration -> String
(Int -> NodeAlonzoProtocolConfiguration -> ShowS)
-> (NodeAlonzoProtocolConfiguration -> String)
-> ([NodeAlonzoProtocolConfiguration] -> ShowS)
-> Show NodeAlonzoProtocolConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NodeAlonzoProtocolConfiguration] -> ShowS
$cshowList :: [NodeAlonzoProtocolConfiguration] -> ShowS
show :: NodeAlonzoProtocolConfiguration -> String
$cshow :: NodeAlonzoProtocolConfiguration -> String
showsPrec :: Int -> NodeAlonzoProtocolConfiguration -> ShowS
$cshowsPrec :: Int -> NodeAlonzoProtocolConfiguration -> ShowS
Show)

data NodeByronProtocolConfiguration =
     NodeByronProtocolConfiguration {
       NodeByronProtocolConfiguration -> GenesisFile
npcByronGenesisFile                   :: !GenesisFile
     , NodeByronProtocolConfiguration -> Maybe GenesisHash
npcByronGenesisFileHash               :: !(Maybe GenesisHash)
     , NodeByronProtocolConfiguration -> RequiresNetworkMagic
npcByronReqNetworkMagic               :: !RequiresNetworkMagic
     , NodeByronProtocolConfiguration -> Maybe Double
npcByronPbftSignatureThresh           :: !(Maybe Double)

       --TODO: eliminate these two: it can be hard-coded
       -- | Update application name.
     , NodeByronProtocolConfiguration -> ApplicationName
npcByronApplicationName               :: !Byron.ApplicationName

       -- | Application (ie software) version.
     , NodeByronProtocolConfiguration -> NumSoftwareVersion
npcByronApplicationVersion            :: !Byron.NumSoftwareVersion

       --TODO: eliminate these: it can be done automatically in consensus
       -- | These declare the version of the protocol that the node is prepared
       -- to run. This is usually the version of the protocol in use on the
       -- chain now, but during protocol updates this version will be the one
       -- that we declare that we are ready to move to. This is the endorsement
       -- mechanism for determining when enough block producers are ready to
       -- move to the next version.
       --
     , NodeByronProtocolConfiguration -> Word16
npcByronSupportedProtocolVersionMajor :: !Word16
     , NodeByronProtocolConfiguration -> Word16
npcByronSupportedProtocolVersionMinor :: !Word16
     , NodeByronProtocolConfiguration -> Word8
npcByronSupportedProtocolVersionAlt   :: !Word8
     }
  deriving (NodeByronProtocolConfiguration
-> NodeByronProtocolConfiguration -> Bool
(NodeByronProtocolConfiguration
 -> NodeByronProtocolConfiguration -> Bool)
-> (NodeByronProtocolConfiguration
    -> NodeByronProtocolConfiguration -> Bool)
-> Eq NodeByronProtocolConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NodeByronProtocolConfiguration
-> NodeByronProtocolConfiguration -> Bool
$c/= :: NodeByronProtocolConfiguration
-> NodeByronProtocolConfiguration -> Bool
== :: NodeByronProtocolConfiguration
-> NodeByronProtocolConfiguration -> Bool
$c== :: NodeByronProtocolConfiguration
-> NodeByronProtocolConfiguration -> Bool
Eq, Int -> NodeByronProtocolConfiguration -> ShowS
[NodeByronProtocolConfiguration] -> ShowS
NodeByronProtocolConfiguration -> String
(Int -> NodeByronProtocolConfiguration -> ShowS)
-> (NodeByronProtocolConfiguration -> String)
-> ([NodeByronProtocolConfiguration] -> ShowS)
-> Show NodeByronProtocolConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NodeByronProtocolConfiguration] -> ShowS
$cshowList :: [NodeByronProtocolConfiguration] -> ShowS
show :: NodeByronProtocolConfiguration -> String
$cshow :: NodeByronProtocolConfiguration -> String
showsPrec :: Int -> NodeByronProtocolConfiguration -> ShowS
$cshowsPrec :: Int -> NodeByronProtocolConfiguration -> ShowS
Show)

-- | Configuration relating to a hard forks themselves, not the specific eras.
--
data NodeHardForkProtocolConfiguration =
     NodeHardForkProtocolConfiguration {

       -- | During the development and integration of new eras we wish to be
       -- able to test the hard fork transition into the new era, but we do not
       -- wish to generally have the node advertise that it understands the new
       -- era. Avoiding advertising new development eras until they are ready
       -- makes it practical to include new not-yet-ready eras into the main
       -- release version of the node without the danger that operators on the
       -- mainnet will prematurely advertise that their nodes are capable of
       -- crossing the next hard fork.
       --
       -- It should /always/ remain at the default of false for nodes running
       -- on the mainnet.
       --
       -- This flag should be set to true for nodes taking part in testnets for
       -- testing the new era.
       --
       NodeHardForkProtocolConfiguration -> Bool
npcTestEnableDevelopmentHardForkEras :: Bool

       -- | For testing purposes we support specifying that the hard fork
       -- happens at an exact epoch number (ie the first epoch of the new era).
       --
       -- Obviously if this is used, all the nodes in the test cluster must be
       -- configured the same, or they will disagree.
       --
     , NodeHardForkProtocolConfiguration -> Maybe EpochNo
npcTestShelleyHardForkAtEpoch        :: Maybe EpochNo

       -- | For testing purposes we support specifying that the hard fork
       -- happens at a given major protocol version. For example this can be
       -- used to cause the Shelley hard fork to occur at the transition from
       -- protocol version 0 to version 1 (rather than the default of from 1 to
       -- 2) which can make the test setup simpler.
       --
       -- Obviously if this is used, all the nodes in the test cluster must be
       -- configured the same, or they will disagree.
       --
     , NodeHardForkProtocolConfiguration -> Maybe Word
npcTestShelleyHardForkAtVersion      :: Maybe Word

       -- | For testing purposes we support specifying that the hard fork
       -- happens at an exact epoch number (ie the first epoch of the new era).
       --
       -- Obviously if this is used, all the nodes in the test cluster must be
       -- configured the same, or they will disagree.
       --
     , NodeHardForkProtocolConfiguration -> Maybe EpochNo
npcTestAllegraHardForkAtEpoch        :: Maybe EpochNo

       -- | For testing purposes we support specifying that the hard fork
       -- happens at a given major protocol version.
       --
       -- Obviously if this is used, all the nodes in the test cluster must be
       -- configured the same, or they will disagree.
       --
     , NodeHardForkProtocolConfiguration -> Maybe Word
npcTestAllegraHardForkAtVersion      :: Maybe Word

       -- | For testing purposes we support specifying that the hard fork
       -- happens at an exact epoch number (ie the first epoch of the new era).
       --
       -- Obviously if this is used, all the nodes in the test cluster must be
       -- configured the same, or they will disagree.
       --
     , NodeHardForkProtocolConfiguration -> Maybe EpochNo
npcTestMaryHardForkAtEpoch           :: Maybe EpochNo

       -- | For testing purposes we support specifying that the hard fork
       -- happens at a given major protocol version.
       --
       -- Obviously if this is used, all the nodes in the test cluster must be
       -- configured the same, or they will disagree.
       --
       --
     , NodeHardForkProtocolConfiguration -> Maybe Word
npcTestMaryHardForkAtVersion         :: Maybe Word

       -- | For testing purposes we support specifying that the hard fork
       -- happens at an exact epoch number (ie the first epoch of the new era).
       --
       -- Obviously if this is used, all the nodes in the test cluster must be
       -- configured the same, or they will disagree.
       --
     , NodeHardForkProtocolConfiguration -> Maybe EpochNo
npcTestAlonzoHardForkAtEpoch         :: Maybe EpochNo

       -- | For testing purposes we support specifying that the hard fork
       -- happens at a given major protocol version.
       --
       -- Obviously if this is used, all the nodes in the test cluster must be
       -- configured the same, or they will disagree.
       --
     , NodeHardForkProtocolConfiguration -> Maybe Word
npcTestAlonzoHardForkAtVersion       :: Maybe Word

     , NodeHardForkProtocolConfiguration -> Maybe EpochNo
npcTestBabbageHardForkAtEpoch        :: Maybe EpochNo

       -- | For testing purposes we support specifying that the hard fork
       -- happens at a given major protocol version.
       --
       -- Obviously if this is used, all the nodes in the test cluster must be
       -- configured the same, or they will disagree.
       --
     , NodeHardForkProtocolConfiguration -> Maybe Word
npcTestBabbageHardForkAtVersion      :: Maybe Word
     }
  deriving (NodeHardForkProtocolConfiguration
-> NodeHardForkProtocolConfiguration -> Bool
(NodeHardForkProtocolConfiguration
 -> NodeHardForkProtocolConfiguration -> Bool)
-> (NodeHardForkProtocolConfiguration
    -> NodeHardForkProtocolConfiguration -> Bool)
-> Eq NodeHardForkProtocolConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NodeHardForkProtocolConfiguration
-> NodeHardForkProtocolConfiguration -> Bool
$c/= :: NodeHardForkProtocolConfiguration
-> NodeHardForkProtocolConfiguration -> Bool
== :: NodeHardForkProtocolConfiguration
-> NodeHardForkProtocolConfiguration -> Bool
$c== :: NodeHardForkProtocolConfiguration
-> NodeHardForkProtocolConfiguration -> Bool
Eq, Int -> NodeHardForkProtocolConfiguration -> ShowS
[NodeHardForkProtocolConfiguration] -> ShowS
NodeHardForkProtocolConfiguration -> String
(Int -> NodeHardForkProtocolConfiguration -> ShowS)
-> (NodeHardForkProtocolConfiguration -> String)
-> ([NodeHardForkProtocolConfiguration] -> ShowS)
-> Show NodeHardForkProtocolConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NodeHardForkProtocolConfiguration] -> ShowS
$cshowList :: [NodeHardForkProtocolConfiguration] -> ShowS
show :: NodeHardForkProtocolConfiguration -> String
$cshow :: NodeHardForkProtocolConfiguration -> String
showsPrec :: Int -> NodeHardForkProtocolConfiguration -> ShowS
$cshowsPrec :: Int -> NodeHardForkProtocolConfiguration -> ShowS
Show)

newtype TopologyFile = TopologyFile
  { TopologyFile -> String
unTopology :: FilePath }
  deriving newtype (Int -> TopologyFile -> ShowS
[TopologyFile] -> ShowS
TopologyFile -> String
(Int -> TopologyFile -> ShowS)
-> (TopologyFile -> String)
-> ([TopologyFile] -> ShowS)
-> Show TopologyFile
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TopologyFile] -> ShowS
$cshowList :: [TopologyFile] -> ShowS
show :: TopologyFile -> String
$cshow :: TopologyFile -> String
showsPrec :: Int -> TopologyFile -> ShowS
$cshowsPrec :: Int -> TopologyFile -> ShowS
Show, TopologyFile -> TopologyFile -> Bool
(TopologyFile -> TopologyFile -> Bool)
-> (TopologyFile -> TopologyFile -> Bool) -> Eq TopologyFile
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TopologyFile -> TopologyFile -> Bool
$c/= :: TopologyFile -> TopologyFile -> Bool
== :: TopologyFile -> TopologyFile -> Bool
$c== :: TopologyFile -> TopologyFile -> Bool
Eq)

instance AdjustFilePaths NodeProtocolConfiguration where

  adjustFilePaths :: ShowS -> NodeProtocolConfiguration -> NodeProtocolConfiguration
adjustFilePaths ShowS
f (NodeProtocolConfigurationByron NodeByronProtocolConfiguration
pc) =
    NodeByronProtocolConfiguration -> NodeProtocolConfiguration
NodeProtocolConfigurationByron (ShowS
-> NodeByronProtocolConfiguration -> NodeByronProtocolConfiguration
forall a. AdjustFilePaths a => ShowS -> a -> a
adjustFilePaths ShowS
f NodeByronProtocolConfiguration
pc)

  adjustFilePaths ShowS
f (NodeProtocolConfigurationShelley NodeShelleyProtocolConfiguration
pc) =
    NodeShelleyProtocolConfiguration -> NodeProtocolConfiguration
NodeProtocolConfigurationShelley (ShowS
-> NodeShelleyProtocolConfiguration
-> NodeShelleyProtocolConfiguration
forall a. AdjustFilePaths a => ShowS -> a -> a
adjustFilePaths ShowS
f NodeShelleyProtocolConfiguration
pc)

  adjustFilePaths ShowS
f (NodeProtocolConfigurationCardano NodeByronProtocolConfiguration
pcb NodeShelleyProtocolConfiguration
pcs NodeAlonzoProtocolConfiguration
pca NodeHardForkProtocolConfiguration
pch) =
    NodeByronProtocolConfiguration
-> NodeShelleyProtocolConfiguration
-> NodeAlonzoProtocolConfiguration
-> NodeHardForkProtocolConfiguration
-> NodeProtocolConfiguration
NodeProtocolConfigurationCardano (ShowS
-> NodeByronProtocolConfiguration -> NodeByronProtocolConfiguration
forall a. AdjustFilePaths a => ShowS -> a -> a
adjustFilePaths ShowS
f NodeByronProtocolConfiguration
pcb)
                                     (ShowS
-> NodeShelleyProtocolConfiguration
-> NodeShelleyProtocolConfiguration
forall a. AdjustFilePaths a => ShowS -> a -> a
adjustFilePaths ShowS
f NodeShelleyProtocolConfiguration
pcs)
                                     (ShowS
-> NodeAlonzoProtocolConfiguration
-> NodeAlonzoProtocolConfiguration
forall a. AdjustFilePaths a => ShowS -> a -> a
adjustFilePaths ShowS
f NodeAlonzoProtocolConfiguration
pca)
                                     NodeHardForkProtocolConfiguration
pch

instance AdjustFilePaths NodeByronProtocolConfiguration where
  adjustFilePaths :: ShowS
-> NodeByronProtocolConfiguration -> NodeByronProtocolConfiguration
adjustFilePaths ShowS
f x :: NodeByronProtocolConfiguration
x@NodeByronProtocolConfiguration {
                        GenesisFile
npcByronGenesisFile :: GenesisFile
npcByronGenesisFile :: NodeByronProtocolConfiguration -> GenesisFile
npcByronGenesisFile
                      } =
    NodeByronProtocolConfiguration
x { npcByronGenesisFile :: GenesisFile
npcByronGenesisFile = ShowS -> GenesisFile -> GenesisFile
forall a. AdjustFilePaths a => ShowS -> a -> a
adjustFilePaths ShowS
f GenesisFile
npcByronGenesisFile }

instance AdjustFilePaths NodeShelleyProtocolConfiguration where
  adjustFilePaths :: ShowS
-> NodeShelleyProtocolConfiguration
-> NodeShelleyProtocolConfiguration
adjustFilePaths ShowS
f x :: NodeShelleyProtocolConfiguration
x@NodeShelleyProtocolConfiguration {
                        GenesisFile
npcShelleyGenesisFile :: GenesisFile
npcShelleyGenesisFile :: NodeShelleyProtocolConfiguration -> GenesisFile
npcShelleyGenesisFile
                      } =
    NodeShelleyProtocolConfiguration
x { npcShelleyGenesisFile :: GenesisFile
npcShelleyGenesisFile = ShowS -> GenesisFile -> GenesisFile
forall a. AdjustFilePaths a => ShowS -> a -> a
adjustFilePaths ShowS
f GenesisFile
npcShelleyGenesisFile }

instance AdjustFilePaths NodeAlonzoProtocolConfiguration where
  adjustFilePaths :: ShowS
-> NodeAlonzoProtocolConfiguration
-> NodeAlonzoProtocolConfiguration
adjustFilePaths ShowS
f x :: NodeAlonzoProtocolConfiguration
x@NodeAlonzoProtocolConfiguration {
                        GenesisFile
npcAlonzoGenesisFile :: GenesisFile
npcAlonzoGenesisFile :: NodeAlonzoProtocolConfiguration -> GenesisFile
npcAlonzoGenesisFile
                      } =
    NodeAlonzoProtocolConfiguration
x { npcAlonzoGenesisFile :: GenesisFile
npcAlonzoGenesisFile = ShowS -> GenesisFile -> GenesisFile
forall a. AdjustFilePaths a => ShowS -> a -> a
adjustFilePaths ShowS
f GenesisFile
npcAlonzoGenesisFile }

instance AdjustFilePaths SocketConfig where
  adjustFilePaths :: ShowS -> SocketConfig -> SocketConfig
adjustFilePaths ShowS
f x :: SocketConfig
x@SocketConfig{Last SocketPath
ncSocketPath :: SocketConfig -> Last SocketPath
ncSocketPath :: Last SocketPath
ncSocketPath} =
    SocketConfig
x { ncSocketPath :: Last SocketPath
ncSocketPath = ShowS -> Last SocketPath -> Last SocketPath
forall a. AdjustFilePaths a => ShowS -> a -> a
adjustFilePaths ShowS
f Last SocketPath
ncSocketPath }

instance AdjustFilePaths SocketPath where
  adjustFilePaths :: ShowS -> SocketPath -> SocketPath
adjustFilePaths ShowS
f (SocketPath String
p) = String -> SocketPath
SocketPath (ShowS
f String
p)

instance AdjustFilePaths GenesisFile where
  adjustFilePaths :: ShowS -> GenesisFile -> GenesisFile
adjustFilePaths ShowS
f (GenesisFile String
p) = String -> GenesisFile
GenesisFile (ShowS
f String
p)

instance AdjustFilePaths a => AdjustFilePaths (Maybe a) where
  adjustFilePaths :: ShowS -> Maybe a -> Maybe a
adjustFilePaths ShowS
f = (a -> a) -> Maybe a -> Maybe a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ShowS -> a -> a
forall a. AdjustFilePaths a => ShowS -> a -> a
adjustFilePaths ShowS
f)

instance AdjustFilePaths a => AdjustFilePaths (Last a) where
  adjustFilePaths :: ShowS -> Last a -> Last a
adjustFilePaths ShowS
f = (a -> a) -> Last a -> Last a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ShowS -> a -> a
forall a. AdjustFilePaths a => ShowS -> a -> a
adjustFilePaths ShowS
f)

data VRFPrivateKeyFilePermissionError
  = OtherPermissionsExist FilePath
  | GroupPermissionsExist FilePath
  | GenericPermissionsExist FilePath
  deriving Int -> VRFPrivateKeyFilePermissionError -> ShowS
[VRFPrivateKeyFilePermissionError] -> ShowS
VRFPrivateKeyFilePermissionError -> String
(Int -> VRFPrivateKeyFilePermissionError -> ShowS)
-> (VRFPrivateKeyFilePermissionError -> String)
-> ([VRFPrivateKeyFilePermissionError] -> ShowS)
-> Show VRFPrivateKeyFilePermissionError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VRFPrivateKeyFilePermissionError] -> ShowS
$cshowList :: [VRFPrivateKeyFilePermissionError] -> ShowS
show :: VRFPrivateKeyFilePermissionError -> String
$cshow :: VRFPrivateKeyFilePermissionError -> String
showsPrec :: Int -> VRFPrivateKeyFilePermissionError -> ShowS
$cshowsPrec :: Int -> VRFPrivateKeyFilePermissionError -> ShowS
Show

renderVRFPrivateKeyFilePermissionError :: VRFPrivateKeyFilePermissionError -> Text
renderVRFPrivateKeyFilePermissionError :: VRFPrivateKeyFilePermissionError -> Text
renderVRFPrivateKeyFilePermissionError VRFPrivateKeyFilePermissionError
err =
  case VRFPrivateKeyFilePermissionError
err of
    OtherPermissionsExist String
fp ->
      Text
"VRF private key file at: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack String
fp
      Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" has \"other\" file permissions. Please remove all \"other\" file permissions."

    GroupPermissionsExist String
fp ->
      Text
"VRF private key file at: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack String
fp
      Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"has \"group\" file permissions. Please remove all \"group\" file permissions."
    GenericPermissionsExist String
fp ->
      Text
"VRF private key file at: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack String
fp
      Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"has \"generic\" file permissions. Please remove all \"generic\" file permissions."