{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Hydra.Options (
  module Hydra.Options,
  ParserResult (..),
  renderFailure,
) where

import Hydra.Prelude

import Control.Arrow (left)
import Control.Lens ((?~))
import Data.Aeson (Value (Object, String), withObject, (.:))
import Data.Aeson.Lens (atKey)
import Data.ByteString qualified as BS
import Data.ByteString.Char8 qualified as BSC
import Data.IP (IP (IPv4), toIPv4, toIPv4w)
import Data.Text (unpack)
import Data.Text qualified as T
import Data.Version (Version (..), showVersion)
import Hydra.Cardano.Api (
  ChainPoint (..),
  File (..),
  NetworkId (..),
  NetworkMagic (..),
  SlotNo (..),
  SocketPath,
  TxId (..),
  deserialiseFromRawBytes,
  deserialiseFromRawBytesHex,
  proxyToAsType,
  serialiseToRawBytesHexText,
 )
import Hydra.Chain (maximumNumberOfParties)
import Hydra.Contract qualified as Contract
import Hydra.Ledger.Cardano ()
import Hydra.Logging (Verbosity (..))
import Hydra.Network (Host (..), NodeId (NodeId), PortNumber, WhichEtcd (..), readHost, readPort, showHost)
import Hydra.Node.DepositPeriod (DepositPeriod (..))
import Hydra.Tx.ContestationPeriod (ContestationPeriod, fromNominalDiffTime)
import Hydra.Tx.HeadId (HeadSeed)
import Hydra.Version (embeddedRevision, gitRevision, unknownVersion)
import Options.Applicative (
  Parser,
  ParserInfo,
  ParserResult (..),
  auto,
  command,
  completer,
  defaultPrefs,
  eitherReader,
  execParserPure,
  flag,
  flag',
  footer,
  fullDesc,
  handleParseResult,
  header,
  help,
  helper,
  hsubparser,
  info,
  infoOption,
  listCompleter,
  long,
  maybeReader,
  metavar,
  option,
  progDesc,
  progDescDoc,
  renderFailure,
  short,
  showDefault,
  strOption,
  value,
 )
import Options.Applicative.Builder (str)
import Options.Applicative.Help (vsep)
import Paths_hydra_node (version)
import Test.QuickCheck (elements, listOf, listOf1, oneof, vectorOf)

data Command
  = Run RunOptions
  | Publish PublishOptions
  | GenHydraKey GenerateKeyPair
  deriving stock (Int -> Command -> ShowS
[Command] -> ShowS
Command -> [Char]
(Int -> Command -> ShowS)
-> (Command -> [Char]) -> ([Command] -> ShowS) -> Show Command
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Command -> ShowS
showsPrec :: Int -> Command -> ShowS
$cshow :: Command -> [Char]
show :: Command -> [Char]
$cshowList :: [Command] -> ShowS
showList :: [Command] -> ShowS
Show, Command -> Command -> Bool
(Command -> Command -> Bool)
-> (Command -> Command -> Bool) -> Eq Command
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Command -> Command -> Bool
== :: Command -> Command -> Bool
$c/= :: Command -> Command -> Bool
/= :: Command -> Command -> Bool
Eq)

commandParser :: Parser Command
commandParser :: Parser Command
commandParser =
  Parser Command
subcommands
    Parser Command -> Parser Command -> Parser Command
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> RunOptions -> Command
Run (RunOptions -> Command) -> Parser RunOptions -> Parser Command
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser RunOptions
runOptionsParser
 where
  subcommands :: Parser Command
subcommands =
    Mod CommandFields Command -> Parser Command
forall a. Mod CommandFields a -> Parser a
hsubparser (Mod CommandFields Command -> Parser Command)
-> Mod CommandFields Command -> Parser Command
forall a b. (a -> b) -> a -> b
$
      Mod CommandFields Command
publishScriptsCommand
        Mod CommandFields Command
-> Mod CommandFields Command -> Mod CommandFields Command
forall a. Semigroup a => a -> a -> a
<> Mod CommandFields Command
genHydraKeyCommand

  publishScriptsCommand :: Mod CommandFields Command
publishScriptsCommand =
    [Char] -> ParserInfo Command -> Mod CommandFields Command
forall a. [Char] -> ParserInfo a -> Mod CommandFields a
command
      [Char]
"publish-scripts"
      ( Parser Command -> InfoMod Command -> ParserInfo Command
forall a. Parser a -> InfoMod a -> ParserInfo a
info
          (PublishOptions -> Command
Publish (PublishOptions -> Command)
-> Parser PublishOptions -> Parser Command
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser PublishOptions
publishOptionsParser)
          ( InfoMod Command
forall a. InfoMod a
fullDesc
              InfoMod Command -> InfoMod Command -> InfoMod Command
forall a. Semigroup a => a -> a -> a
<> Maybe (Doc AnsiStyle) -> InfoMod Command
forall a. Maybe (Doc AnsiStyle) -> InfoMod a
progDescDoc
                ( Doc AnsiStyle -> Maybe (Doc AnsiStyle)
forall a. a -> Maybe a
Just (Doc AnsiStyle -> Maybe (Doc AnsiStyle))
-> Doc AnsiStyle -> Maybe (Doc AnsiStyle)
forall a b. (a -> b) -> a -> b
$
                    [Doc AnsiStyle] -> Doc AnsiStyle
forall ann. [Doc ann] -> Doc ann
vsep
                      [ Doc AnsiStyle
"Publish Hydra's Plutus scripts on chain to be used"
                      , Doc AnsiStyle
"by the hydra-node as --hydra-script-tx-id."
                      , Doc AnsiStyle
""
                      , Doc AnsiStyle
" ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ "
                      , Doc AnsiStyle
" ┃              ⚠ WARNING ⚠              ┃ "
                      , Doc AnsiStyle
" ┣═══════════════════════════════════════┫ "
                      , Doc AnsiStyle
" ┃    This costs money. About 50 Ada.    ┃ "
                      , Doc AnsiStyle
" ┃ Spent using the provided signing key. ┃ "
                      , Doc AnsiStyle
" ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ "
                      ]
                )
              InfoMod Command -> InfoMod Command -> InfoMod Command
forall a. Semigroup a => a -> a -> a
<> [Char] -> InfoMod Command
forall a. [Char] -> InfoMod a
footer
                [Char]
"The command outputs the transaction id (in base16) \
                \of the publishing transaction. This transaction id \
                \can then be passed onto '--hydra-scripts-tx-id' to \
                \start a hydra-node using the referenced scripts."
          )
      )

  genHydraKeyCommand :: Mod CommandFields Command
genHydraKeyCommand =
    [Char] -> ParserInfo Command -> Mod CommandFields Command
forall a. [Char] -> ParserInfo a -> Mod CommandFields a
command
      [Char]
"gen-hydra-key"
      ( Parser Command -> InfoMod Command -> ParserInfo Command
forall a. Parser a -> InfoMod a -> ParserInfo a
info
          (GenerateKeyPair -> Command
GenHydraKey (GenerateKeyPair -> Command)
-> ([Char] -> GenerateKeyPair) -> [Char] -> Command
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> GenerateKeyPair
GenerateKeyPair ([Char] -> Command) -> Parser [Char] -> Parser Command
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Char]
outputFileParser)
          ([Char] -> InfoMod Command
forall a. [Char] -> InfoMod a
progDesc [Char]
"Generate a pair of Hydra signing/verification keys (off-chain keys).")
      )

data PublishOptions = PublishOptions
  { PublishOptions -> ChainBackendOptions
chainBackendOptions :: ChainBackendOptions
  , PublishOptions -> [Char]
publishSigningKey :: FilePath
  }
  deriving stock (Int -> PublishOptions -> ShowS
[PublishOptions] -> ShowS
PublishOptions -> [Char]
(Int -> PublishOptions -> ShowS)
-> (PublishOptions -> [Char])
-> ([PublishOptions] -> ShowS)
-> Show PublishOptions
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PublishOptions -> ShowS
showsPrec :: Int -> PublishOptions -> ShowS
$cshow :: PublishOptions -> [Char]
show :: PublishOptions -> [Char]
$cshowList :: [PublishOptions] -> ShowS
showList :: [PublishOptions] -> ShowS
Show, PublishOptions -> PublishOptions -> Bool
(PublishOptions -> PublishOptions -> Bool)
-> (PublishOptions -> PublishOptions -> Bool) -> Eq PublishOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PublishOptions -> PublishOptions -> Bool
== :: PublishOptions -> PublishOptions -> Bool
$c/= :: PublishOptions -> PublishOptions -> Bool
/= :: PublishOptions -> PublishOptions -> Bool
Eq, (forall x. PublishOptions -> Rep PublishOptions x)
-> (forall x. Rep PublishOptions x -> PublishOptions)
-> Generic PublishOptions
forall x. Rep PublishOptions x -> PublishOptions
forall x. PublishOptions -> Rep PublishOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PublishOptions -> Rep PublishOptions x
from :: forall x. PublishOptions -> Rep PublishOptions x
$cto :: forall x. Rep PublishOptions x -> PublishOptions
to :: forall x. Rep PublishOptions x -> PublishOptions
Generic)

-- | Default options as they should also be provided by 'runOptionsParser'.
defaultPublishOptions :: PublishOptions
defaultPublishOptions :: PublishOptions
defaultPublishOptions =
  PublishOptions
    { $sel:chainBackendOptions:PublishOptions :: ChainBackendOptions
chainBackendOptions = DirectOptions -> ChainBackendOptions
Direct DirectOptions
defaultDirectOptions
    , $sel:publishSigningKey:PublishOptions :: [Char]
publishSigningKey = [Char]
"cardano.sk"
    }

defaultDirectOptions :: DirectOptions
defaultDirectOptions :: DirectOptions
defaultDirectOptions =
  DirectOptions
    { $sel:networkId:DirectOptions :: NetworkId
networkId = NetworkMagic -> NetworkId
Testnet (Word32 -> NetworkMagic
NetworkMagic Word32
42)
    , $sel:nodeSocket:DirectOptions :: SocketPath
nodeSocket = SocketPath
"node.socket"
    }

data ChainBackendOptions
  = Direct DirectOptions
  | Blockfrost BlockfrostOptions
  deriving stock ((forall x. ChainBackendOptions -> Rep ChainBackendOptions x)
-> (forall x. Rep ChainBackendOptions x -> ChainBackendOptions)
-> Generic ChainBackendOptions
forall x. Rep ChainBackendOptions x -> ChainBackendOptions
forall x. ChainBackendOptions -> Rep ChainBackendOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ChainBackendOptions -> Rep ChainBackendOptions x
from :: forall x. ChainBackendOptions -> Rep ChainBackendOptions x
$cto :: forall x. Rep ChainBackendOptions x -> ChainBackendOptions
to :: forall x. Rep ChainBackendOptions x -> ChainBackendOptions
Generic, Int -> ChainBackendOptions -> ShowS
[ChainBackendOptions] -> ShowS
ChainBackendOptions -> [Char]
(Int -> ChainBackendOptions -> ShowS)
-> (ChainBackendOptions -> [Char])
-> ([ChainBackendOptions] -> ShowS)
-> Show ChainBackendOptions
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChainBackendOptions -> ShowS
showsPrec :: Int -> ChainBackendOptions -> ShowS
$cshow :: ChainBackendOptions -> [Char]
show :: ChainBackendOptions -> [Char]
$cshowList :: [ChainBackendOptions] -> ShowS
showList :: [ChainBackendOptions] -> ShowS
Show, ChainBackendOptions -> ChainBackendOptions -> Bool
(ChainBackendOptions -> ChainBackendOptions -> Bool)
-> (ChainBackendOptions -> ChainBackendOptions -> Bool)
-> Eq ChainBackendOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChainBackendOptions -> ChainBackendOptions -> Bool
== :: ChainBackendOptions -> ChainBackendOptions -> Bool
$c/= :: ChainBackendOptions -> ChainBackendOptions -> Bool
/= :: ChainBackendOptions -> ChainBackendOptions -> Bool
Eq)
  deriving anyclass ([ChainBackendOptions] -> Value
[ChainBackendOptions] -> Encoding
ChainBackendOptions -> Bool
ChainBackendOptions -> Value
ChainBackendOptions -> Encoding
(ChainBackendOptions -> Value)
-> (ChainBackendOptions -> Encoding)
-> ([ChainBackendOptions] -> Value)
-> ([ChainBackendOptions] -> Encoding)
-> (ChainBackendOptions -> Bool)
-> ToJSON ChainBackendOptions
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: ChainBackendOptions -> Value
toJSON :: ChainBackendOptions -> Value
$ctoEncoding :: ChainBackendOptions -> Encoding
toEncoding :: ChainBackendOptions -> Encoding
$ctoJSONList :: [ChainBackendOptions] -> Value
toJSONList :: [ChainBackendOptions] -> Value
$ctoEncodingList :: [ChainBackendOptions] -> Encoding
toEncodingList :: [ChainBackendOptions] -> Encoding
$comitField :: ChainBackendOptions -> Bool
omitField :: ChainBackendOptions -> Bool
ToJSON, Maybe ChainBackendOptions
Value -> Parser [ChainBackendOptions]
Value -> Parser ChainBackendOptions
(Value -> Parser ChainBackendOptions)
-> (Value -> Parser [ChainBackendOptions])
-> Maybe ChainBackendOptions
-> FromJSON ChainBackendOptions
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser ChainBackendOptions
parseJSON :: Value -> Parser ChainBackendOptions
$cparseJSONList :: Value -> Parser [ChainBackendOptions]
parseJSONList :: Value -> Parser [ChainBackendOptions]
$comittedField :: Maybe ChainBackendOptions
omittedField :: Maybe ChainBackendOptions
FromJSON)

data DirectOptions = DirectOptions
  { DirectOptions -> NetworkId
networkId :: NetworkId
  -- ^ Network identifier to which we expect to connect.
  , DirectOptions -> SocketPath
nodeSocket :: SocketPath
  -- ^ Path to a domain socket used to connect to the server.
  }
  deriving stock ((forall x. DirectOptions -> Rep DirectOptions x)
-> (forall x. Rep DirectOptions x -> DirectOptions)
-> Generic DirectOptions
forall x. Rep DirectOptions x -> DirectOptions
forall x. DirectOptions -> Rep DirectOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. DirectOptions -> Rep DirectOptions x
from :: forall x. DirectOptions -> Rep DirectOptions x
$cto :: forall x. Rep DirectOptions x -> DirectOptions
to :: forall x. Rep DirectOptions x -> DirectOptions
Generic, Int -> DirectOptions -> ShowS
[DirectOptions] -> ShowS
DirectOptions -> [Char]
(Int -> DirectOptions -> ShowS)
-> (DirectOptions -> [Char])
-> ([DirectOptions] -> ShowS)
-> Show DirectOptions
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DirectOptions -> ShowS
showsPrec :: Int -> DirectOptions -> ShowS
$cshow :: DirectOptions -> [Char]
show :: DirectOptions -> [Char]
$cshowList :: [DirectOptions] -> ShowS
showList :: [DirectOptions] -> ShowS
Show, DirectOptions -> DirectOptions -> Bool
(DirectOptions -> DirectOptions -> Bool)
-> (DirectOptions -> DirectOptions -> Bool) -> Eq DirectOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DirectOptions -> DirectOptions -> Bool
== :: DirectOptions -> DirectOptions -> Bool
$c/= :: DirectOptions -> DirectOptions -> Bool
/= :: DirectOptions -> DirectOptions -> Bool
Eq)
  deriving anyclass ([DirectOptions] -> Value
[DirectOptions] -> Encoding
DirectOptions -> Bool
DirectOptions -> Value
DirectOptions -> Encoding
(DirectOptions -> Value)
-> (DirectOptions -> Encoding)
-> ([DirectOptions] -> Value)
-> ([DirectOptions] -> Encoding)
-> (DirectOptions -> Bool)
-> ToJSON DirectOptions
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: DirectOptions -> Value
toJSON :: DirectOptions -> Value
$ctoEncoding :: DirectOptions -> Encoding
toEncoding :: DirectOptions -> Encoding
$ctoJSONList :: [DirectOptions] -> Value
toJSONList :: [DirectOptions] -> Value
$ctoEncodingList :: [DirectOptions] -> Encoding
toEncodingList :: [DirectOptions] -> Encoding
$comitField :: DirectOptions -> Bool
omitField :: DirectOptions -> Bool
ToJSON, Maybe DirectOptions
Value -> Parser [DirectOptions]
Value -> Parser DirectOptions
(Value -> Parser DirectOptions)
-> (Value -> Parser [DirectOptions])
-> Maybe DirectOptions
-> FromJSON DirectOptions
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser DirectOptions
parseJSON :: Value -> Parser DirectOptions
$cparseJSONList :: Value -> Parser [DirectOptions]
parseJSONList :: Value -> Parser [DirectOptions]
$comittedField :: Maybe DirectOptions
omittedField :: Maybe DirectOptions
FromJSON)

