-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move transaction echo command to under 'debug' command group.
- Loading branch information
Showing
27 changed files
with
223 additions
and
188 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.Transaction | ||
( DebugTransactionCmds (..) | ||
) where | ||
|
||
import Cardano.CLI.Commands.Debug.Transaction.Echo | ||
|
||
newtype DebugTransactionCmds = | ||
DebugTransactionEchoCmd TransactionEchoCmdArgs |
15 changes: 15 additions & 0 deletions
15
cardano-cli/src/Cardano/CLI/Commands/Debug/Transaction/Echo.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,15 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE DuplicateRecordFields #-} | ||
|
||
module Cardano.CLI.Commands.Debug.Transaction.Echo | ||
( TransactionEchoCmdArgs(..) | ||
) where | ||
|
||
import Cardano.Api.Shelley | ||
|
||
import Cardano.CLI.Types.Common | ||
|
||
data TransactionEchoCmdArgs = TransactionEchoCmdArgs | ||
{ txOrTxBodyFile :: !InputTxBodyOrTxFile | ||
, outTxFile :: !(TxFile 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
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,67 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
{- HLINT ignore "Use <$>" -} | ||
{- HLINT ignore "Move brackets to avoid $" -} | ||
|
||
module Cardano.CLI.Options.Debug.Transaction | ||
( 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 Cardano.CLI.Options.Debug.Transaction.Echo | ||
|
||
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 transaction commands" | ||
, Opt.commandGroup "debug commands" | ||
, Opt.command "transaction" | ||
$ Opt.info (pDebugCmds envCli) | ||
$ Opt.progDesc "Debug transaction commands" | ||
] | ||
|
||
pDebugCmds :: EnvCli -> Parser DebugCmds | ||
pDebugCmds envCli = | ||
asum | ||
[ subParser "log-epoch-state" | ||
$ Opt.info pLogEpochStateCmdArgs | ||
$ Opt.progDesc | ||
$ mconcat | ||
[ "Log epoch state of a running node." | ||
, " This command will connect to a local node and log the epoch state to a file." | ||
, " The log file format is line delimited JSON." | ||
, " The command will not terminate." | ||
] | ||
, subParser "echo" | ||
$ Opt.info (DebugTransactionCmds <$> pDebugTransactionEcho) | ||
$ Opt.progDesc "Echo a transaction" | ||
] | ||
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") | ||
] |
21 changes: 21 additions & 0 deletions
21
cardano-cli/src/Cardano/CLI/Options/Debug/Transaction/Echo.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,21 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module Cardano.CLI.Options.Debug.Transaction.Echo | ||
( pDebugTransactionEcho | ||
) where | ||
|
||
import Cardano.CLI.Commands.Debug.Transaction | ||
import Cardano.CLI.Commands.Debug.Transaction.Echo | ||
import Cardano.CLI.EraBased.Options.Common | ||
|
||
import Options.Applicative hiding (help, str) | ||
|
||
pDebugTransactionEcho :: Parser DebugTransactionCmds | ||
pDebugTransactionEcho = | ||
fmap DebugTransactionEchoCmd $ | ||
TransactionEchoCmdArgs | ||
<$> pInputTxOrTxBodyFile | ||
<*> pTxFileOut |
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,17 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
|
||
module Cardano.CLI.Run.Debug.Transaction | ||
( runDebugTransactionCmds | ||
) where | ||
|
||
import Cardano.Api | ||
|
||
import Cardano.CLI.Commands.Debug.Transaction | ||
import Cardano.CLI.Run.Debug.Transaction.Echo | ||
import Cardano.CLI.Types.Errors.DebugCmdError | ||
|
||
runDebugTransactionCmds | ||
:: DebugTransactionCmds | ||
-> ExceptT DebugCmdError IO () | ||
runDebugTransactionCmds = \case | ||
DebugTransactionEchoCmd cmd -> runDebugTransactionEchoCmd cmd |
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,51 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE DuplicateRecordFields #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module Cardano.CLI.Run.Debug.Transaction.Echo | ||
( runDebugTransactionEchoCmd | ||
) where | ||
|
||
import Cardano.Api | ||
|
||
import qualified Cardano.CLI.Commands.Debug.Transaction.Echo as Cmd | ||
import Cardano.CLI.Orphans () | ||
import Cardano.CLI.Read | ||
import Cardano.CLI.Types.Common | ||
import Cardano.CLI.Types.Errors.DebugCmdError | ||
|
||
import Data.Function ((&)) | ||
|
||
runDebugTransactionEchoCmd :: () | ||
=> Cmd.TransactionEchoCmdArgs | ||
-> ExceptT DebugCmdError IO () | ||
runDebugTransactionEchoCmd | ||
Cmd.TransactionEchoCmdArgs | ||
{ Cmd.txOrTxBodyFile = txOrTxBody | ||
, Cmd.outTxFile = outTxFile | ||
} = do | ||
|
||
case txOrTxBody of | ||
InputTxFile (File inputTxFilePath) -> do | ||
inputTxFile <- liftIO $ fileOrPipe inputTxFilePath | ||
anyTx <- lift (readFileTx inputTxFile) & onLeft (left . DebugCmdTextEnvCddlError) | ||
|
||
InAnyShelleyBasedEra sbe tx <- pure anyTx | ||
|
||
lift (writeTxFileTextEnvelopeCddl sbe outTxFile tx) | ||
& onLeft (left . DebugCmdWriteFileError) | ||
|
||
InputTxBodyFile (File txbodyFilePath) -> do | ||
txbodyFile <- liftIO $ fileOrPipe txbodyFilePath | ||
unwitnessed <- firstExceptT DebugCmdTextEnvCddlError . newExceptT $ readFileTxBody txbodyFile | ||
|
||
case unwitnessed of | ||
IncompleteCddlTxBody anyTxBody -> do | ||
InAnyShelleyBasedEra sbe txbody <- pure anyTxBody | ||
|
||
let tx = makeSignedTransaction [] txbody | ||
|
||
firstExceptT DebugCmdWriteFileError . newExceptT | ||
$ writeLazyByteStringFile outTxFile | ||
$ shelleyBasedEraConstraints sbe | ||
$ textEnvelopeToJSON Nothing tx |
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,16 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE GADTs #-} | ||
|
||
module Cardano.CLI.Types.Errors.DebugCmdError | ||
( DebugCmdError(..) | ||
) where | ||
|
||
import Cardano.Api | ||
|
||
import GHC.Generics (Generic) | ||
|
||
data DebugCmdError = | ||
DebugCmdFailed | ||
| DebugCmdTextEnvCddlError !(FileError TextEnvelopeCddlError) | ||
| DebugCmdWriteFileError !(FileError ()) | ||
deriving (Show, Generic) |
Oops, something went wrong.