-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move PingCmd to Cardano.CLI.Commands.Ping
- Loading branch information
Showing
13 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Cardano.CLI.Commands.Debug | ||
( DebugCmds (..) | ||
) where | ||
|
||
import Cardano.CLI.Commands.Debug.LogEpochState | ||
|
||
newtype DebugCmds = | ||
DebugLogEpochStateCmd LogEpochStateCmdArgs |
18 changes: 18 additions & 0 deletions
18
cardano-cli/src/Cardano/CLI/Commands/Debug/LogEpochState.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
|
||
module Cardano.CLI.Commands.Debug.LogEpochState | ||
( LogEpochStateCmdArgs(..) | ||
, Configuration | ||
) where | ||
|
||
import Cardano.Api | ||
|
||
import Cardano.CLI.Orphans () | ||
|
||
data Configuration | ||
|
||
data LogEpochStateCmdArgs = LogEpochStateCmdArgs | ||
{ nodeSocketPath :: !SocketPath | ||
, configurationFile :: !(NodeConfigFile 'In) | ||
, outputFilePath :: !(File Configuration 'Out) | ||
} deriving Show |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
{- HLINT ignore "Use <$>" -} | ||
{- HLINT ignore "Move brackets to avoid $" -} | ||
|
||
module Cardano.CLI.Options.Debug | ||
( parseDebugCmds | ||
) where | ||
|
||
import Cardano.Api.Shelley hiding (QueryInShelleyBasedEra (..)) | ||
|
||
import Cardano.CLI.Commands.Debug | ||
import Cardano.CLI.Commands.Debug.LogEpochState | ||
import Cardano.CLI.Environment | ||
import Cardano.CLI.EraBased.Options.Common | ||
|
||
import Data.Foldable | ||
import Options.Applicative hiding (help, str) | ||
import qualified Options.Applicative as Opt | ||
|
||
parseDebugCmds :: EnvCli -> Parser DebugCmds | ||
parseDebugCmds envCli = | ||
Opt.hsubparser $ mconcat | ||
[ Opt.metavar "debug commands" | ||
, Opt.commandGroup "debug commands" | ||
, Opt.command "debug" | ||
$ Opt.info (pDebugCmds envCli) | ||
$ Opt.progDesc "Debug commands" | ||
] | ||
|
||
pDebugCmds :: EnvCli -> Parser DebugCmds | ||
pDebugCmds envCli = | ||
asum | ||
[ subParser "log-epoch-state" | ||
(Opt.info pLogEpochStateCmdArgs $ Opt.progDesc "Log epoch state.") | ||
] | ||
where | ||
pLogEpochStateCmdArgs :: Parser DebugCmds | ||
pLogEpochStateCmdArgs = | ||
fmap DebugLogEpochStateCmd $ | ||
LogEpochStateCmdArgs | ||
<$> pSocketPath envCli | ||
<*> pNodeConfigurationFileIn | ||
<*> pFileOutDirection "out-file" "Output filepath of the log file. The log file format is line delimited JSON." | ||
|
||
pNodeConfigurationFileIn :: Parser (NodeConfigFile In) | ||
pNodeConfigurationFileIn = | ||
fmap File $ Opt.strOption $ mconcat | ||
[ Opt.long "node-configuration-file" | ||
, Opt.metavar "FILE" | ||
, Opt.help "Input filepath of the node configuration file." | ||
, Opt.completer (Opt.bashCompleter "file") | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
|
||
module Cardano.CLI.Orphans | ||
( | ||
) where | ||
|
||
import Cardano.Api | ||
|
||
import qualified Cardano.Ledger.Api as L | ||
import qualified Cardano.Ledger.Shelley.LedgerState as L | ||
|
||
import Data.Aeson | ||
|
||
-- TODO upstream this orphaned instance to the ledger | ||
instance (L.EraTxOut ledgerera, L.EraGov ledgerera) => ToJSON (L.NewEpochState ledgerera) where | ||
toJSON (L.NewEpochState nesEL nesBprev nesBCur nesEs nesRu nesPd _stashedAvvm)= | ||
object | ||
[ "currentEpoch" .= nesEL | ||
, "priorBlocks" .= nesBprev | ||
, "currentEpochBlocks" .= nesBCur | ||
, "currentEpochState" .= nesEs | ||
, "rewardUpdate" .= nesRu | ||
, "currentStakeDistribution" .= nesPd | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
|
||
module Cardano.CLI.Run.Debug | ||
( DebugCmdError(..) | ||
, runLogEpochStateCmd | ||
, runDebugCmds | ||
, renderDebugCmdError | ||
) where | ||
|
||
import Cardano.CLI.Commands.Debug | ||
import Cardano.CLI.Run.Debug.LogEpochState | ||
|
||
import Control.Monad.IO.Class | ||
import Control.Monad.Trans.Except | ||
import Prettyprinter | ||
|
||
data DebugCmdError = DebugCmdFailed | ||
|
||
runDebugCmds :: DebugCmds -> ExceptT DebugCmdError IO () | ||
runDebugCmds = \case | ||
DebugLogEpochStateCmd cmd -> liftIO $ runLogEpochStateCmd cmd | ||
|
||
renderDebugCmdError :: DebugCmdError -> Doc ann | ||
renderDebugCmdError DebugCmdFailed = "Debug command failed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module Cardano.CLI.Run.Debug.LogEpochState | ||
( runLogEpochStateCmd | ||
) where | ||
|
||
import Cardano.Api | ||
import qualified Cardano.Api as Api | ||
|
||
import Cardano.CLI.Commands.Debug.LogEpochState | ||
import Cardano.CLI.Orphans () | ||
|
||
import qualified Data.Aeson as Aeson | ||
import qualified Data.ByteString.Lazy as LBS | ||
import qualified System.IO as IO | ||
|
||
runLogEpochStateCmd | ||
:: LogEpochStateCmdArgs | ||
-> IO () | ||
runLogEpochStateCmd | ||
LogEpochStateCmdArgs | ||
{ nodeSocketPath | ||
, configurationFile | ||
, outputFilePath = File outputFilePath | ||
} = do | ||
LBS.appendFile outputFilePath "" | ||
|
||
result <- runExceptT $ foldEpochState | ||
configurationFile | ||
nodeSocketPath | ||
Api.QuickValidation | ||
(EpochNo maxBound) | ||
() | ||
(\(AnyNewEpochState sbe nes) _ _ -> do | ||
liftIO $ LBS.appendFile outputFilePath | ||
$ shelleyBasedEraConstraints sbe (Aeson.encode nes) <> "\n" | ||
pure ConditionNotMet | ||
) | ||
|
||
case result of | ||
Right _ -> pure () | ||
Left e -> IO.hPutStrLn IO.stderr $ "Error: " <> show e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
cardano-cli/test/cardano-cli-golden/files/golden/help/debug_log-epoch-state.cli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Usage: cardano-cli debug log-epoch-state --socket-path SOCKET_PATH | ||
--node-configuration-file FILE | ||
--out-file FILE | ||
|
||
Log epoch state. | ||
|
||
Available options: | ||
--socket-path SOCKET_PATH | ||
Path to the node socket. This overrides the | ||
CARDANO_NODE_SOCKET_PATH environment variable. The | ||
argument is optional if CARDANO_NODE_SOCKET_PATH is | ||
defined and mandatory otherwise. | ||
--node-configuration-file FILE | ||
Input filepath of the node configuration file. | ||
--out-file FILE Output filepath of the log file. The log file format | ||
is line delimited JSON. | ||
-h,--help Show this help text |