newtype BlockfrostOptions = BlockfrostOptions
  { BlockfrostOptions -> [Char]
projectPath :: FilePath
  -- ^ Path to the blockfrost project file
  }
  deriving stock ((forall x. BlockfrostOptions -> Rep BlockfrostOptions x)
-> (forall x. Rep BlockfrostOptions x -> BlockfrostOptions)
-> Generic BlockfrostOptions
forall x. Rep BlockfrostOptions x -> BlockfrostOptions
forall x. BlockfrostOptions -> Rep BlockfrostOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BlockfrostOptions -> Rep BlockfrostOptions x
from :: forall x. BlockfrostOptions -> Rep BlockfrostOptions x
$cto :: forall x. Rep BlockfrostOptions x -> BlockfrostOptions
to :: forall x. Rep BlockfrostOptions x -> BlockfrostOptions
Generic, Int -> BlockfrostOptions -> ShowS
[BlockfrostOptions] -> ShowS
BlockfrostOptions -> [Char]
(Int -> BlockfrostOptions -> ShowS)
-> (BlockfrostOptions -> [Char])
-> ([BlockfrostOptions] -> ShowS)
-> Show BlockfrostOptions
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BlockfrostOptions -> ShowS
showsPrec :: Int -> BlockfrostOptions -> ShowS
$cshow :: BlockfrostOptions -> [Char]
show :: BlockfrostOptions -> [Char]
$cshowList :: [BlockfrostOptions] -> ShowS
showList :: [BlockfrostOptions] -> ShowS
Show, BlockfrostOptions -> BlockfrostOptions -> Bool
(BlockfrostOptions -> BlockfrostOptions -> Bool)
-> (BlockfrostOptions -> BlockfrostOptions -> Bool)
-> Eq BlockfrostOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BlockfrostOptions -> BlockfrostOptions -> Bool
== :: BlockfrostOptions -> BlockfrostOptions -> Bool
$c/= :: BlockfrostOptions -> BlockfrostOptions -> Bool
/= :: BlockfrostOptions -> BlockfrostOptions -> Bool
Eq)
  deriving anyclass ([BlockfrostOptions] -> Value
[BlockfrostOptions] -> Encoding
BlockfrostOptions -> Bool
BlockfrostOptions -> Value
BlockfrostOptions -> Encoding
(BlockfrostOptions -> Value)
-> (BlockfrostOptions -> Encoding)
-> ([BlockfrostOptions] -> Value)
-> ([BlockfrostOptions] -> Encoding)
-> (BlockfrostOptions -> Bool)
-> ToJSON BlockfrostOptions
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: BlockfrostOptions -> Value
toJSON :: BlockfrostOptions -> Value
$ctoEncoding :: BlockfrostOptions -> Encoding
toEncoding :: BlockfrostOptions -> Encoding
$ctoJSONList :: [BlockfrostOptions] -> Value
toJSONList :: [BlockfrostOptions] -> Value
$ctoEncodingList :: [BlockfrostOptions] -> Encoding
toEncodingList :: [BlockfrostOptions] -> Encoding
$comitField :: BlockfrostOptions -> Bool
omitField :: BlockfrostOptions -> Bool
ToJSON, Maybe BlockfrostOptions
Value -> Parser [BlockfrostOptions]
Value -> Parser BlockfrostOptions
(Value -> Parser BlockfrostOptions)
-> (Value -> Parser [BlockfrostOptions])
-> Maybe BlockfrostOptions
-> FromJSON BlockfrostOptions
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser BlockfrostOptions
parseJSON :: Value -> Parser BlockfrostOptions
$cparseJSONList :: Value -> Parser [BlockfrostOptions]
parseJSONList :: Value -> Parser [BlockfrostOptions]
$comittedField :: Maybe BlockfrostOptions
omittedField :: Maybe BlockfrostOptions
FromJSON)

publishOptionsParser :: Parser PublishOptions
publishOptionsParser :: Parser PublishOptions
publishOptionsParser =
  ChainBackendOptions -> [Char] -> PublishOptions
PublishOptions (ChainBackendOptions -> [Char] -> PublishOptions)
-> Parser ChainBackendOptions -> Parser ([Char] -> PublishOptions)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ChainBackendOptions
chainBackendOptionsParser Parser ([Char] -> PublishOptions)
-> Parser [Char] -> Parser PublishOptions
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser [Char]
cardanoSigningKeyFileParser

data RunOptions = RunOptions
  { RunOptions -> Verbosity
verbosity :: Verbosity
  , RunOptions -> NodeId
nodeId :: NodeId
  , RunOptions -> Host
listen :: Host
  , RunOptions -> Maybe Host
advertise :: Maybe Host
  , RunOptions -> [Host]
peers :: [Host]
  , RunOptions -> IP
apiHost :: IP
  , RunOptions -> PortNumber
apiPort :: PortNumber
  , RunOptions -> Maybe [Char]
tlsCertPath :: Maybe FilePath
  , RunOptions -> Maybe [Char]
tlsKeyPath :: Maybe FilePath
  , RunOptions -> Maybe PortNumber
monitoringPort :: Maybe PortNumber
  , RunOptions -> [Char]
hydraSigningKey :: FilePath
  , RunOptions -> [[Char]]
hydraVerificationKeys :: [FilePath]
  , RunOptions -> [Char]
persistenceDir :: FilePath
  , RunOptions -> Maybe Natural
persistenceRotateAfter :: Maybe Natural
  , RunOptions -> ChainConfig
chainConfig :: ChainConfig
  , RunOptions -> LedgerConfig
ledgerConfig :: LedgerConfig
  , RunOptions -> WhichEtcd
whichEtcd :: WhichEtcd
  }
  deriving stock (RunOptions -> RunOptions -> Bool
(RunOptions -> RunOptions -> Bool)
-> (RunOptions -> RunOptions -> Bool) -> Eq RunOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RunOptions -> RunOptions -> Bool
== :: RunOptions -> RunOptions -> Bool
$c/= :: RunOptions -> RunOptions -> Bool
/= :: RunOptions -> RunOptions -> Bool
Eq, Int -> RunOptions -> ShowS
[RunOptions] -> ShowS
RunOptions -> [Char]
(Int -> RunOptions -> ShowS)
-> (RunOptions -> [Char])
-> ([RunOptions] -> ShowS)
-> Show RunOptions
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RunOptions -> ShowS
showsPrec :: Int -> RunOptions -> ShowS
$cshow :: RunOptions -> [Char]
show :: RunOptions -> [Char]
$cshowList :: [RunOptions] -> ShowS
showList :: [RunOptions] -> ShowS
Show, (forall x. RunOptions -> Rep RunOptions x)
-> (forall x. Rep RunOptions x -> RunOptions) -> Generic RunOptions
forall x. Rep RunOptions x -> RunOptions
forall x. RunOptions -> Rep RunOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. RunOptions -> Rep RunOptions x
from :: forall x. RunOptions -> Rep RunOptions x
$cto :: forall x. Rep RunOptions x -> RunOptions
to :: forall x. Rep RunOptions x -> RunOptions
Generic)
  deriving anyclass ([RunOptions] -> Value
[RunOptions] -> Encoding
RunOptions -> Bool
RunOptions -> Value
RunOptions -> Encoding
(RunOptions -> Value)
-> (RunOptions -> Encoding)
-> ([RunOptions] -> Value)
-> ([RunOptions] -> Encoding)
-> (RunOptions -> Bool)
-> ToJSON RunOptions
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: RunOptions -> Value
toJSON :: RunOptions -> Value
$ctoEncoding :: RunOptions -> Encoding
toEncoding :: RunOptions -> Encoding
$ctoJSONList :: [RunOptions] -> Value
toJSONList :: [RunOptions] -> Value
$ctoEncodingList :: [RunOptions] -> Encoding
toEncodingList :: [RunOptions] -> Encoding
$comitField :: RunOptions -> Bool
omitField :: RunOptions -> Bool
ToJSON, Maybe RunOptions
Value -> Parser [RunOptions]
Value -> Parser RunOptions
(Value -> Parser RunOptions)
-> (Value -> Parser [RunOptions])
-> Maybe RunOptions
-> FromJSON RunOptions
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser RunOptions
parseJSON :: Value -> Parser RunOptions
$cparseJSONList :: Value -> Parser [RunOptions]
parseJSONList :: Value -> Parser [RunOptions]
$comittedField :: Maybe RunOptions
omittedField :: Maybe RunOptions
FromJSON)

-- Orphan instance
instance Arbitrary IP where
  arbitrary :: Gen IP
arbitrary = IPv4 -> IP
IPv4 (IPv4 -> IP) -> (Word32 -> IPv4) -> Word32 -> IP
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> IPv4
toIPv4w (Word32 -> IP) -> Gen Word32 -> Gen IP
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Word32
forall a. Arbitrary a => Gen a
arbitrary
  shrink :: IP -> [IP]
shrink = IP -> [IP]
forall a.
(Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) =>
a -> [a]
genericShrink

instance Arbitrary RunOptions where
  arbitrary :: Gen RunOptions
arbitrary = do
    Verbosity
verbosity <- [Verbosity] -> Gen Verbosity
forall a. HasCallStack => [a] -> Gen a
elements [Verbosity
Quiet, Text -> Verbosity
Verbose Text
"HydraNode"]
    NodeId
nodeId <- Gen NodeId
forall a. Arbitrary a => Gen a
arbitrary
    Host
listen <- Gen Host
forall a. Arbitrary a => Gen a
arbitrary
    Maybe Host
advertise <- Gen (Maybe Host)
forall a. Arbitrary a => Gen a
arbitrary
    [Host]
peers <- Gen [Host] -> Gen [Host]
forall a. Gen a -> Gen a
reasonablySized Gen [Host]
forall a. Arbitrary a => Gen a
arbitrary
    IP
apiHost <- Gen IP
forall a. Arbitrary a => Gen a
arbitrary
    PortNumber
apiPort <- Gen PortNumber
forall a. Arbitrary a => Gen a
arbitrary
    Maybe [Char]
tlsCertPath <- [Gen (Maybe [Char])] -> Gen (Maybe [Char])
forall a. HasCallStack => [Gen a] -> Gen a
oneof [Maybe [Char] -> Gen (Maybe [Char])
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe [Char]
forall a. Maybe a
Nothing, [Char] -> Maybe [Char]
forall a. a -> Maybe a
Just ([Char] -> Maybe [Char]) -> Gen [Char] -> Gen (Maybe [Char])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Char] -> Gen [Char]
genFilePath [Char]
"pem"]
    Maybe [Char]
tlsKeyPath <- [Gen (Maybe [Char])] -> Gen (Maybe [Char])
forall a. HasCallStack => [Gen a] -> Gen a
oneof [Maybe [Char] -> Gen (Maybe [Char])
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe [Char]
forall a. Maybe a
Nothing, [Char] -> Maybe [Char]
forall a. a -> Maybe a
Just ([Char] -> Maybe [Char]) -> Gen [Char] -> Gen (Maybe [Char])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Char] -> Gen [Char]
genFilePath [Char]
"key"]
    Maybe PortNumber
monitoringPort <- Gen (Maybe PortNumber)
forall a. Arbitrary a => Gen a
arbitrary
    [Char]
hydraSigningKey <- [Char] -> Gen [Char]
genFilePath [Char]
"sk"
    [[Char]]
hydraVerificationKeys <- Gen [[Char]] -> Gen [[Char]]
forall a. Gen a -> Gen a
reasonablySized (Gen [Char] -> Gen [[Char]]
forall a. Gen a -> Gen [a]
listOf ([Char] -> Gen [Char]
genFilePath [Char]
"vk"))
    [Char]
persistenceDir <- Gen [Char]
genDirPath
    Maybe Natural
persistenceRotateAfter <- Gen (Maybe Natural)
forall a. Arbitrary a => Gen a
arbitrary
    ChainConfig
chainConfig <- Gen ChainConfig
forall a. Arbitrary a => Gen a
arbitrary
    LedgerConfig
ledgerConfig <- Gen LedgerConfig
forall a. Arbitrary a => Gen a
arbitrary
    WhichEtcd
whichEtcd <- Gen WhichEtcd
forall a. Arbitrary a => Gen a
arbitrary
    pure $
      RunOptions
        { Verbosity
$sel:verbosity:RunOptions :: Verbosity
verbosity :: Verbosity
verbosity
        , NodeId
$sel:nodeId:RunOptions :: NodeId
nodeId :: NodeId
nodeId
        , Host
$sel:listen:RunOptions :: Host
listen :: Host
listen
        , Maybe Host
$sel:advertise:RunOptions :: Maybe Host
advertise :: Maybe Host
advertise
        , [Host]
$sel:peers:RunOptions :: [Host]
peers :: [Host]
peers
        , IP
$sel:apiHost:RunOptions :: IP
apiHost :: IP
apiHost
        , PortNumber
$sel:apiPort:RunOptions :: PortNumber
apiPort :: PortNumber
apiPort
        , Maybe [Char]
$sel:tlsCertPath:RunOptions :: Maybe [Char]
tlsCertPath :: Maybe [Char]
tlsCertPath
        , Maybe [Char]
$sel:tlsKeyPath:RunOptions :: Maybe [Char]
tlsKeyPath :: Maybe [Char]
tlsKeyPath
        , Maybe PortNumber
$sel:monitoringPort:RunOptions :: Maybe PortNumber
monitoringPort :: Maybe PortNumber
monitoringPort
        , [Char]
$sel:hydraSigningKey:RunOptions :: [Char]
hydraSigningKey :: [Char]
hydraSigningKey
        , [[Char]]
$sel:hydraVerificationKeys:RunOptions :: [[Char]]
hydraVerificationKeys :: [[Char]]
hydraVerificationKeys
        , [Char]
$sel:persistenceDir:RunOptions :: [Char]
persistenceDir :: [Char]
persistenceDir
        , Maybe Natural
$sel:persistenceRotateAfter:RunOptions :: Maybe Natural
persistenceRotateAfter :: Maybe Natural
persistenceRotateAfter
        , ChainConfig
$sel:chainConfig:RunOptions :: ChainConfig
chainConfig :: ChainConfig
chainConfig
        , LedgerConfig
$sel:ledgerConfig:RunOptions :: LedgerConfig
ledgerConfig :: LedgerConfig
ledgerConfig
        , WhichEtcd
$sel:whichEtcd:RunOptions :: WhichEtcd
whichEtcd :: WhichEtcd
whichEtcd
        }

  shrink :: RunOptions -> [RunOptions]
shrink = RunOptions -> [RunOptions]
forall a.
(Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) =>
a -> [a]
genericShrink

-- | Default options as they should also be provided by 'runOptionsParser'.
defaultRunOptions :: RunOptions
defaultRunOptions :: RunOptions
defaultRunOptions =
  RunOptions
    { $sel:verbosity:RunOptions :: Verbosity
verbosity = Text -> Verbosity
Verbose Text
"HydraNode"
    , $sel:nodeId:RunOptions :: NodeId
nodeId = Text -> NodeId
NodeId Text
"hydra-node-1"
    , $sel:listen:RunOptions :: Host
listen = Text -> PortNumber -> Host
Host Text
"0.0.0.0" PortNumber
5001
    , $sel:advertise:RunOptions :: Maybe Host
advertise = Maybe Host
forall a. Maybe a
Nothing
    , $sel:peers:RunOptions :: [Host]
peers = []
    , $sel:apiHost:RunOptions :: IP
apiHost = IP
localhost
    , $sel:apiPort:RunOptions :: PortNumber
apiPort = PortNumber
4001
    , $sel:tlsCertPath:RunOptions :: Maybe [Char]
tlsCertPath = Maybe [Char]
forall a. Maybe a
Nothing
    , $sel:tlsKeyPath:RunOptions :: Maybe [Char]
tlsKeyPath = Maybe [Char]
forall a. Maybe a
Nothing
    , $sel:monitoringPort:RunOptions :: Maybe PortNumber
monitoringPort = Maybe PortNumber
forall a. Maybe a
Nothing
    , $sel:hydraSigningKey:RunOptions :: [Char]
hydraSigningKey = [Char]
"hydra.sk"
    , $sel:hydraVerificationKeys:RunOptions :: [[Char]]
hydraVerificationKeys = []
    , $sel:persistenceDir:RunOptions :: [Char]
persistenceDir = [Char]
"./"
    , $sel:persistenceRotateAfter:RunOptions :: Maybe Natural
persistenceRotateAfter = Maybe Natural
forall a. Maybe a
Nothing
    , $sel:chainConfig:RunOptions :: ChainConfig
chainConfig = CardanoChainConfig -> ChainConfig
Cardano CardanoChainConfig
defaultCardanoChainConfig
    , $sel:ledgerConfig:RunOptions :: LedgerConfig
ledgerConfig = LedgerConfig
defaultLedgerConfig
    , $sel:whichEtcd:RunOptions :: WhichEtcd
whichEtcd = WhichEtcd
EmbeddedEtcd
    }
 where
  localhost :: IP
localhost = IPv4 -> IP
IPv4 (IPv4 -> IP) -> IPv4 -> IP
forall a b. (a -> b) -> a -> b
$ [Int] -> IPv4
toIPv4 [Int
127, Int
0, Int
0, Int
1]

-- | Parser for running the cardano-node with all its 'RunOptions'.
runOptionsParser :: Parser RunOptions
runOptionsParser :: Parser RunOptions
runOptionsParser =
  Verbosity
-> NodeId
-> Host
-> Maybe Host
-> [Host]
-> IP
-> PortNumber
-> Maybe [Char]
-> Maybe [Char]
-> Maybe PortNumber
-> [Char]
-> [[Char]]
-> [Char]
-> Maybe Natural
-> ChainConfig
-> LedgerConfig
-> WhichEtcd
-> RunOptions
RunOptions
    (Verbosity
 -> NodeId
 -> Host
 -> Maybe Host
 -> [Host]
 -> IP
 -> PortNumber
 -> Maybe [Char]
 -> Maybe [Char]
 -> Maybe PortNumber
 -> [Char]
 -> [[Char]]
 -> [Char]
 -> Maybe Natural
 -> ChainConfig
 -> LedgerConfig
 -> WhichEtcd
 -> RunOptions)
-> Parser Verbosity
-> Parser
     (NodeId
      -> Host
      -> Maybe Host
      -> [Host]
      -> IP
      -> PortNumber
      -> Maybe [Char]
      -> Maybe [Char]
      -> Maybe PortNumber
      -> [Char]
      -> [[Char]]
      -> [Char]
      -> Maybe Natural
      -> ChainConfig
      -> LedgerConfig
      -> WhichEtcd
      -> RunOptions)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Verbosity
verbosityParser
    Parser
  (NodeId
   -> Host
   -> Maybe Host
   -> [Host]
   -> IP
   -> PortNumber
   -> Maybe [Char]
   -> Maybe [Char]
   -> Maybe PortNumber
   -> [Char]
   -> [[Char]]
   -> [Char]
   -> Maybe Natural
   -> ChainConfig
   -> LedgerConfig
   -> WhichEtcd
   -> RunOptions)
-> Parser NodeId
-> Parser
     (Host
      -> Maybe Host
      -> [Host]
      -> IP
      -> PortNumber
      -> Maybe [Char]
      -> Maybe [Char]
      -> Maybe PortNumber
      -> [Char]
      -> [[Char]]
      -> [Char]
      -> Maybe Natural
      -> ChainConfig
      -> LedgerConfig
      -> WhichEtcd
      -> RunOptions)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser NodeId
nodeIdParser
    Parser
  (Host
   -> Maybe Host
   -> [Host]
   -> IP
   -> PortNumber
   -> Maybe [Char]
   -> Maybe [Char]
   -> Maybe PortNumber
   -> [Char]
   -> [[Char]]
   -> [Char]
   -> Maybe Natural
   -> ChainConfig
   -> LedgerConfig
   -> WhichEtcd
   -> RunOptions)
-> Parser Host
-> Parser
     (Maybe Host
      -> [Host]
      -> IP
      -> PortNumber
      -> Maybe [Char]
      -> Maybe [Char]
      -> Maybe PortNumber
      -> [Char]
      -> [[Char]]
      -> [Char]
      -> Maybe Natural
      -> ChainConfig
      -> LedgerConfig
      -> WhichEtcd
      -> RunOptions)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Host
listenParser
    Parser
  (Maybe Host
   -> [Host]
   -> IP
   -> PortNumber
   -> Maybe [Char]
   -> Maybe [Char]
   -> Maybe PortNumber
   -> [Char]
   -> [[Char]]
   -> [Char]
   -> Maybe Natural
   -> ChainConfig
   -> LedgerConfig
   -> WhichEtcd
   -> RunOptions)
-> Parser (Maybe Host)
-> Parser
     ([Host]
      -> IP
      -> PortNumber
      -> Maybe [Char]
      -> Maybe [Char]
      -> Maybe PortNumber
      -> [Char]
      -> [[Char]]
      -> [Char]
      -> Maybe Natural
      -> ChainConfig
      -> LedgerConfig
      -> WhichEtcd
      -> RunOptions)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Host -> Parser (Maybe Host)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser Host
advertiseParser
    Parser
  ([Host]
   -> IP
   -> PortNumber
   -> Maybe [Char]
   -> Maybe [Char]
   -> Maybe PortNumber
   -> [Char]
   -> [[Char]]
   -> [Char]
   -> Maybe Natural
   -> ChainConfig
   -> LedgerConfig
   -> WhichEtcd
   -> RunOptions)
-> Parser [Host]
-> Parser
     (IP
      -> PortNumber
      -> Maybe [Char]
      -> Maybe [Char]
      -> Maybe PortNumber
      -> [Char]
      -> [[Char]]
      -> [Char]
      -> Maybe Natural
      -> ChainConfig
      -> LedgerConfig
      -> WhichEtcd
      -> RunOptions)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Host -> Parser [Host]
forall a. Parser a -> Parser [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many Parser Host
peerParser
    Parser
  (IP
   -> PortNumber
   -> Maybe [Char]
   -> Maybe [Char]
   -> Maybe PortNumber
   -> [Char]
   -> [[Char]]
   -> [Char]
   -> Maybe Natural
   -> ChainConfig
   -> LedgerConfig
   -> WhichEtcd
   -> RunOptions)
-> Parser IP
-> Parser
     (PortNumber
      -> Maybe [Char]
      -> Maybe [Char]
      -> Maybe PortNumber
      -> [Char]
      -> [[Char]]
      -> [Char]
      -> Maybe Natural
      -> ChainConfig
      -> LedgerConfig
      -> WhichEtcd
      -> RunOptions)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser IP
apiHostParser
    Parser
  (PortNumber
   -> Maybe [Char]
   -> Maybe [Char]
   -> Maybe PortNumber
   -> [Char]
   -> [[Char]]
   -> [Char]
   -> Maybe Natural
   -> ChainConfig
   -> LedgerConfig
   -> WhichEtcd
   -> RunOptions)
-> Parser PortNumber
-> Parser
     (Maybe [Char]
      -> Maybe [Char]
      -> Maybe PortNumber
      -> [Char]
      -> [[Char]]
      -> [Char]
      -> Maybe Natural
      -> ChainConfig
      -> LedgerConfig
      -> WhichEtcd
      -> RunOptions)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser PortNumber
apiPortParser
    Parser
  (Maybe [Char]
   -> Maybe [Char]
   -> Maybe PortNumber
   -> [Char]
   -> [[Char]]
   -> [Char]
   -> Maybe Natural
   -> ChainConfig
   -> LedgerConfig
   -> WhichEtcd
   -> RunOptions)
-> Parser (Maybe [Char])
-> Parser
     (Maybe [Char]
      -> Maybe PortNumber
      -> [Char]
      -> [[Char]]
      -> [Char]
      -> Maybe Natural
      -> ChainConfig
      -> LedgerConfig
      -> WhichEtcd
      -> RunOptions)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser [Char] -> Parser (Maybe [Char])
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser [Char]
tlsCertPathParser
    Parser
  (Maybe [Char]
   -> Maybe PortNumber
   -> [Char]
   -> [[Char]]
   -> [Char]
   -> Maybe Natural
   -> ChainConfig
   -> LedgerConfig
   -> WhichEtcd
   -> RunOptions)
-> Parser (Maybe [Char])
-> Parser
     (Maybe PortNumber
      -> [Char]
      -> [[Char]]
      -> [Char]
      -> Maybe Natural
      -> ChainConfig
      -> LedgerConfig
      -> WhichEtcd
      -> RunOptions)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser [Char] -> Parser (Maybe [Char])
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser [Char]
tlsKeyPathParser
    Parser
  (Maybe PortNumber
   -> [Char]
   -> [[Char]]
   -> [Char]
   -> Maybe Natural
   -> ChainConfig
   -> LedgerConfig
   -> WhichEtcd
   -> RunOptions)
-> Parser (Maybe PortNumber)
-> Parser
     ([Char]
      -> [[Char]]
      -> [Char]
      -> Maybe Natural
      -> ChainConfig
      -> LedgerConfig
      -> WhichEtcd
      -> RunOptions)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser PortNumber -> Parser (Maybe PortNumber)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser PortNumber
monitoringPortParser
    Parser
  ([Char]
   -> [[Char]]
   -> [Char]
   -> Maybe Natural
   -> ChainConfig
   -> LedgerConfig
   -> WhichEtcd
   -> RunOptions)
-> Parser [Char]
-> Parser
     ([[Char]]
      -> [Char]
      -> Maybe Natural
      -> ChainConfig
      -> LedgerConfig
      -> WhichEtcd
      -> RunOptions)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser [Char]
hydraSigningKeyFileParser
    Parser
  ([[Char]]
   -> [Char]
   -> Maybe Natural
   -> ChainConfig
   -> LedgerConfig
   -> WhichEtcd
   -> RunOptions)
-> Parser [[Char]]
-> Parser
     ([Char]
      -> Maybe Natural
      -> ChainConfig
      -> LedgerConfig
      -> WhichEtcd
      -> RunOptions)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser [Char] -> Parser [[Char]]
forall a. Parser a -> Parser [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many Parser [Char]
hydraVerificationKeyFileParser
    Parser
  ([Char]
   -> Maybe Natural
   -> ChainConfig
   -> LedgerConfig
   -> WhichEtcd
   -> RunOptions)
-> Parser [Char]
-> Parser
     (Maybe Natural
      -> ChainConfig -> LedgerConfig -> WhichEtcd -> RunOptions)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser [Char]
persistenceDirParser
    Parser
  (Maybe Natural
   -> ChainConfig -> LedgerConfig -> WhichEtcd -> RunOptions)
-> Parser (Maybe Natural)
-> Parser (ChainConfig -> LedgerConfig -> WhichEtcd -> RunOptions)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Natural -> Parser (Maybe Natural)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser Natural
persistenceRotateAfterParser
    Parser (ChainConfig -> LedgerConfig -> WhichEtcd -> RunOptions)
-> Parser ChainConfig
-> Parser (LedgerConfig -> WhichEtcd -> RunOptions)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ChainConfig
chainConfigParser
    Parser (LedgerConfig -> WhichEtcd -> RunOptions)
-> Parser LedgerConfig -> Parser (WhichEtcd -> RunOptions)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser LedgerConfig
ledgerConfigParser
    Parser (WhichEtcd -> RunOptions)
-> Parser WhichEtcd -> Parser RunOptions
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser WhichEtcd
whichEtcdParser

whichEtcdParser :: Parser WhichEtcd
whichEtcdParser :: Parser WhichEtcd
whichEtcdParser =
  WhichEtcd
-> WhichEtcd -> Mod FlagFields WhichEtcd -> Parser WhichEtcd
forall a. a -> a -> Mod FlagFields a -> Parser a
flag
    WhichEtcd
EmbeddedEtcd
    WhichEtcd
SystemEtcd
    ( [Char] -> Mod FlagFields WhichEtcd
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"use-system-etcd"
        Mod FlagFields WhichEtcd
-> Mod FlagFields WhichEtcd -> Mod FlagFields WhichEtcd
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod FlagFields WhichEtcd
forall (f :: * -> *) a. [Char] -> Mod f a
help [Char]
"Use the `etcd` binary found on the path instead of the embedded one."
    )

chainConfigParser :: Parser ChainConfig
chainConfigParser :: Parser ChainConfig
chainConfigParser =
  CardanoChainConfig -> ChainConfig
Cardano (CardanoChainConfig -> ChainConfig)
-> Parser CardanoChainConfig -> Parser ChainConfig
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser CardanoChainConfig
cardanoChainConfigParser
    Parser ChainConfig -> Parser ChainConfig -> Parser ChainConfig
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> OfflineChainConfig -> ChainConfig
Offline (OfflineChainConfig -> ChainConfig)
-> Parser OfflineChainConfig -> Parser ChainConfig
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser OfflineChainConfig
offlineChainConfigParser

chainBackendOptionsParser :: Parser ChainBackendOptions
chainBackendOptionsParser :: Parser ChainBackendOptions
chainBackendOptionsParser = Parser ChainBackendOptions
directOptionsParser Parser ChainBackendOptions
-> Parser ChainBackendOptions -> Parser ChainBackendOptions
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser ChainBackendOptions
blockfrostOptionsParser
 where
  directOptionsParser :: Parser ChainBackendOptions
directOptionsParser =
    (DirectOptions -> ChainBackendOptions)
-> Parser DirectOptions -> Parser ChainBackendOptions
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DirectOptions -> ChainBackendOptions
Direct (Parser DirectOptions -> Parser ChainBackendOptions)
-> Parser DirectOptions -> Parser ChainBackendOptions
forall a b. (a -> b) -> a -> b
$
      NetworkId -> SocketPath -> DirectOptions
DirectOptions
        (NetworkId -> SocketPath -> DirectOptions)
-> Parser NetworkId -> Parser (SocketPath -> DirectOptions)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NetworkId
networkIdParser
        Parser (SocketPath -> DirectOptions)
-> Parser SocketPath -> Parser DirectOptions
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser SocketPath
nodeSocketParser

  blockfrostOptionsParser :: Parser ChainBackendOptions
blockfrostOptionsParser =
    (BlockfrostOptions -> ChainBackendOptions)
-> Parser BlockfrostOptions -> Parser ChainBackendOptions
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap BlockfrostOptions -> ChainBackendOptions
Blockfrost (Parser BlockfrostOptions -> Parser ChainBackendOptions)
-> Parser BlockfrostOptions -> Parser ChainBackendOptions
forall a b. (a -> b) -> a -> b
$
      [Char] -> BlockfrostOptions
BlockfrostOptions
        ([Char] -> BlockfrostOptions)
-> Parser [Char] -> Parser BlockfrostOptions
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Char]
blockfrostProjectPathParser

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

outputFileParser :: Parser FilePath
outputFileParser :: Parser [Char]
outputFileParser =
  Mod OptionFields [Char] -> Parser [Char]
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
    ( [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"output-file"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"FILE"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value [Char]
"hydra-key"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. [Char] -> Mod f a
help [Char]
"Basename of files to generate key-pair into. Signing key will be suffixed '.sk' and verification key '.vk'"
    )

newtype LedgerConfig = CardanoLedgerConfig
  { LedgerConfig -> [Char]
cardanoLedgerProtocolParametersFile :: FilePath
  }
  deriving stock (LedgerConfig -> LedgerConfig -> Bool
(LedgerConfig -> LedgerConfig -> Bool)
-> (LedgerConfig -> LedgerConfig -> Bool) -> Eq LedgerConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LedgerConfig -> LedgerConfig -> Bool
== :: LedgerConfig -> LedgerConfig -> Bool
$c/= :: LedgerConfig -> LedgerConfig -> Bool
/= :: LedgerConfig -> LedgerConfig -> Bool
Eq, Int -> LedgerConfig -> ShowS
[LedgerConfig] -> ShowS
LedgerConfig -> [Char]
(Int -> LedgerConfig -> ShowS)
-> (LedgerConfig -> [Char])
-> ([LedgerConfig] -> ShowS)
-> Show LedgerConfig
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LedgerConfig -> ShowS
showsPrec :: Int -> LedgerConfig -> ShowS
$cshow :: LedgerConfig -> [Char]
show :: LedgerConfig -> [Char]
$cshowList :: [LedgerConfig] -> ShowS
showList :: [LedgerConfig] -> ShowS
Show, (forall x. LedgerConfig -> Rep LedgerConfig x)
-> (forall x. Rep LedgerConfig x -> LedgerConfig)
-> Generic LedgerConfig
forall x. Rep LedgerConfig x -> LedgerConfig
forall x. LedgerConfig -> Rep LedgerConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. LedgerConfig -> Rep LedgerConfig x
from :: forall x. LedgerConfig -> Rep LedgerConfig x
$cto :: forall x. Rep LedgerConfig x -> LedgerConfig
to :: forall x. Rep LedgerConfig x -> LedgerConfig
Generic)
  deriving anyclass ([LedgerConfig] -> Value
[LedgerConfig] -> Encoding
LedgerConfig -> Bool
LedgerConfig -> Value
LedgerConfig -> Encoding
(LedgerConfig -> Value)
-> (LedgerConfig -> Encoding)
-> ([LedgerConfig] -> Value)
-> ([LedgerConfig] -> Encoding)
-> (LedgerConfig -> Bool)
-> ToJSON LedgerConfig
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: LedgerConfig -> Value
toJSON :: LedgerConfig -> Value
$ctoEncoding :: LedgerConfig -> Encoding
toEncoding :: LedgerConfig -> Encoding
$ctoJSONList :: [LedgerConfig] -> Value
toJSONList :: [LedgerConfig] -> Value
$ctoEncodingList :: [LedgerConfig] -> Encoding
toEncodingList :: [LedgerConfig] -> Encoding
$comitField :: LedgerConfig -> Bool
omitField :: LedgerConfig -> Bool
ToJSON, Maybe LedgerConfig
Value -> Parser [LedgerConfig]
Value -> Parser LedgerConfig
(Value -> Parser LedgerConfig)
-> (Value -> Parser [LedgerConfig])
-> Maybe LedgerConfig
-> FromJSON LedgerConfig
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser LedgerConfig
parseJSON :: Value -> Parser LedgerConfig
$cparseJSONList :: Value -> Parser [LedgerConfig]
parseJSONList :: Value -> Parser [LedgerConfig]
$comittedField :: Maybe LedgerConfig
omittedField :: Maybe LedgerConfig
FromJSON)

defaultLedgerConfig :: LedgerConfig
defaultLedgerConfig :: LedgerConfig
defaultLedgerConfig =
  CardanoLedgerConfig
    { $sel:cardanoLedgerProtocolParametersFile:CardanoLedgerConfig :: [Char]
cardanoLedgerProtocolParametersFile = [Char]
"protocol-parameters.json"
    }

instance Arbitrary LedgerConfig where
  arbitrary :: Gen LedgerConfig
arbitrary = do
    [Char]
cardanoLedgerProtocolParametersFile <- [Char] -> Gen [Char]
genFilePath [Char]
"json"
    pure $ CardanoLedgerConfig{[Char]
$sel:cardanoLedgerProtocolParametersFile:CardanoLedgerConfig :: [Char]
cardanoLedgerProtocolParametersFile :: [Char]
cardanoLedgerProtocolParametersFile}

ledgerConfigParser :: Parser LedgerConfig
ledgerConfigParser :: Parser LedgerConfig
ledgerConfigParser =
  [Char] -> LedgerConfig
CardanoLedgerConfig
    ([Char] -> LedgerConfig) -> Parser [Char] -> Parser LedgerConfig
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Char]
cardanoLedgerProtocolParametersParser

cardanoLedgerProtocolParametersParser :: Parser FilePath
cardanoLedgerProtocolParametersParser :: Parser [Char]
cardanoLedgerProtocolParametersParser =
  Mod OptionFields [Char] -> Parser [Char]
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
    ( [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"ledger-protocol-parameters"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"FILE"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value [Char]
"protocol-parameters.json"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields [Char]
forall a (f :: * -> *). Show a => Mod f a
showDefault
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. [Char] -> Mod f a
help
          [Char]
"Path to protocol parameters used in the Hydra Head. \
          \See manual how to configure this."
    )

data ChainConfig
  = Offline OfflineChainConfig
  | Cardano CardanoChainConfig
  deriving stock (ChainConfig -> ChainConfig -> Bool
(ChainConfig -> ChainConfig -> Bool)
-> (ChainConfig -> ChainConfig -> Bool) -> Eq ChainConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChainConfig -> ChainConfig -> Bool
== :: ChainConfig -> ChainConfig -> Bool
$c/= :: ChainConfig -> ChainConfig -> Bool
/= :: ChainConfig -> ChainConfig -> Bool
Eq, Int -> ChainConfig -> ShowS
[ChainConfig] -> ShowS
ChainConfig -> [Char]
(Int -> ChainConfig -> ShowS)
-> (ChainConfig -> [Char])
-> ([ChainConfig] -> ShowS)
-> Show ChainConfig
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChainConfig -> ShowS
showsPrec :: Int -> ChainConfig -> ShowS
$cshow :: ChainConfig -> [Char]
show :: ChainConfig -> [Char]
$cshowList :: [ChainConfig] -> ShowS
showList :: [ChainConfig] -> ShowS
Show, (forall x. ChainConfig -> Rep ChainConfig x)
-> (forall x. Rep ChainConfig x -> ChainConfig)
-> Generic ChainConfig
forall x. Rep ChainConfig x -> ChainConfig
forall x. ChainConfig -> Rep ChainConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ChainConfig -> Rep ChainConfig x
from :: forall x. ChainConfig -> Rep ChainConfig x
$cto :: forall x. Rep ChainConfig x -> ChainConfig
to :: forall x. Rep ChainConfig x -> ChainConfig
Generic)

instance ToJSON ChainConfig where
  toJSON :: ChainConfig -> Value
toJSON = \case
    Offline OfflineChainConfig
cfg -> OfflineChainConfig -> Value
forall a. ToJSON a => a -> Value
toJSON OfflineChainConfig
cfg Value -> (Value -> Value) -> Value
forall a b. a -> (a -> b) -> b
& Key -> Traversal' Value (Maybe Value)
forall t. AsValue t => Key -> Traversal' t (Maybe Value)
atKey Key
"tag" ((Maybe Value -> Identity (Maybe Value))
 -> Value -> Identity Value)
-> Value -> Value -> Value
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Text -> Value
String Text
"OfflineChainConfig"
    Cardano CardanoChainConfig
cfg -> CardanoChainConfig -> Value
forall a. ToJSON a => a -> Value
toJSON CardanoChainConfig
cfg Value -> (Value -> Value) -> Value
forall a b. a -> (a -> b) -> b
& Key -> Traversal' Value (Maybe Value)
forall t. AsValue t => Key -> Traversal' t (Maybe Value)
atKey Key
"tag" ((Maybe Value -> Identity (Maybe Value))
 -> Value -> Identity Value)
-> Value -> Value -> Value
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Text -> Value
String Text
"CardanoChainConfig"

instance FromJSON ChainConfig where
  parseJSON :: Value -> Parser ChainConfig
parseJSON =
    [Char]
-> (Object -> Parser ChainConfig) -> Value -> Parser ChainConfig
forall a. [Char] -> (Object -> Parser a) -> Value -> Parser a
withObject [Char]
"ChainConfig" ((Object -> Parser ChainConfig) -> Value -> Parser ChainConfig)
-> (Object -> Parser ChainConfig) -> Value -> Parser ChainConfig
forall a b. (a -> b) -> a -> b
$ \Object
o ->
      Object
o Object -> Key -> Parser [Char]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"tag" Parser [Char]
-> ([Char] -> Parser ChainConfig) -> Parser ChainConfig
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
        [Char]
"OfflineChainConfig" -> OfflineChainConfig -> ChainConfig
Offline (OfflineChainConfig -> ChainConfig)
-> Parser OfflineChainConfig -> Parser ChainConfig
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser OfflineChainConfig
forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
        [Char]
"CardanoChainConfig" -> CardanoChainConfig -> ChainConfig
Cardano (CardanoChainConfig -> ChainConfig)
-> Parser CardanoChainConfig -> Parser ChainConfig
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser CardanoChainConfig
forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
o)
        [Char]
tag -> [Char] -> Parser ChainConfig
forall a. [Char] -> Parser a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ([Char] -> Parser ChainConfig) -> [Char] -> Parser ChainConfig
forall a b. (a -> b) -> a -> b
$ [Char]
"unexpected tag " [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> [Char]
tag

data OfflineChainConfig = OfflineChainConfig
  { OfflineChainConfig -> HeadSeed
offlineHeadSeed :: HeadSeed
  -- ^ Manually provided seed of the offline head.
  , OfflineChainConfig -> [Char]
initialUTxOFile :: FilePath
  -- ^ Path to a json encoded starting 'UTxO' for the offline-mode head.
  , OfflineChainConfig -> Maybe [Char]
ledgerGenesisFile :: Maybe FilePath
  -- ^ Path to a shelley genesis file with slot lengths used by the offline-mode chain.
  }
  deriving stock (OfflineChainConfig -> OfflineChainConfig -> Bool
(OfflineChainConfig -> OfflineChainConfig -> Bool)
-> (OfflineChainConfig -> OfflineChainConfig -> Bool)
-> Eq OfflineChainConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: OfflineChainConfig -> OfflineChainConfig -> Bool
== :: OfflineChainConfig -> OfflineChainConfig -> Bool
$c/= :: OfflineChainConfig -> OfflineChainConfig -> Bool
/= :: OfflineChainConfig -> OfflineChainConfig -> Bool
Eq, Int -> OfflineChainConfig -> ShowS
[OfflineChainConfig] -> ShowS
OfflineChainConfig -> [Char]
(Int -> OfflineChainConfig -> ShowS)
-> (OfflineChainConfig -> [Char])
-> ([OfflineChainConfig] -> ShowS)
-> Show OfflineChainConfig
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> OfflineChainConfig -> ShowS
showsPrec :: Int -> OfflineChainConfig -> ShowS
$cshow :: OfflineChainConfig -> [Char]
show :: OfflineChainConfig -> [Char]
$cshowList :: [OfflineChainConfig] -> ShowS
showList :: [OfflineChainConfig] -> ShowS
Show, (forall x. OfflineChainConfig -> Rep OfflineChainConfig x)
-> (forall x. Rep OfflineChainConfig x -> OfflineChainConfig)
-> Generic OfflineChainConfig
forall x. Rep OfflineChainConfig x -> OfflineChainConfig
forall x. OfflineChainConfig -> Rep OfflineChainConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. OfflineChainConfig -> Rep OfflineChainConfig x
from :: forall x. OfflineChainConfig -> Rep OfflineChainConfig x
$cto :: forall x. Rep OfflineChainConfig x -> OfflineChainConfig
to :: forall x. Rep OfflineChainConfig x -> OfflineChainConfig
Generic)
  deriving anyclass ([OfflineChainConfig] -> Value
[OfflineChainConfig] -> Encoding
OfflineChainConfig -> Bool
OfflineChainConfig -> Value
OfflineChainConfig -> Encoding
(OfflineChainConfig -> Value)
-> (OfflineChainConfig -> Encoding)
-> ([OfflineChainConfig] -> Value)
-> ([OfflineChainConfig] -> Encoding)
-> (OfflineChainConfig -> Bool)
-> ToJSON OfflineChainConfig
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: OfflineChainConfig -> Value
toJSON :: OfflineChainConfig -> Value
$ctoEncoding :: OfflineChainConfig -> Encoding
toEncoding :: OfflineChainConfig -> Encoding
$ctoJSONList :: [OfflineChainConfig] -> Value
toJSONList :: [OfflineChainConfig] -> Value
$ctoEncodingList :: [OfflineChainConfig] -> Encoding
toEncodingList :: [OfflineChainConfig] -> Encoding
$comitField :: OfflineChainConfig -> Bool
omitField :: OfflineChainConfig -> Bool
ToJSON, Maybe OfflineChainConfig
Value -> Parser [OfflineChainConfig]
Value -> Parser OfflineChainConfig
(Value -> Parser OfflineChainConfig)
-> (Value -> Parser [OfflineChainConfig])
-> Maybe OfflineChainConfig
-> FromJSON OfflineChainConfig
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser OfflineChainConfig
parseJSON :: Value -> Parser OfflineChainConfig
$cparseJSONList :: Value -> Parser [OfflineChainConfig]
parseJSONList :: Value -> Parser [OfflineChainConfig]
$comittedField :: Maybe OfflineChainConfig
omittedField :: Maybe OfflineChainConfig
FromJSON)

data CardanoChainConfig = CardanoChainConfig
  { CardanoChainConfig -> [TxId]
hydraScriptsTxId :: [TxId]
  -- ^ Identifier of transaction holding the hydra scripts to use.
  , CardanoChainConfig -> [Char]
cardanoSigningKey :: FilePath
  -- ^ Path to the cardano signing key of the internal wallet.
  , CardanoChainConfig -> [[Char]]
cardanoVerificationKeys :: [FilePath]
  -- ^ Paths to other node's verification keys.
  , CardanoChainConfig -> Maybe ChainPoint
startChainFrom :: Maybe ChainPoint
  -- ^ Point at which to start following the chain.
  , CardanoChainConfig -> ContestationPeriod
contestationPeriod :: ContestationPeriod
  , CardanoChainConfig -> DepositPeriod
depositPeriod :: DepositPeriod
  , CardanoChainConfig -> ChainBackendOptions
chainBackendOptions :: ChainBackendOptions
  }
  deriving stock (CardanoChainConfig -> CardanoChainConfig -> Bool
(CardanoChainConfig -> CardanoChainConfig -> Bool)
-> (CardanoChainConfig -> CardanoChainConfig -> Bool)
-> Eq CardanoChainConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CardanoChainConfig -> CardanoChainConfig -> Bool
== :: CardanoChainConfig -> CardanoChainConfig -> Bool
$c/= :: CardanoChainConfig -> CardanoChainConfig -> Bool
/= :: CardanoChainConfig -> CardanoChainConfig -> Bool
Eq, Int -> CardanoChainConfig -> ShowS
[CardanoChainConfig] -> ShowS
CardanoChainConfig -> [Char]
(Int -> CardanoChainConfig -> ShowS)
-> (CardanoChainConfig -> [Char])
-> ([CardanoChainConfig] -> ShowS)
-> Show CardanoChainConfig
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CardanoChainConfig -> ShowS
showsPrec :: Int -> CardanoChainConfig -> ShowS
$cshow :: CardanoChainConfig -> [Char]
show :: CardanoChainConfig -> [Char]
$cshowList :: [CardanoChainConfig] -> ShowS
showList :: [CardanoChainConfig] -> ShowS
Show, (forall x. CardanoChainConfig -> Rep CardanoChainConfig x)
-> (forall x. Rep CardanoChainConfig x -> CardanoChainConfig)
-> Generic CardanoChainConfig
forall x. Rep CardanoChainConfig x -> CardanoChainConfig
forall x. CardanoChainConfig -> Rep CardanoChainConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. CardanoChainConfig -> Rep CardanoChainConfig x
from :: forall x. CardanoChainConfig -> Rep CardanoChainConfig x
$cto :: forall x. Rep CardanoChainConfig x -> CardanoChainConfig
to :: forall x. Rep CardanoChainConfig x -> CardanoChainConfig
Generic)
  deriving anyclass ([CardanoChainConfig] -> Value
[CardanoChainConfig] -> Encoding
CardanoChainConfig -> Bool
CardanoChainConfig -> Value
CardanoChainConfig -> Encoding
(CardanoChainConfig -> Value)
-> (CardanoChainConfig -> Encoding)
-> ([CardanoChainConfig] -> Value)
-> ([CardanoChainConfig] -> Encoding)
-> (CardanoChainConfig -> Bool)
-> ToJSON CardanoChainConfig
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: CardanoChainConfig -> Value
toJSON :: CardanoChainConfig -> Value
$ctoEncoding :: CardanoChainConfig -> Encoding
toEncoding :: CardanoChainConfig -> Encoding
$ctoJSONList :: [CardanoChainConfig] -> Value
toJSONList :: [CardanoChainConfig] -> Value
$ctoEncodingList :: [CardanoChainConfig] -> Encoding
toEncodingList :: [CardanoChainConfig] -> Encoding
$comitField :: CardanoChainConfig -> Bool
omitField :: CardanoChainConfig -> Bool
ToJSON, Maybe CardanoChainConfig
Value -> Parser [CardanoChainConfig]
Value -> Parser CardanoChainConfig
(Value -> Parser CardanoChainConfig)
-> (Value -> Parser [CardanoChainConfig])
-> Maybe CardanoChainConfig
-> FromJSON CardanoChainConfig
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser CardanoChainConfig
parseJSON :: Value -> Parser CardanoChainConfig
$cparseJSONList :: Value -> Parser [CardanoChainConfig]
parseJSONList :: Value -> Parser [CardanoChainConfig]
$comittedField :: Maybe CardanoChainConfig
omittedField :: Maybe CardanoChainConfig
FromJSON)

defaultCardanoChainConfig :: CardanoChainConfig
defaultCardanoChainConfig :: CardanoChainConfig
defaultCardanoChainConfig =
  CardanoChainConfig
    { $sel:hydraScriptsTxId:CardanoChainConfig :: [TxId]
hydraScriptsTxId = []
    , $sel:cardanoSigningKey:CardanoChainConfig :: [Char]
cardanoSigningKey = [Char]
"cardano.sk"
    , $sel:cardanoVerificationKeys:CardanoChainConfig :: [[Char]]
cardanoVerificationKeys = []
    , $sel:startChainFrom:CardanoChainConfig :: Maybe ChainPoint
startChainFrom = Maybe ChainPoint
forall a. Maybe a
Nothing
    , $sel:contestationPeriod:CardanoChainConfig :: ContestationPeriod
contestationPeriod = ContestationPeriod
defaultContestationPeriod
    , $sel:depositPeriod:CardanoChainConfig :: DepositPeriod
depositPeriod = DepositPeriod
defaultDepositPeriod
    , $sel:chainBackendOptions:CardanoChainConfig :: ChainBackendOptions
chainBackendOptions = DirectOptions -> ChainBackendOptions
Direct DirectOptions
defaultDirectOptions
    }

data BlockfrostChainConfig = BlockfrostChainConfig
  { BlockfrostChainConfig -> [Char]
projectPath :: FilePath
  -- ^ Path to the blockfrost project file
  , BlockfrostChainConfig -> [Char]
cardanoSigningKey :: FilePath
  -- ^ Path to the cardano signing key of the internal wallet.
  , BlockfrostChainConfig -> [TxId]
hydraScriptsTxId :: [TxId]
  -- ^ Identifier of transaction holding the hydra scripts to use.
  }
  deriving stock (BlockfrostChainConfig -> BlockfrostChainConfig -> Bool
(BlockfrostChainConfig -> BlockfrostChainConfig -> Bool)
-> (BlockfrostChainConfig -> BlockfrostChainConfig -> Bool)
-> Eq BlockfrostChainConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BlockfrostChainConfig -> BlockfrostChainConfig -> Bool
== :: BlockfrostChainConfig -> BlockfrostChainConfig -> Bool
$c/= :: BlockfrostChainConfig -> BlockfrostChainConfig -> Bool
/= :: BlockfrostChainConfig -> BlockfrostChainConfig -> Bool
Eq, Int -> BlockfrostChainConfig -> ShowS
[BlockfrostChainConfig] -> ShowS
BlockfrostChainConfig -> [Char]
(Int -> BlockfrostChainConfig -> ShowS)
-> (BlockfrostChainConfig -> [Char])
-> ([BlockfrostChainConfig] -> ShowS)
-> Show BlockfrostChainConfig
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BlockfrostChainConfig -> ShowS
showsPrec :: Int -> BlockfrostChainConfig -> ShowS
$cshow :: BlockfrostChainConfig -> [Char]
show :: BlockfrostChainConfig -> [Char]
$cshowList :: [BlockfrostChainConfig] -> ShowS
showList :: [BlockfrostChainConfig] -> ShowS
Show, (forall x. BlockfrostChainConfig -> Rep BlockfrostChainConfig x)
-> (forall x. Rep BlockfrostChainConfig x -> BlockfrostChainConfig)
-> Generic BlockfrostChainConfig
forall x. Rep BlockfrostChainConfig x -> BlockfrostChainConfig
forall x. BlockfrostChainConfig -> Rep BlockfrostChainConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BlockfrostChainConfig -> Rep BlockfrostChainConfig x
from :: forall x. BlockfrostChainConfig -> Rep BlockfrostChainConfig x
$cto :: forall x. Rep BlockfrostChainConfig x -> BlockfrostChainConfig
to :: forall x. Rep BlockfrostChainConfig x -> BlockfrostChainConfig
Generic)

instance Arbitrary ChainConfig where
  arbitrary :: Gen ChainConfig
arbitrary =
    [Gen ChainConfig] -> Gen ChainConfig
forall a. HasCallStack => [Gen a] -> Gen a
oneof
      [ CardanoChainConfig -> ChainConfig
Cardano (CardanoChainConfig -> ChainConfig)
-> Gen CardanoChainConfig -> Gen ChainConfig
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen CardanoChainConfig
genCardanoChainConfig
      , OfflineChainConfig -> ChainConfig
Offline (OfflineChainConfig -> ChainConfig)
-> Gen OfflineChainConfig -> Gen ChainConfig
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen OfflineChainConfig
genOfflineChainConfig
      ]
   where
    genCardanoChainConfig :: Gen CardanoChainConfig
genCardanoChainConfig = do
      [TxId]
hydraScriptsTxId <- Gen [TxId] -> Gen [TxId]
forall a. Gen a -> Gen a
reasonablySized Gen [TxId]
forall a. Arbitrary a => Gen a
arbitrary
      [Char]
cardanoSigningKey <- [Char] -> Gen [Char]
genFilePath [Char]
"sk"
      [[Char]]
cardanoVerificationKeys <- Gen [[Char]] -> Gen [[Char]]
forall a. Gen a -> Gen a
reasonablySized (Gen [Char] -> Gen [[Char]]
forall a. Gen a -> Gen [a]
listOf ([Char] -> Gen [Char]
genFilePath [Char]
"vk"))
      Maybe ChainPoint
startChainFrom <- [Gen (Maybe ChainPoint)] -> Gen (Maybe ChainPoint)
forall a. HasCallStack => [Gen a] -> Gen a
oneof [Maybe ChainPoint -> Gen (Maybe ChainPoint)
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe ChainPoint
forall a. Maybe a
Nothing, ChainPoint -> Maybe ChainPoint
forall a. a -> Maybe a
Just (ChainPoint -> Maybe ChainPoint)
-> Gen ChainPoint -> Gen (Maybe ChainPoint)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ChainPoint
genChainPoint]
      ContestationPeriod
contestationPeriod <- Gen ContestationPeriod
forall a. Arbitrary a => Gen a
arbitrary
      DepositPeriod
depositPeriod <- Gen DepositPeriod
forall a. Arbitrary a => Gen a
arbitrary
      ChainBackendOptions
chainBackendOptions <-
        [Gen ChainBackendOptions] -> Gen ChainBackendOptions
forall a. HasCallStack => [Gen a] -> Gen a
oneof
          [ ChainBackendOptions -> Gen ChainBackendOptions
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChainBackendOptions -> Gen ChainBackendOptions)
-> ChainBackendOptions -> Gen ChainBackendOptions
forall a b. (a -> b) -> a -> b
$ DirectOptions -> ChainBackendOptions
Direct DirectOptions
defaultDirectOptions
          , ChainBackendOptions -> Gen ChainBackendOptions
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChainBackendOptions -> Gen ChainBackendOptions)
-> ChainBackendOptions -> Gen ChainBackendOptions
forall a b. (a -> b) -> a -> b
$ BlockfrostOptions -> ChainBackendOptions
Blockfrost BlockfrostOptions{$sel:projectPath:BlockfrostOptions :: [Char]
projectPath = [Char]
"blockfrost-project.txt"}
          ]
      pure
        CardanoChainConfig
          { [TxId]
$sel:hydraScriptsTxId:CardanoChainConfig :: [TxId]
hydraScriptsTxId :: [TxId]
hydraScriptsTxId
          , [Char]
$sel:cardanoSigningKey:CardanoChainConfig :: [Char]
cardanoSigningKey :: [Char]
cardanoSigningKey
          , [[Char]]
$sel:cardanoVerificationKeys:CardanoChainConfig :: [[Char]]
cardanoVerificationKeys :: [[Char]]
cardanoVerificationKeys
          , Maybe ChainPoint
$sel:startChainFrom:CardanoChainConfig :: Maybe ChainPoint
startChainFrom :: Maybe ChainPoint
startChainFrom
          , ContestationPeriod
$sel:contestationPeriod:CardanoChainConfig :: ContestationPeriod
contestationPeriod :: ContestationPeriod
contestationPeriod
          , DepositPeriod
$sel:depositPeriod:CardanoChainConfig :: DepositPeriod
depositPeriod :: DepositPeriod
depositPeriod
          , ChainBackendOptions
$sel:chainBackendOptions:CardanoChainConfig :: ChainBackendOptions
chainBackendOptions :: ChainBackendOptions
chainBackendOptions
          }

    genOfflineChainConfig :: Gen OfflineChainConfig
genOfflineChainConfig = do
      HeadSeed
offlineHeadSeed <- Gen HeadSeed
forall a. Arbitrary a => Gen a
arbitrary
      Maybe [Char]
ledgerGenesisFile <- [Gen (Maybe [Char])] -> Gen (Maybe [Char])
forall a. HasCallStack => [Gen a] -> Gen a
oneof [Maybe [Char] -> Gen (Maybe [Char])
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe [Char]
forall a. Maybe a
Nothing, [Char] -> Maybe [Char]
forall a. a -> Maybe a
Just ([Char] -> Maybe [Char]) -> Gen [Char] -> Gen (Maybe [Char])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Char] -> Gen [Char]
genFilePath [Char]
"json"]
      [Char]
initialUTxOFile <- [Char] -> Gen [Char]
genFilePath [Char]
"json"
      pure
        OfflineChainConfig
          { HeadSeed
$sel:offlineHeadSeed:OfflineChainConfig :: HeadSeed
offlineHeadSeed :: HeadSeed
offlineHeadSeed
          , [Char]
$sel:initialUTxOFile:OfflineChainConfig :: [Char]
initialUTxOFile :: [Char]
initialUTxOFile
          , Maybe [Char]
$sel:ledgerGenesisFile:OfflineChainConfig :: Maybe [Char]
ledgerGenesisFile :: Maybe [Char]
ledgerGenesisFile
          }

offlineChainConfigParser :: Parser OfflineChainConfig
offlineChainConfigParser :: Parser OfflineChainConfig
offlineChainConfigParser =
  HeadSeed -> [Char] -> Maybe [Char] -> OfflineChainConfig
OfflineChainConfig
    (HeadSeed -> [Char] -> Maybe [Char] -> OfflineChainConfig)
-> Parser HeadSeed
-> Parser ([Char] -> Maybe [Char] -> OfflineChainConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser HeadSeed
offlineHeadSeedParser
    Parser ([Char] -> Maybe [Char] -> OfflineChainConfig)
-> Parser [Char] -> Parser (Maybe [Char] -> OfflineChainConfig)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser [Char]
initialUTxOFileParser
    Parser (Maybe [Char] -> OfflineChainConfig)
-> Parser (Maybe [Char]) -> Parser OfflineChainConfig
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (Maybe [Char])
ledgerGenesisFileParser

offlineHeadSeedParser :: Parser HeadSeed
offlineHeadSeedParser :: Parser HeadSeed
offlineHeadSeedParser =
  ReadM HeadSeed -> Mod OptionFields HeadSeed -> Parser HeadSeed
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    (([Char] -> Either [Char] HeadSeed) -> ReadM HeadSeed
forall a. ([Char] -> Either [Char] a) -> ReadM a
eitherReader (([Char] -> Either [Char] HeadSeed) -> ReadM HeadSeed)
-> ([Char] -> Either [Char] HeadSeed) -> ReadM HeadSeed
forall a b. (a -> b) -> a -> b
$ (RawBytesHexError -> [Char])
-> Either RawBytesHexError HeadSeed -> Either [Char] HeadSeed
forall b c d. (b -> c) -> Either b d -> Either c d
forall (a :: * -> * -> *) b c d.
ArrowChoice a =>
a b c -> a (Either b d) (Either c d)
left RawBytesHexError -> [Char]
forall b a. (Show a, IsString b) => a -> b
show (Either RawBytesHexError HeadSeed -> Either [Char] HeadSeed)
-> ([Char] -> Either RawBytesHexError HeadSeed)
-> [Char]
-> Either [Char] HeadSeed
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either RawBytesHexError HeadSeed
forall a.
SerialiseAsRawBytes a =>
ByteString -> Either RawBytesHexError a
deserialiseFromRawBytesHex (ByteString -> Either RawBytesHexError HeadSeed)
-> ([Char] -> ByteString)
-> [Char]
-> Either RawBytesHexError HeadSeed
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ByteString
BSC.pack)
    ( [Char] -> Mod OptionFields HeadSeed
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"offline-head-seed"
        Mod OptionFields HeadSeed
-> Mod OptionFields HeadSeed -> Mod OptionFields HeadSeed
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields HeadSeed
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"HEX"
        Mod OptionFields HeadSeed
-> Mod OptionFields HeadSeed -> Mod OptionFields HeadSeed
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields HeadSeed
forall (f :: * -> *) a. [Char] -> Mod f a
help [Char]
"Offline mode: Hexadecimal seed bytes to derive the offline head id from. Needs to be consistent across the hydra-node instances."
    )

initialUTxOFileParser :: Parser FilePath
initialUTxOFileParser :: Parser [Char]
initialUTxOFileParser =
  ReadM [Char] -> Mod OptionFields [Char] -> Parser [Char]
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    ReadM [Char]
forall s. IsString s => ReadM s
str
    ( [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"initial-utxo"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"FILE"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value [Char]
"utxo.json"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields [Char]
forall a (f :: * -> *). Show a => Mod f a
showDefault
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. [Char] -> Mod f a
help [Char]
"Offline mode: File containing initial UTxO for the L2 ledger in offline mode."
    )

ledgerGenesisFileParser :: Parser (Maybe FilePath)
ledgerGenesisFileParser :: Parser (Maybe [Char])
ledgerGenesisFileParser =
  ReadM (Maybe [Char])
-> Mod OptionFields (Maybe [Char]) -> Parser (Maybe [Char])
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    (ReadM [Char] -> ReadM (Maybe [Char])
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional ReadM [Char]
forall s. IsString s => ReadM s
str)
    ( [Char] -> Mod OptionFields (Maybe [Char])
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"ledger-genesis"
        Mod OptionFields (Maybe [Char])
-> Mod OptionFields (Maybe [Char])
-> Mod OptionFields (Maybe [Char])
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields (Maybe [Char])
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"FILE"
        Mod OptionFields (Maybe [Char])
-> Mod OptionFields (Maybe [Char])
-> Mod OptionFields (Maybe [Char])
forall a. Semigroup a => a -> a -> a
<> Maybe [Char] -> Mod OptionFields (Maybe [Char])
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value Maybe [Char]
forall a. Maybe a
Nothing
        Mod OptionFields (Maybe [Char])
-> Mod OptionFields (Maybe [Char])
-> Mod OptionFields (Maybe [Char])
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields (Maybe [Char])
forall a (f :: * -> *). Show a => Mod f a
showDefault
        Mod OptionFields (Maybe [Char])
-> Mod OptionFields (Maybe [Char])
-> Mod OptionFields (Maybe [Char])
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields (Maybe [Char])
forall (f :: * -> *) a. [Char] -> Mod f a
help [Char]
"Offline mode: File containing shelley genesis parameters for the simulated L1 chain in offline mode."
    )

cardanoChainConfigParser :: Parser CardanoChainConfig
cardanoChainConfigParser :: Parser CardanoChainConfig
cardanoChainConfigParser =
  [TxId]
-> [Char]
-> [[Char]]
-> Maybe ChainPoint
-> ContestationPeriod
-> DepositPeriod
-> ChainBackendOptions
-> CardanoChainConfig
CardanoChainConfig
    ([TxId]
 -> [Char]
 -> [[Char]]
 -> Maybe ChainPoint
 -> ContestationPeriod
 -> DepositPeriod
 -> ChainBackendOptions
 -> CardanoChainConfig)
-> Parser [TxId]
-> Parser
     ([Char]
      -> [[Char]]
      -> Maybe ChainPoint
      -> ContestationPeriod
      -> DepositPeriod
      -> ChainBackendOptions
      -> CardanoChainConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser [TxId]
hydraScriptsTxIdsParser Parser [TxId] -> Parser [TxId] -> Parser [TxId]
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser TxId -> Parser [TxId]
forall a. Parser a -> Parser [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many Parser TxId
hydraScriptsTxIdParser)
    Parser
  ([Char]
   -> [[Char]]
   -> Maybe ChainPoint
   -> ContestationPeriod
   -> DepositPeriod
   -> ChainBackendOptions
   -> CardanoChainConfig)
-> Parser [Char]
-> Parser
     ([[Char]]
      -> Maybe ChainPoint
      -> ContestationPeriod
      -> DepositPeriod
      -> ChainBackendOptions
      -> CardanoChainConfig)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser [Char]
cardanoSigningKeyFileParser
    Parser
  ([[Char]]
   -> Maybe ChainPoint
   -> ContestationPeriod
   -> DepositPeriod
   -> ChainBackendOptions
   -> CardanoChainConfig)
-> Parser [[Char]]
-> Parser
     (Maybe ChainPoint
      -> ContestationPeriod
      -> DepositPeriod
      -> ChainBackendOptions
      -> CardanoChainConfig)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser [Char] -> Parser [[Char]]
forall a. Parser a -> Parser [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many Parser [Char]
cardanoVerificationKeyFileParser
    Parser
  (Maybe ChainPoint
   -> ContestationPeriod
   -> DepositPeriod
   -> ChainBackendOptions
   -> CardanoChainConfig)
-> Parser (Maybe ChainPoint)
-> Parser
     (ContestationPeriod
      -> DepositPeriod -> ChainBackendOptions -> CardanoChainConfig)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ChainPoint -> Parser (Maybe ChainPoint)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser ChainPoint
startChainFromParser
    Parser
  (ContestationPeriod
   -> DepositPeriod -> ChainBackendOptions -> CardanoChainConfig)
-> Parser ContestationPeriod
-> Parser
     (DepositPeriod -> ChainBackendOptions -> CardanoChainConfig)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ContestationPeriod
contestationPeriodParser
    Parser (DepositPeriod -> ChainBackendOptions -> CardanoChainConfig)
-> Parser DepositPeriod
-> Parser (ChainBackendOptions -> CardanoChainConfig)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser DepositPeriod
depositPeriodParser
    Parser (ChainBackendOptions -> CardanoChainConfig)
-> Parser ChainBackendOptions -> Parser CardanoChainConfig
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ChainBackendOptions
chainBackendOptionsParser

blockfrostProjectPathParser :: Parser FilePath
blockfrostProjectPathParser :: Parser [Char]
blockfrostProjectPathParser =
  Mod OptionFields [Char] -> Parser [Char]
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
    ( [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"blockfrost"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"FILE"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields [Char]
forall a (f :: * -> *). Show a => Mod f a
showDefault
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value [Char]
"blockfrost.txt"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. [Char] -> Mod f a
help
          [Char]
"Blockfrost project path containing the api key."
    )

networkIdParser :: Parser NetworkId
networkIdParser :: Parser NetworkId
networkIdParser = Parser NetworkId
pMainnet Parser NetworkId -> Parser NetworkId -> Parser NetworkId
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (NetworkMagic -> NetworkId)
-> Parser NetworkMagic -> Parser NetworkId
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NetworkMagic -> NetworkId
Testnet Parser NetworkMagic
pTestnetMagic
 where
  pMainnet :: Parser NetworkId
  pMainnet :: Parser NetworkId
pMainnet =
    NetworkId -> Mod FlagFields NetworkId -> Parser NetworkId
forall a. a -> Mod FlagFields a -> Parser a
flag'
      NetworkId
Mainnet
      ( [Char] -> Mod FlagFields NetworkId
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"mainnet"
          Mod FlagFields NetworkId
-> Mod FlagFields NetworkId -> Mod FlagFields NetworkId
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod FlagFields NetworkId
forall (f :: * -> *) a. [Char] -> Mod f a
help [Char]
"Use the mainnet magic id."
      )

  pTestnetMagic :: Parser NetworkMagic
  pTestnetMagic :: Parser NetworkMagic
pTestnetMagic =
    Word32 -> NetworkMagic
NetworkMagic
      (Word32 -> NetworkMagic) -> Parser Word32 -> Parser NetworkMagic
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM Word32 -> Mod OptionFields Word32 -> Parser Word32
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
        ReadM Word32
forall a. Read a => ReadM a
auto
        ( [Char] -> Mod OptionFields Word32
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"testnet-magic"
            Mod OptionFields Word32
-> Mod OptionFields Word32 -> Mod OptionFields Word32
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields Word32
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"NATURAL"
            Mod OptionFields Word32
-> Mod OptionFields Word32 -> Mod OptionFields Word32
forall a. Semigroup a => a -> a -> a
<> Word32 -> Mod OptionFields Word32
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value Word32
42
            Mod OptionFields Word32
-> Mod OptionFields Word32 -> Mod OptionFields Word32
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields Word32
forall a (f :: * -> *). Show a => Mod f a
showDefault
            Mod OptionFields Word32
-> Mod OptionFields Word32 -> Mod OptionFields Word32
forall a. Semigroup a => a -> a -> a
<> Completer -> Mod OptionFields Word32
forall (f :: * -> *) a. HasCompleter f => Completer -> Mod f a
completer ([[Char]] -> Completer
listCompleter [[Char]
"1", [Char]
"2", [Char]
"42"])
            Mod OptionFields Word32
-> Mod OptionFields Word32 -> Mod OptionFields Word32
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields Word32
forall (f :: * -> *) a. [Char] -> Mod f a
help
              [Char]
"Network identifier for a testnet to connect to. We only need to \
              \provide the magic number here. For example: '2' is the 'preview' \
              \network. See https://book.world.dev.cardano.org/environments.html for available networks."
        )

nodeSocketParser :: Parser SocketPath
nodeSocketParser :: Parser SocketPath
nodeSocketParser =
  Mod OptionFields SocketPath -> Parser SocketPath
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
    ( [Char] -> Mod OptionFields SocketPath
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"node-socket"
        Mod OptionFields SocketPath
-> Mod OptionFields SocketPath -> Mod OptionFields SocketPath
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields SocketPath
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"FILE"
        Mod OptionFields SocketPath
-> Mod OptionFields SocketPath -> Mod OptionFields SocketPath
forall a. Semigroup a => a -> a -> a
<> SocketPath -> Mod OptionFields SocketPath
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value DirectOptions
defaultDirectOptions.nodeSocket
        Mod OptionFields SocketPath
-> Mod OptionFields SocketPath -> Mod OptionFields SocketPath
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields SocketPath
forall a (f :: * -> *). Show a => Mod f a
showDefault
        Mod OptionFields SocketPath
-> Mod OptionFields SocketPath -> Mod OptionFields SocketPath
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields SocketPath
forall (f :: * -> *) a. [Char] -> Mod f a
help
          [Char]
"Filepath to local unix domain socket used to communicate with \
          \the cardano node."
    )

cardanoSigningKeyFileParser :: Parser FilePath
cardanoSigningKeyFileParser :: Parser [Char]
cardanoSigningKeyFileParser =
  Mod OptionFields [Char] -> Parser [Char]
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
    ( [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"cardano-signing-key"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"FILE"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields [Char]
forall a (f :: * -> *). Show a => Mod f a
showDefault
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value CardanoChainConfig
defaultCardanoChainConfig.cardanoSigningKey
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. [Char] -> Mod f a
help
          [Char]
"Cardano signing key of our hydra-node. This will be used to authorize \
          \Hydra protocol transactions for heads the node takes part in and any \
          \funds owned by this key will be used as 'fuel'."
    )

cardanoVerificationKeyFileParser :: Parser FilePath
cardanoVerificationKeyFileParser :: Parser [Char]
cardanoVerificationKeyFileParser =
  ReadM [Char] -> Mod OptionFields [Char] -> Parser [Char]
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    ReadM [Char]
forall s. IsString s => ReadM s
str
    ( [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"cardano-verification-key"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"FILE"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. [Char] -> Mod f a
help
          ( [Char]
"Cardano verification key of another party in the Head. Can be \
            \provided multiple times, once for each participant (current maximum limit is "
              [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> Int -> [Char]
forall b a. (Show a, IsString b) => a -> b
show Int
maximumNumberOfParties
              [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> [Char]
")."
          )
    )

hydraSigningKeyFileParser :: Parser FilePath
hydraSigningKeyFileParser :: Parser [Char]
hydraSigningKeyFileParser =
  ReadM [Char] -> Mod OptionFields [Char] -> Parser [Char]
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    ReadM [Char]
forall s. IsString s => ReadM s
str
    ( [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"hydra-signing-key"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"FILE"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value [Char]
"hydra.sk"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields [Char]
forall a (f :: * -> *). Show a => Mod f a
showDefault
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. [Char] -> Mod f a
help [Char]
"Hydra signing key used by our hydra-node."
    )

hydraVerificationKeyFileParser :: Parser FilePath
hydraVerificationKeyFileParser :: Parser [Char]
hydraVerificationKeyFileParser =
  ReadM [Char] -> Mod OptionFields [Char] -> Parser [Char]
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    ReadM [Char]
forall s. IsString s => ReadM s
str
    ( [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"hydra-verification-key"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"FILE"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. [Char] -> Mod f a
help
          ( [Char]
"Hydra verification key of another party in the Head. Can be \
            \provided multiple times, once for each participant (current maximum limit is "
              [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> Int -> [Char]
forall b a. (Show a, IsString b) => a -> b
show Int
maximumNumberOfParties
              [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> [Char]
" )."
          )
    )

peerParser :: Parser Host
peerParser :: Parser Host
peerParser =
  ReadM Host -> Mod OptionFields Host -> Parser Host
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    (([Char] -> Maybe Host) -> ReadM Host
forall a. ([Char] -> Maybe a) -> ReadM a
maybeReader [Char] -> Maybe Host
forall (m :: * -> *). MonadFail m => [Char] -> m Host
readHost)
    ( [Char] -> Mod OptionFields Host
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"peer"
        Mod OptionFields Host
-> Mod OptionFields Host -> Mod OptionFields Host
forall a. Semigroup a => a -> a -> a
<> Char -> Mod OptionFields Host
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'P'
        Mod OptionFields Host
-> Mod OptionFields Host -> Mod OptionFields Host
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields Host
forall (f :: * -> *) a. [Char] -> Mod f a
help
          ( [Char]
"A peer address in the form <host>:<port>, where <host> can be an IP \
            \address, or a host name. Can be provided multiple times, once for \
            \each peer (current maximum limit is "
              [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> Int -> [Char]
forall b a. (Show a, IsString b) => a -> b
show Int
maximumNumberOfParties
              [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> [Char]
" peers)."
          )
    )

nodeIdParser :: Parser NodeId
nodeIdParser :: Parser NodeId
nodeIdParser =
  ReadM NodeId -> Mod OptionFields NodeId -> Parser NodeId
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    ReadM NodeId
forall s. IsString s => ReadM s
str
    ( [Char] -> Mod OptionFields NodeId
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"node-id"
        Mod OptionFields NodeId
-> Mod OptionFields NodeId -> Mod OptionFields NodeId
forall a. Semigroup a => a -> a -> a
<> Char -> Mod OptionFields NodeId
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'n'
        Mod OptionFields NodeId
-> Mod OptionFields NodeId -> Mod OptionFields NodeId
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields NodeId
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"NODE-ID"
        Mod OptionFields NodeId
-> Mod OptionFields NodeId -> Mod OptionFields NodeId
forall a. Semigroup a => a -> a -> a
<> NodeId -> Mod OptionFields NodeId
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value NodeId
"hydra-node-1"
        Mod OptionFields NodeId
-> Mod OptionFields NodeId -> Mod OptionFields NodeId
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields NodeId
forall (f :: * -> *) a. [Char] -> Mod f a
help
          [Char]
"The Hydra node identifier used on the Hydra network. It is \
          \important to have a unique identifier in order to be able to \
          \distinguish between connected peers."
    )

verbosityParser :: Parser Verbosity
verbosityParser :: Parser Verbosity
verbosityParser =
  Verbosity
-> Verbosity -> Mod FlagFields Verbosity -> Parser Verbosity
forall a. a -> a -> Mod FlagFields a -> Parser a
flag
    (Text -> Verbosity
Verbose Text
"HydraNode")
    Verbosity
Quiet
    ( [Char] -> Mod FlagFields Verbosity
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"quiet"
        Mod FlagFields Verbosity
-> Mod FlagFields Verbosity -> Mod FlagFields Verbosity
forall a. Semigroup a => a -> a -> a
<> Char -> Mod FlagFields Verbosity
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'q'
        Mod FlagFields Verbosity
-> Mod FlagFields Verbosity -> Mod FlagFields Verbosity
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod FlagFields Verbosity
forall (f :: * -> *) a. [Char] -> Mod f a
help [Char]
"Turns off logging."
    )

listenParser :: Parser Host
listenParser :: Parser Host
listenParser =
  ReadM Host -> Mod OptionFields Host -> Parser Host
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    ReadM Host
forall a. Read a => ReadM a
auto
    ( [Char] -> Mod OptionFields Host
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"listen"
        Mod OptionFields Host
-> Mod OptionFields Host -> Mod OptionFields Host
forall a. Semigroup a => a -> a -> a
<> Char -> Mod OptionFields Host
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'l'
        Mod OptionFields Host
-> Mod OptionFields Host -> Mod OptionFields Host
forall a. Semigroup a => a -> a -> a
<> Host -> Mod OptionFields Host
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value (Text -> PortNumber -> Host
Host Text
"0.0.0.0" PortNumber
5001)
        Mod OptionFields Host
-> Mod OptionFields Host -> Mod OptionFields Host
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields Host
forall a (f :: * -> *). Show a => Mod f a
showDefault
        Mod OptionFields Host
-> Mod OptionFields Host -> Mod OptionFields Host
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields Host
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"HOST:PORT"
        Mod OptionFields Host
-> Mod OptionFields Host -> Mod OptionFields Host
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields Host
forall (f :: * -> *) a. [Char] -> Mod f a
help [Char]
"Address and port to listen for Hydra network connections. If --advertise is not set, this will be also advertised to other peers on the network."
    )

advertiseParser :: Parser Host
advertiseParser :: Parser Host
advertiseParser =
  ReadM Host -> Mod OptionFields Host -> Parser Host
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    ReadM Host
forall a. Read a => ReadM a
auto
    ( [Char] -> Mod OptionFields Host
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"advertise"
        Mod OptionFields Host
-> Mod OptionFields Host -> Mod OptionFields Host
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields Host
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"HOST:PORT"
        Mod OptionFields Host
-> Mod OptionFields Host -> Mod OptionFields Host
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields Host
forall (f :: * -> *) a. [Char] -> Mod f a
help [Char]
"Address and port to advertise as public endpoint to other peers on the Hydra network. If this is not set, the --listen address is used."
    )

apiHostParser :: Parser IP
apiHostParser :: Parser IP
apiHostParser =
  ReadM IP -> Mod OptionFields IP -> Parser IP
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    ReadM IP
forall a. Read a => ReadM a
auto
    ( [Char] -> Mod OptionFields IP
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"api-host"
        Mod OptionFields IP -> Mod OptionFields IP -> Mod OptionFields IP
forall a. Semigroup a => a -> a -> a
<> IP -> Mod OptionFields IP
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value IP
"127.0.0.1"
        Mod OptionFields IP -> Mod OptionFields IP -> Mod OptionFields IP
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields IP
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"IP"
        Mod OptionFields IP -> Mod OptionFields IP -> Mod OptionFields IP
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields IP
forall a (f :: * -> *). Show a => Mod f a
showDefault
        Mod OptionFields IP -> Mod OptionFields IP -> Mod OptionFields IP
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields IP
forall (f :: * -> *) a. [Char] -> Mod f a
help [Char]
"Listen address for incoming client API connections."
    )

apiPortParser :: Parser PortNumber
apiPortParser :: Parser PortNumber
apiPortParser =
  ReadM PortNumber
-> Mod OptionFields PortNumber -> Parser PortNumber
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    (([Char] -> Maybe PortNumber) -> ReadM PortNumber
forall a. ([Char] -> Maybe a) -> ReadM a
maybeReader [Char] -> Maybe PortNumber
forall (m :: * -> *). MonadFail m => [Char] -> m PortNumber
readPort)
    ( [Char] -> Mod OptionFields PortNumber
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"api-port"
        Mod OptionFields PortNumber
-> Mod OptionFields PortNumber -> Mod OptionFields PortNumber
forall a. Semigroup a => a -> a -> a
<> PortNumber -> Mod OptionFields PortNumber
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value PortNumber
4001
        Mod OptionFields PortNumber
-> Mod OptionFields PortNumber -> Mod OptionFields PortNumber
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields PortNumber
forall a (f :: * -> *). Show a => Mod f a
showDefault
        Mod OptionFields PortNumber
-> Mod OptionFields PortNumber -> Mod OptionFields PortNumber
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields PortNumber
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"PORT"
        Mod OptionFields PortNumber
-> Mod OptionFields PortNumber -> Mod OptionFields PortNumber
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields PortNumber
forall (f :: * -> *) a. [Char] -> Mod f a
help [Char]
"Listen port for incoming client API connections."
    )

tlsCertPathParser :: Parser FilePath
tlsCertPathParser :: Parser [Char]
tlsCertPathParser =
  ReadM [Char] -> Mod OptionFields [Char] -> Parser [Char]
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    ReadM [Char]
forall s. IsString s => ReadM s
str
    ( [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"tls-cert"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"FILE"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. [Char] -> Mod f a
help
          [Char]
"Path to the TLS certificate (chain). If this and --tls-key are \
          \set, the API server will expect TLS connections (WSS/HTTPS)."
    )

tlsKeyPathParser :: Parser FilePath
tlsKeyPathParser :: Parser [Char]
tlsKeyPathParser =
  ReadM [Char] -> Mod OptionFields [Char] -> Parser [Char]
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    ReadM [Char]
forall s. IsString s => ReadM s
str
    ( [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"tls-key"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"FILE"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. [Char] -> Mod f a
help
          [Char]
"Path to the TLS key. If this and --tls-cert are \
          \set, the API server will expect TLS connections (WSS/HTTPS)."
    )

monitoringPortParser :: Parser PortNumber
monitoringPortParser :: Parser PortNumber
monitoringPortParser =
  ReadM PortNumber
-> Mod OptionFields PortNumber -> Parser PortNumber
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    (([Char] -> Maybe PortNumber) -> ReadM PortNumber
forall a. ([Char] -> Maybe a) -> ReadM a
maybeReader [Char] -> Maybe PortNumber
forall (m :: * -> *). MonadFail m => [Char] -> m PortNumber
readPort)
    ( [Char] -> Mod OptionFields PortNumber
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"monitoring-port"
        Mod OptionFields PortNumber
-> Mod OptionFields PortNumber -> Mod OptionFields PortNumber
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields PortNumber
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"PORT"
        Mod OptionFields PortNumber
-> Mod OptionFields PortNumber -> Mod OptionFields PortNumber
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields PortNumber
forall (f :: * -> *) a. [Char] -> Mod f a
help
          [Char]
"Listen port for monitoring and metrics via prometheus. If left \
          \empty, monitoring server is not started."
    )

startChainFromParser :: Parser ChainPoint
startChainFromParser :: Parser ChainPoint
startChainFromParser =
  ReadM ChainPoint
-> Mod OptionFields ChainPoint -> Parser ChainPoint
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    (([Char] -> Maybe ChainPoint) -> ReadM ChainPoint
forall a. ([Char] -> Maybe a) -> ReadM a
maybeReader [Char] -> Maybe ChainPoint
readChainPoint)
    ( [Char] -> Mod OptionFields ChainPoint
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"start-chain-from"
        Mod OptionFields ChainPoint
-> Mod OptionFields ChainPoint -> Mod OptionFields ChainPoint
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields ChainPoint
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"SLOT.HEADER_HASH"
        Mod OptionFields ChainPoint
-> Mod OptionFields ChainPoint -> Mod OptionFields ChainPoint
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields ChainPoint
forall (f :: * -> *) a. [Char] -> Mod f a
help
          [Char]
"The id of the block we want to start observing the chain from. Only \
          \used if the last known head state is older than given point. If not \
          \given and no known head state, the chain tip is used. Composed by the \
          \slot number, a separator ('.') and the hash of the block header. For \
          \example: \
          \52970883.d36a9936ae7a07f5f4bdc9ad0b23761cb7b14f35007e54947e27a1510f897f04."
    )
 where
  readChainPoint :: String -> Maybe ChainPoint
  readChainPoint :: [Char] -> Maybe ChainPoint
readChainPoint = \case
    [Char]
"0" -> ChainPoint -> Maybe ChainPoint
forall a. a -> Maybe a
Just ChainPoint
ChainPointAtGenesis
    [Char]
chainPointStr ->
      case HasCallStack => Text -> Text -> [Text]
Text -> Text -> [Text]
T.splitOn Text
"." ([Char] -> Text
forall a. ToText a => a -> Text
toText [Char]
chainPointStr) of
        [Text
slotNoTxt, Text
headerHashTxt] -> do
          SlotNo
slotNo <- Word64 -> SlotNo
SlotNo (Word64 -> SlotNo) -> Maybe Word64 -> Maybe SlotNo
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Char] -> Maybe Word64
forall a. Read a => [Char] -> Maybe a
readMaybe (Text -> [Char]
forall a. ToString a => a -> [Char]
toString Text
slotNoTxt)
          Hash BlockHeader
headerHash <-
            (RawBytesHexError -> Maybe (Hash BlockHeader))
-> (Hash BlockHeader -> Maybe (Hash BlockHeader))
-> Either RawBytesHexError (Hash BlockHeader)
-> Maybe (Hash BlockHeader)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe (Hash BlockHeader)
-> RawBytesHexError -> Maybe (Hash BlockHeader)
forall a b. a -> b -> a
const Maybe (Hash BlockHeader)
forall a. Maybe a
Nothing) Hash BlockHeader -> Maybe (Hash BlockHeader)
forall a. a -> Maybe a
Just (Either RawBytesHexError (Hash BlockHeader)
 -> Maybe (Hash BlockHeader))
-> Either RawBytesHexError (Hash BlockHeader)
-> Maybe (Hash BlockHeader)
forall a b. (a -> b) -> a -> b
$
              ByteString -> Either RawBytesHexError (Hash BlockHeader)
forall a.
SerialiseAsRawBytes a =>
ByteString -> Either RawBytesHexError a
deserialiseFromRawBytesHex (Text -> ByteString
forall a b. ConvertUtf8 a b => a -> b
encodeUtf8 Text
headerHashTxt)
          pure $ SlotNo -> Hash BlockHeader -> ChainPoint
ChainPoint SlotNo
slotNo Hash BlockHeader
headerHash
        [Text]
_emptyOrSingularList ->
          Maybe ChainPoint
forall a. Maybe a
Nothing

hydraScriptsTxIdsParser :: Parser [TxId]
hydraScriptsTxIdsParser :: Parser [TxId]
hydraScriptsTxIdsParser =
  ReadM [TxId] -> Mod OptionFields [TxId] -> Parser [TxId]
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    (([Char] -> Either [Char] [TxId]) -> ReadM [TxId]
forall a. ([Char] -> Either [Char] a) -> ReadM a
eitherReader (([Char] -> Either [Char] [TxId]) -> ReadM [TxId])
-> ([Char] -> Either [Char] [TxId]) -> ReadM [TxId]
forall a b. (a -> b) -> a -> b
$ (RawBytesHexError -> [Char])
-> Either RawBytesHexError [TxId] -> Either [Char] [TxId]
forall b c d. (b -> c) -> Either b d -> Either c d
forall (a :: * -> * -> *) b c d.
ArrowChoice a =>
a b c -> a (Either b d) (Either c d)
left RawBytesHexError -> [Char]
forall b a. (Show a, IsString b) => a -> b
show (Either RawBytesHexError [TxId] -> Either [Char] [TxId])
-> ([Char] -> Either RawBytesHexError [TxId])
-> [Char]
-> Either [Char] [TxId]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ByteString] -> Either RawBytesHexError [TxId]
parseFromHex ([ByteString] -> Either RawBytesHexError [TxId])
-> ([Char] -> [ByteString])
-> [Char]
-> Either RawBytesHexError [TxId]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ByteString -> [ByteString]
BSC.split Char
',' (ByteString -> [ByteString])
-> ([Char] -> ByteString) -> [Char] -> [ByteString]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ByteString
BSC.pack)
    ( [Char] -> Mod OptionFields [TxId]
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"hydra-scripts-tx-id"
        Mod OptionFields [TxId]
-> Mod OptionFields [TxId] -> Mod OptionFields [TxId]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [TxId]
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"TXID"
        Mod OptionFields [TxId]
-> Mod OptionFields [TxId] -> Mod OptionFields [TxId]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [TxId]
forall (f :: * -> *) a. [Char] -> Mod f a
help
          [Char]
"The transactions which are expected to have published Hydra scripts as \
          \reference scripts in their outputs. You can use the 'publish-scripts' \
          \sub-command to publish scripts yourself."
    )
 where
  parseFromHex :: [ByteString] -> Either RawBytesHexError [TxId]
parseFromHex = (ByteString -> Either RawBytesHexError TxId)
-> [ByteString] -> Either RawBytesHexError [TxId]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM ByteString -> Either RawBytesHexError TxId
forall a.
SerialiseAsRawBytes a =>
ByteString -> Either RawBytesHexError a
deserialiseFromRawBytesHex

hydraScriptsTxIdParser :: Parser TxId
hydraScriptsTxIdParser :: Parser TxId
hydraScriptsTxIdParser =
  ReadM TxId -> Mod OptionFields TxId -> Parser TxId
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    (([Char] -> Either [Char] TxId) -> ReadM TxId
forall a. ([Char] -> Either [Char] a) -> ReadM a
eitherReader (([Char] -> Either [Char] TxId) -> ReadM TxId)
-> ([Char] -> Either [Char] TxId) -> ReadM TxId
forall a b. (a -> b) -> a -> b
$ (RawBytesHexError -> [Char])
-> Either RawBytesHexError TxId -> Either [Char] TxId
forall b c d. (b -> c) -> Either b d -> Either c d
forall (a :: * -> * -> *) b c d.
ArrowChoice a =>
a b c -> a (Either b d) (Either c d)
left RawBytesHexError -> [Char]
forall b a. (Show a, IsString b) => a -> b
show (Either RawBytesHexError TxId -> Either [Char] TxId)
-> ([Char] -> Either RawBytesHexError TxId)
-> [Char]
-> Either [Char] TxId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either RawBytesHexError TxId
forall a.
SerialiseAsRawBytes a =>
ByteString -> Either RawBytesHexError a
deserialiseFromRawBytesHex (ByteString -> Either RawBytesHexError TxId)
-> ([Char] -> ByteString) -> [Char] -> Either RawBytesHexError TxId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ByteString
BSC.pack)
    ( [Char] -> Mod OptionFields TxId
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"hydra-scripts-tx-id"
        Mod OptionFields TxId
-> Mod OptionFields TxId -> Mod OptionFields TxId
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields TxId
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"TXID"
        Mod OptionFields TxId
-> Mod OptionFields TxId -> Mod OptionFields TxId
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields TxId
forall (f :: * -> *) a. [Char] -> Mod f a
help
          [Char]
"The transaction which is expected to have published Hydra scripts as \
          \reference scripts in its outputs. Note: All scripts need to be in the \
          \first 10 outputs. See release notes for pre-published versions. You \
          \can use the 'publish-scripts' sub-command to publish them yourself."
    )

persistenceDirParser :: Parser FilePath
persistenceDirParser :: Parser [Char]
persistenceDirParser =
  ReadM [Char] -> Mod OptionFields [Char] -> Parser [Char]
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    ReadM [Char]
forall s. IsString s => ReadM s
str
    ( [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"persistence-dir"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"DIR"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value [Char]
"./"
        Mod OptionFields [Char]
-> Mod OptionFields [Char] -> Mod OptionFields [Char]
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields [Char]
forall (f :: * -> *) a. [Char] -> Mod f a
help
          [Char]
"The directory where the Hydra Head state is stored.\
          \Do not edit these files manually!"
    )

persistenceRotateAfterParser :: Parser Natural
persistenceRotateAfterParser :: Parser Natural
persistenceRotateAfterParser =
  ReadM Natural -> Mod OptionFields Natural -> Parser Natural
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    ReadM Natural
forall a. Read a => ReadM a
auto
    ( [Char] -> Mod OptionFields Natural
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"persistence-rotate-after"
        Mod OptionFields Natural
-> Mod OptionFields Natural -> Mod OptionFields Natural
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields Natural
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"NATURAL"
        Mod OptionFields Natural
-> Mod OptionFields Natural -> Mod OptionFields Natural
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields Natural
forall (f :: * -> *) a. [Char] -> Mod f a
help
          [Char]
"The number of Hydra events to trigger rotation (default: no rotation)"
    )

hydraNodeCommand :: ParserInfo Command
hydraNodeCommand :: ParserInfo Command
hydraNodeCommand =
  Parser Command -> InfoMod Command -> ParserInfo Command
forall a. Parser a -> InfoMod a -> ParserInfo a
info
    ( Parser Command
commandParser
        Parser Command -> Parser (Command -> Command) -> Parser Command
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> Parser (Command -> Command)
forall {a}. Parser (a -> a)
versionInfo
        Parser Command -> Parser (Command -> Command) -> Parser Command
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> Parser (Command -> Command)
forall {a}. Parser (a -> a)
scriptInfo
        Parser Command -> Parser (Command -> Command) -> Parser Command
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> Parser (Command -> Command)
forall {a}. Parser (a -> a)
helper
    )
    ( InfoMod Command
forall a. InfoMod a
fullDesc
        InfoMod Command -> InfoMod Command -> InfoMod Command
forall a. Semigroup a => a -> a -> a
<> [Char] -> InfoMod Command
forall a. [Char] -> InfoMod a
progDesc [Char]
"Starts a Hydra Node"
        InfoMod Command -> InfoMod Command -> InfoMod Command
forall a. Semigroup a => a -> a -> a
<> [Char] -> InfoMod Command
forall a. [Char] -> InfoMod a
header [Char]
"hydra-node - Implementation of the Hydra Head protocol"
    )
 where
  versionInfo :: Parser (a -> a)
versionInfo =
    [Char] -> Mod OptionFields (a -> a) -> Parser (a -> a)
forall a. [Char] -> Mod OptionFields (a -> a) -> Parser (a -> a)
infoOption
      (Version -> [Char]
showVersion Version
hydraNodeVersion)
      ([Char] -> Mod OptionFields (a -> a)
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"version" Mod OptionFields (a -> a)
-> Mod OptionFields (a -> a) -> Mod OptionFields (a -> a)
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields (a -> a)
forall (f :: * -> *) a. [Char] -> Mod f a
help [Char]
"Show version")

  scriptInfo :: Parser (a -> a)
scriptInfo =
    [Char] -> Mod OptionFields (a -> a) -> Parser (a -> a)
forall a. [Char] -> Mod OptionFields (a -> a) -> Parser (a -> a)
infoOption
      (ByteString -> [Char]
forall a b. ConvertUtf8 a b => b -> a
decodeUtf8 (ByteString -> [Char]) -> ByteString -> [Char]
forall a b. (a -> b) -> a -> b
$ ScriptInfo -> ByteString
forall a. ToJSON a => a -> ByteString
encodePretty ScriptInfo
Contract.scriptInfo)
      ([Char] -> Mod OptionFields (a -> a)
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"script-info" Mod OptionFields (a -> a)
-> Mod OptionFields (a -> a) -> Mod OptionFields (a -> a)
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields (a -> a)
forall (f :: * -> *) a. [Char] -> Mod f a
help [Char]
"Dump script info as JSON")

hydraNodeVersion :: Version
hydraNodeVersion :: Version
hydraNodeVersion =
  Version
version Version -> (Version -> Version) -> Version
forall a b. a -> (a -> b) -> b
& \(Version [Int]
semver [[Char]]
_) -> [Int] -> [[Char]] -> Version
Version [Int]
semver [[Char]]
revision
 where
  revision :: [[Char]]
revision =
    Maybe [Char] -> [[Char]]
forall a. Maybe a -> [a]
maybeToList (Maybe [Char] -> [[Char]]) -> Maybe [Char] -> [[Char]]
forall a b. (a -> b) -> a -> b
$
      Maybe [Char]
embeddedRevision
        Maybe [Char] -> Maybe [Char] -> Maybe [Char]
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe [Char]
gitRevision
        Maybe [Char] -> Maybe [Char] -> Maybe [Char]
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Char] -> Maybe [Char]
forall a. a -> Maybe a
Just [Char]
unknownVersion

defaultContestationPeriod :: ContestationPeriod
defaultContestationPeriod :: ContestationPeriod
defaultContestationPeriod = ContestationPeriod
600

contestationPeriodParser :: Parser ContestationPeriod
contestationPeriodParser :: Parser ContestationPeriod
contestationPeriodParser =
  ReadM ContestationPeriod
-> Mod OptionFields ContestationPeriod -> Parser ContestationPeriod
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    (ReadM NominalDiffTime
forall a. Read a => ReadM a
auto ReadM NominalDiffTime
-> (NominalDiffTime -> ReadM ContestationPeriod)
-> ReadM ContestationPeriod
forall a b. ReadM a -> (a -> ReadM b) -> ReadM b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= NominalDiffTime -> ReadM ContestationPeriod
forall (m :: * -> *).
MonadFail m =>
NominalDiffTime -> m ContestationPeriod
fromNominalDiffTime)
    ( [Char] -> Mod OptionFields ContestationPeriod
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"contestation-period"
        Mod OptionFields ContestationPeriod
-> Mod OptionFields ContestationPeriod
-> Mod OptionFields ContestationPeriod
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields ContestationPeriod
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"SECONDS"
        Mod OptionFields ContestationPeriod
-> Mod OptionFields ContestationPeriod
-> Mod OptionFields ContestationPeriod
forall a. Semigroup a => a -> a -> a
<> ContestationPeriod -> Mod OptionFields ContestationPeriod
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value ContestationPeriod
defaultContestationPeriod
        Mod OptionFields ContestationPeriod
-> Mod OptionFields ContestationPeriod
-> Mod OptionFields ContestationPeriod
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields ContestationPeriod
forall a (f :: * -> *). Show a => Mod f a
showDefault
        Mod OptionFields ContestationPeriod
-> Mod OptionFields ContestationPeriod
-> Mod OptionFields ContestationPeriod
forall a. Semigroup a => a -> a -> a
<> Completer -> Mod OptionFields ContestationPeriod
forall (f :: * -> *) a. HasCompleter f => Completer -> Mod f a
completer ([[Char]] -> Completer
listCompleter [[Char]
"60", [Char]
"180", [Char]
"300"])
        Mod OptionFields ContestationPeriod
-> Mod OptionFields ContestationPeriod
-> Mod OptionFields ContestationPeriod
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields ContestationPeriod
forall (f :: * -> *) a. [Char] -> Mod f a
help
          [Char]
"Contestation period for close transaction in seconds. \
          \ If this value is not in sync with other participants hydra-node will ignore the initial tx.\
          \ Additionally, this value needs to make sense compared to the current network we are running."
    )

defaultDepositPeriod :: DepositPeriod
defaultDepositPeriod :: DepositPeriod
defaultDepositPeriod = NominalDiffTime -> DepositPeriod
DepositPeriod NominalDiffTime
3600

depositPeriodParser :: Parser DepositPeriod
depositPeriodParser :: Parser DepositPeriod
depositPeriodParser =
  ReadM DepositPeriod
-> Mod OptionFields DepositPeriod -> Parser DepositPeriod
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    (NominalDiffTime -> DepositPeriod
DepositPeriod (NominalDiffTime -> DepositPeriod)
-> ReadM NominalDiffTime -> ReadM DepositPeriod
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM NominalDiffTime
forall a. Read a => ReadM a
auto)
    ( [Char] -> Mod OptionFields DepositPeriod
forall (f :: * -> *) a. HasName f => [Char] -> Mod f a
long [Char]
"deposit-period"
        Mod OptionFields DepositPeriod
-> Mod OptionFields DepositPeriod -> Mod OptionFields DepositPeriod
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields DepositPeriod
forall (f :: * -> *) a. HasMetavar f => [Char] -> Mod f a
metavar [Char]
"SECONDS"
        Mod OptionFields DepositPeriod
-> Mod OptionFields DepositPeriod -> Mod OptionFields DepositPeriod
forall a. Semigroup a => a -> a -> a
<> DepositPeriod -> Mod OptionFields DepositPeriod
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value DepositPeriod
defaultDepositPeriod
        Mod OptionFields DepositPeriod
-> Mod OptionFields DepositPeriod -> Mod OptionFields DepositPeriod
forall a. Semigroup a => a -> a -> a
<> Mod OptionFields DepositPeriod
forall a (f :: * -> *). Show a => Mod f a
showDefault
        Mod OptionFields DepositPeriod
-> Mod OptionFields DepositPeriod -> Mod OptionFields DepositPeriod
forall a. Semigroup a => a -> a -> a
<> Completer -> Mod OptionFields DepositPeriod
forall (f :: * -> *) a. HasCompleter f => Completer -> Mod f a
completer ([[Char]] -> Completer
listCompleter [[Char]
"3600", [Char]
"7200", [Char]
"43200"])
        Mod OptionFields DepositPeriod
-> Mod OptionFields DepositPeriod -> Mod OptionFields DepositPeriod
forall a. Semigroup a => a -> a -> a
<> [Char] -> Mod OptionFields DepositPeriod
forall (f :: * -> *) a. [Char] -> Mod f a
help
          [Char]
"Minimum time before deadline to consider deposits. 2 x deposit-period \
          \is used to set the deadline on any drafted deposit transactions."
    )

data InvalidOptions
  = MaximumNumberOfPartiesExceeded
  | CardanoAndHydraKeysMismatch
  deriving stock (InvalidOptions -> InvalidOptions -> Bool
(InvalidOptions -> InvalidOptions -> Bool)
-> (InvalidOptions -> InvalidOptions -> Bool) -> Eq InvalidOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InvalidOptions -> InvalidOptions -> Bool
== :: InvalidOptions -> InvalidOptions -> Bool
$c/= :: InvalidOptions -> InvalidOptions -> Bool
/= :: InvalidOptions -> InvalidOptions -> Bool
Eq, Int -> InvalidOptions -> ShowS
[InvalidOptions] -> ShowS
InvalidOptions -> [Char]
(Int -> InvalidOptions -> ShowS)
-> (InvalidOptions -> [Char])
-> ([InvalidOptions] -> ShowS)
-> Show InvalidOptions
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InvalidOptions -> ShowS
showsPrec :: Int -> InvalidOptions -> ShowS
$cshow :: InvalidOptions -> [Char]
show :: InvalidOptions -> [Char]
$cshowList :: [InvalidOptions] -> ShowS
showList :: [InvalidOptions] -> ShowS
Show)

-- | Validate cmd line arguments for hydra-node and check if they make sense before actually running the node.
-- Rules we apply:
--  - Check if number of parties is bigger than our hardcoded limit
--      (by looking at loaded hydra or cardano keys and comparing it to the 'maximumNumberOfParties')
--  - Check that number of loaded hydra keys match with the number of loaded cardano keys
--      (by comparing lengths of the two lists)
validateRunOptions :: RunOptions -> Either InvalidOptions ()
validateRunOptions :: RunOptions -> Either InvalidOptions ()
validateRunOptions RunOptions{[[Char]]
$sel:hydraVerificationKeys:RunOptions :: RunOptions -> [[Char]]
hydraVerificationKeys :: [[Char]]
hydraVerificationKeys, ChainConfig
$sel:chainConfig:RunOptions :: RunOptions -> ChainConfig
chainConfig :: ChainConfig
chainConfig} =
  case ChainConfig
chainConfig of
    Offline{} -> () -> Either InvalidOptions ()
forall a b. b -> Either a b
Right ()
    Cardano CardanoChainConfig{[[Char]]
$sel:cardanoVerificationKeys:CardanoChainConfig :: CardanoChainConfig -> [[Char]]
cardanoVerificationKeys :: [[Char]]
cardanoVerificationKeys}
      | Int -> Int -> Int
forall a. Ord a => a -> a -> a
max ([[Char]] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [[Char]]
hydraVerificationKeys) ([[Char]] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [[Char]]
cardanoVerificationKeys) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
maximumNumberOfParties ->
          InvalidOptions -> Either InvalidOptions ()
forall a b. a -> Either a b
Left InvalidOptions
MaximumNumberOfPartiesExceeded
      | [[Char]] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [[Char]]
cardanoVerificationKeys Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= [[Char]] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [[Char]]
hydraVerificationKeys ->
          InvalidOptions -> Either InvalidOptions ()
forall a b. a -> Either a b
Left InvalidOptions
CardanoAndHydraKeysMismatch
      | Bool
otherwise -> () -> Either InvalidOptions ()
forall a b. b -> Either a b
Right ()

-- | Parse command-line arguments into a `Option` or exit with failure and error message.
parseHydraCommand :: IO Command
parseHydraCommand :: IO Command
parseHydraCommand = IO [[Char]]
forall (m :: * -> *). MonadIO m => m [[Char]]
getArgs IO [[Char]]
-> ([[Char]] -> ParserResult Command) -> IO (ParserResult Command)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> [[Char]] -> ParserResult Command
parseHydraCommandFromArgs IO (ParserResult Command)
-> (ParserResult Command -> IO Command) -> IO Command
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ParserResult Command -> IO Command
forall a. ParserResult a -> IO a
handleParseResult

-- | Pure parsing of `Option` from a list of arguments.
parseHydraCommandFromArgs :: [String] -> ParserResult Command
parseHydraCommandFromArgs :: [[Char]] -> ParserResult Command
parseHydraCommandFromArgs = ParserPrefs
-> ParserInfo Command -> [[Char]] -> ParserResult Command
forall a. ParserPrefs -> ParserInfo a -> [[Char]] -> ParserResult a
execParserPure ParserPrefs
defaultPrefs ParserInfo Command
hydraNodeCommand

-- | Convert an 'Options' instance into the corresponding list of command-line arguments.
--
-- This is useful in situations where one wants to programmatically define 'Options', providing
-- some measure of type safety, without having to juggle with strings.
toArgs :: RunOptions -> [String]
toArgs :: RunOptions -> [[Char]]
toArgs
  RunOptions
    { Verbosity
$sel:verbosity:RunOptions :: RunOptions -> Verbosity
verbosity :: Verbosity
verbosity
    , NodeId
$sel:nodeId:RunOptions :: RunOptions -> NodeId
nodeId :: NodeId
nodeId
    , Host
$sel:listen:RunOptions :: RunOptions -> Host
listen :: Host
listen
    , Maybe Host
$sel:advertise:RunOptions :: RunOptions -> Maybe Host
advertise :: Maybe Host
advertise
    , [Host]
$sel:peers:RunOptions :: RunOptions -> [Host]
peers :: [Host]
peers
    , IP
$sel:apiHost:RunOptions :: RunOptions -> IP
apiHost :: IP
apiHost
    , PortNumber
$sel:apiPort:RunOptions :: RunOptions -> PortNumber
apiPort :: PortNumber
apiPort
    , Maybe [Char]
$sel:tlsCertPath:RunOptions :: RunOptions -> Maybe [Char]
tlsCertPath :: Maybe [Char]
tlsCertPath
    , Maybe [Char]
$sel:tlsKeyPath:RunOptions :: RunOptions -> Maybe [Char]
tlsKeyPath :: Maybe [Char]
tlsKeyPath
    , Maybe PortNumber
$sel:monitoringPort:RunOptions :: RunOptions -> Maybe PortNumber
monitoringPort :: Maybe PortNumber
monitoringPort
    , [Char]
$sel:hydraSigningKey:RunOptions :: RunOptions -> [Char]
hydraSigningKey :: [Char]
hydraSigningKey
    , [[Char]]
$sel:hydraVerificationKeys:RunOptions :: RunOptions -> [[Char]]
hydraVerificationKeys :: [[Char]]
hydraVerificationKeys
    , [Char]
$sel:persistenceDir:RunOptions :: RunOptions -> [Char]
persistenceDir :: [Char]
persistenceDir
    , Maybe Natural
$sel:persistenceRotateAfter:RunOptions :: RunOptions -> Maybe Natural
persistenceRotateAfter :: Maybe Natural
persistenceRotateAfter
    , ChainConfig
$sel:chainConfig:RunOptions :: RunOptions -> ChainConfig
chainConfig :: ChainConfig
chainConfig
    , LedgerConfig
$sel:ledgerConfig:RunOptions :: RunOptions -> LedgerConfig
ledgerConfig :: LedgerConfig
ledgerConfig
    , WhichEtcd
$sel:whichEtcd:RunOptions :: RunOptions -> WhichEtcd
whichEtcd :: WhichEtcd
whichEtcd
    } =
    Verbosity -> [[Char]]
isVerbose Verbosity
verbosity
      [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> [[Char]
"--node-id", Text -> [Char]
unpack Text
nId]
      [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> [[Char]
"--listen", Host -> [Char]
showHost Host
listen]
      [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> [[Char]] -> (Host -> [[Char]]) -> Maybe Host -> [[Char]]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Host
h -> [[Char]
"--advertise", Host -> [Char]
showHost Host
h]) Maybe Host
advertise
      [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> [[Char]
"--api-host", IP -> [Char]
forall b a. (Show a, IsString b) => a -> b
show IP
apiHost]
      [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> PortNumber -> [[Char]]
toArgApiPort PortNumber
apiPort
      [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> WhichEtcd -> [[Char]]
toWhichEtcd WhichEtcd
whichEtcd
      [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> [[Char]] -> ([Char] -> [[Char]]) -> Maybe [Char] -> [[Char]]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\[Char]
cert -> [[Char]
"--tls-cert", [Char]
cert]) Maybe [Char]
tlsCertPath
      [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> [[Char]] -> ([Char] -> [[Char]]) -> Maybe [Char] -> [[Char]]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\[Char]
key -> [[Char]
"--tls-key", [Char]
key]) Maybe [Char]
tlsKeyPath
      [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> [[Char]
"--hydra-signing-key", [Char]
hydraSigningKey]
      [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> ([Char] -> [[Char]]) -> [[Char]] -> [[Char]]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\[Char]
vk -> [[Char]
"--hydra-verification-key", [Char]
vk]) [[Char]]
hydraVerificationKeys
      [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> (Host -> [[Char]]) -> [Host] -> [[Char]]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Host -> [[Char]]
forall {a} {a}. (IsString a, Show a) => a -> [a]
toArgPeer [Host]
peers
      [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> [[Char]]
-> (PortNumber -> [[Char]]) -> Maybe PortNumber -> [[Char]]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\PortNumber
port -> [[Char]
"--monitoring-port", PortNumber -> [Char]
forall b a. (Show a, IsString b) => a -> b
show PortNumber
port]) Maybe PortNumber
monitoringPort
      [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> [[Char]
"--persistence-dir", [Char]
persistenceDir]
      [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> [[Char]] -> (Natural -> [[Char]]) -> Maybe Natural -> [[Char]]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Natural
rotateAfter -> [[Char]
"--persistence-rotate-after", Natural -> [Char]
forall b a. (Show a, IsString b) => a -> b
show Natural
rotateAfter]) Maybe Natural
persistenceRotateAfter
      [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> ChainConfig -> [[Char]]
argsChainConfig ChainConfig
chainConfig
      [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> [[Char]]
argsLedgerConfig
   where
    (NodeId Text
nId) = NodeId
nodeId

    toWhichEtcd :: WhichEtcd -> [[Char]]
toWhichEtcd = \case
      WhichEtcd
SystemEtcd -> [[Char]
"--use-system-etcd"]
      WhichEtcd
EmbeddedEtcd -> []

    isVerbose :: Verbosity -> [[Char]]
isVerbose = \case
      Verbosity
Quiet -> [[Char]
"--quiet"]
      Verbosity
_ -> []

    toArgPeer :: a -> [a]
toArgPeer a
p =
      [a
"--peer", a -> a
forall b a. (Show a, IsString b) => a -> b
show a
p]

    toArgStartChainFrom :: Maybe ChainPoint -> [[Char]]
toArgStartChainFrom = \case
      Just ChainPoint
ChainPointAtGenesis ->
        Text -> [[Char]]
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"ChainPointAtGenesis"
      Just (ChainPoint (SlotNo Word64
slotNo) Hash BlockHeader
headerHash) ->
        let headerHashBase16 :: [Char]
headerHashBase16 = Text -> [Char]
forall a. ToString a => a -> [Char]
toString (Hash BlockHeader -> Text
forall a. SerialiseAsRawBytes a => a -> Text
serialiseToRawBytesHexText Hash BlockHeader
headerHash)
         in [[Char]
"--start-chain-from", Word64 -> [Char]
forall b a. (Show a, IsString b) => a -> b
show Word64
slotNo [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> [Char]
"." [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> [Char]
headerHashBase16]
      Maybe ChainPoint
Nothing ->
        []

    argsChainConfig :: ChainConfig -> [[Char]]
argsChainConfig = \case
      Offline
        OfflineChainConfig
          { HeadSeed
$sel:offlineHeadSeed:OfflineChainConfig :: OfflineChainConfig -> HeadSeed
offlineHeadSeed :: HeadSeed
offlineHeadSeed
          , [Char]
$sel:initialUTxOFile:OfflineChainConfig :: OfflineChainConfig -> [Char]
initialUTxOFile :: [Char]
initialUTxOFile
          , Maybe [Char]
$sel:ledgerGenesisFile:OfflineChainConfig :: OfflineChainConfig -> Maybe [Char]
ledgerGenesisFile :: Maybe [Char]
ledgerGenesisFile
          } ->
          [[Char]
"--offline-head-seed", Text -> [Char]
forall a. ToString a => a -> [Char]
toString (Text -> [Char]) -> Text -> [Char]
forall a b. (a -> b) -> a -> b
$ HeadSeed -> Text
forall a. SerialiseAsRawBytes a => a -> Text
serialiseToRawBytesHexText HeadSeed
offlineHeadSeed]
            [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> [[Char]
"--initial-utxo", [Char]
initialUTxOFile]
            [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> case Maybe [Char]
ledgerGenesisFile of
              Just [Char]
fp -> [[Char]
"--ledger-genesis", [Char]
fp]
              Maybe [Char]
Nothing -> []
      Cardano
        CardanoChainConfig
          { [TxId]
$sel:hydraScriptsTxId:CardanoChainConfig :: CardanoChainConfig -> [TxId]
hydraScriptsTxId :: [TxId]
hydraScriptsTxId
          , [Char]
$sel:cardanoSigningKey:CardanoChainConfig :: CardanoChainConfig -> [Char]
cardanoSigningKey :: [Char]
cardanoSigningKey
          , [[Char]]
$sel:cardanoVerificationKeys:CardanoChainConfig :: CardanoChainConfig -> [[Char]]
cardanoVerificationKeys :: [[Char]]
cardanoVerificationKeys
          , Maybe ChainPoint
$sel:startChainFrom:CardanoChainConfig :: CardanoChainConfig -> Maybe ChainPoint
startChainFrom :: Maybe ChainPoint
startChainFrom
          , ContestationPeriod
$sel:contestationPeriod:CardanoChainConfig :: CardanoChainConfig -> ContestationPeriod
contestationPeriod :: ContestationPeriod
contestationPeriod
          , DepositPeriod
$sel:depositPeriod:CardanoChainConfig :: CardanoChainConfig -> DepositPeriod
depositPeriod :: DepositPeriod
depositPeriod
          , ChainBackendOptions
$sel:chainBackendOptions:CardanoChainConfig :: CardanoChainConfig -> ChainBackendOptions
chainBackendOptions :: ChainBackendOptions
chainBackendOptions
          } ->
          ( case ChainBackendOptions
chainBackendOptions of
              Blockfrost BlockfrostOptions{[Char]
$sel:projectPath:BlockfrostOptions :: BlockfrostOptions -> [Char]
projectPath :: [Char]
projectPath} ->
                [[Char]
"--blockfrost", [Char]
projectPath]
              Direct DirectOptions{NetworkId
$sel:networkId:DirectOptions :: DirectOptions -> NetworkId
networkId :: NetworkId
networkId, SocketPath
$sel:nodeSocket:DirectOptions :: DirectOptions -> SocketPath
nodeSocket :: SocketPath
nodeSocket} ->
                NetworkId -> [[Char]]
toArgNetworkId NetworkId
networkId
                  [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> SocketPath -> [[Char]]
toArgNodeSocket SocketPath
nodeSocket
          )
            [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> [[Char]
"--hydra-scripts-tx-id", [Char] -> [[Char]] -> [Char]
forall a. [a] -> [[a]] -> [a]
intercalate [Char]
"," ([[Char]] -> [Char]) -> [[Char]] -> [Char]
forall a b. (a -> b) -> a -> b
$ Text -> [Char]
forall a. ToString a => a -> [Char]
toString (Text -> [Char]) -> (TxId -> Text) -> TxId -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxId -> Text
forall a. SerialiseAsRawBytes a => a -> Text
serialiseToRawBytesHexText (TxId -> [Char]) -> [TxId] -> [[Char]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [TxId]
hydraScriptsTxId]
            [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> [[Char]
"--cardano-signing-key", [Char]
cardanoSigningKey]
            [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> [[Char]
"--contestation-period", ContestationPeriod -> [Char]
forall b a. (Show a, IsString b) => a -> b
show ContestationPeriod
contestationPeriod]
            [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> [[Char]
"--deposit-period", DepositPeriod -> [Char]
forall b a. (Show a, IsString b) => a -> b
show DepositPeriod
depositPeriod]
            [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> ([Char] -> [[Char]]) -> [[Char]] -> [[Char]]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\[Char]
vk -> [[Char]
"--cardano-verification-key", [Char]
vk]) [[Char]]
cardanoVerificationKeys
            [[Char]] -> [[Char]] -> [[Char]]
forall a. Semigroup a => a -> a -> a
<> Maybe ChainPoint -> [[Char]]
toArgStartChainFrom Maybe ChainPoint
startChainFrom

    argsLedgerConfig :: [[Char]]
argsLedgerConfig =
      [[Char]
"--ledger-protocol-parameters", [Char]
cardanoLedgerProtocolParametersFile]

    CardanoLedgerConfig
      { [Char]
$sel:cardanoLedgerProtocolParametersFile:CardanoLedgerConfig :: LedgerConfig -> [Char]
cardanoLedgerProtocolParametersFile :: [Char]
cardanoLedgerProtocolParametersFile
      } = LedgerConfig
ledgerConfig

toArgNodeSocket :: SocketPath -> [String]
toArgNodeSocket :: SocketPath -> [[Char]]
toArgNodeSocket SocketPath
nodeSocket = [[Char]
"--node-socket", SocketPath -> [Char]
forall content (direction :: FileDirection).
File content direction -> [Char]
unFile SocketPath
nodeSocket]

toArgApiPort :: PortNumber -> [String]
toArgApiPort :: PortNumber -> [[Char]]
toArgApiPort PortNumber
apiPort = [[Char]
"--api-port", PortNumber -> [Char]
forall b a. (Show a, IsString b) => a -> b
show PortNumber
apiPort]

toArgNetworkId :: NetworkId -> [String]
toArgNetworkId :: NetworkId -> [[Char]]
toArgNetworkId = \case
  NetworkId
Mainnet -> [[Char]
"--mainnet"]
  Testnet (NetworkMagic Word32
magic) -> [[Char]
"--testnet-magic", Word32 -> [Char]
forall b a. (Show a, IsString b) => a -> b
show Word32
magic]

genFilePath :: String -> Gen FilePath
genFilePath :: [Char] -> Gen [Char]
genFilePath [Char]
extension = do
  [[Char]]
path <- Gen [[Char]] -> Gen [[Char]]
forall a. Gen a -> Gen a
reasonablySized (Gen [Char] -> Gen [[Char]]
forall a. Gen a -> Gen [a]
listOf1 ([[Char]] -> Gen [Char]
forall a. HasCallStack => [a] -> Gen a
elements [[Char]
"a", [Char]
"b", [Char]
"c"]))
  pure $ [Char] -> [[Char]] -> [Char]
forall a. [a] -> [[a]] -> [a]
intercalate [Char]
"/" [[Char]]
path [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> [Char]
"." [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> [Char]
extension

genDirPath :: Gen FilePath
genDirPath :: Gen [Char]
genDirPath = do
  [[Char]]
path <- Gen [[Char]] -> Gen [[Char]]
forall a. Gen a -> Gen a
reasonablySized (Gen [Char] -> Gen [[Char]]
forall a. Gen a -> Gen [a]
listOf1 ([[Char]] -> Gen [Char]
forall a. HasCallStack => [a] -> Gen a
elements [[Char]
"a", [Char]
"b", [Char]
"c"]))
  pure $ [Char] -> [[Char]] -> [Char]
forall a. [a] -> [[a]] -> [a]
intercalate [Char]
"/" [[Char]]
path

genChainPoint :: Gen ChainPoint
genChainPoint :: Gen ChainPoint
genChainPoint = (SlotNo -> Hash BlockHeader -> ChainPoint
ChainPoint (SlotNo -> Hash BlockHeader -> ChainPoint)
-> (Word64 -> SlotNo) -> Word64 -> Hash BlockHeader -> ChainPoint
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> SlotNo
SlotNo (Word64 -> Hash BlockHeader -> ChainPoint)
-> Gen Word64 -> Gen (Hash BlockHeader -> ChainPoint)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Word64
forall a. Arbitrary a => Gen a
arbitrary) Gen (Hash BlockHeader -> ChainPoint)
-> Gen (Hash BlockHeader) -> Gen ChainPoint
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen (Hash BlockHeader)
someHeaderHash
 where
  someHeaderHash :: Gen (Hash BlockHeader)
someHeaderHash = do
    [Word8]
bytes <- Int -> Gen Word8 -> Gen [Word8]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
32 Gen Word8
forall a. Arbitrary a => Gen a
arbitrary
    let hash :: Hash BlockHeader
hash = (SerialiseAsRawBytesError -> Hash BlockHeader)
-> (Hash BlockHeader -> Hash BlockHeader)
-> Either SerialiseAsRawBytesError (Hash BlockHeader)
-> Hash BlockHeader
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Text -> SerialiseAsRawBytesError -> Hash BlockHeader
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"invalid bytes") Hash BlockHeader -> Hash BlockHeader
forall a. a -> a
id (Either SerialiseAsRawBytesError (Hash BlockHeader)
 -> Hash BlockHeader)
-> Either SerialiseAsRawBytesError (Hash BlockHeader)
-> Hash BlockHeader
forall a b. (a -> b) -> a -> b
$ AsType (Hash BlockHeader)
-> ByteString -> Either SerialiseAsRawBytesError (Hash BlockHeader)
forall a.
SerialiseAsRawBytes a =>
AsType a -> ByteString -> Either SerialiseAsRawBytesError a
deserialiseFromRawBytes (Proxy (Hash BlockHeader) -> AsType (Hash BlockHeader)
forall t. HasTypeProxy t => Proxy t -> AsType t
proxyToAsType Proxy (Hash BlockHeader)
forall {k} (t :: k). Proxy t
Proxy) (ByteString -> Either SerialiseAsRawBytesError (Hash BlockHeader))
-> ([Word8] -> ByteString)
-> [Word8]
-> Either SerialiseAsRawBytesError (Hash BlockHeader)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Word8] -> ByteString
BS.pack ([Word8] -> Either SerialiseAsRawBytesError (Hash BlockHeader))
-> [Word8] -> Either SerialiseAsRawBytesError (Hash BlockHeader)
forall a b. (a -> b) -> a -> b
$ [Word8]
bytes
    Hash BlockHeader -> Gen (Hash BlockHeader)
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Hash BlockHeader
hash