-
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.
Merge pull request #840 from IntersectMBO/smelc/add-transaction-view-…
…under-debug Add era-independent "debug transaction view" command
- Loading branch information
Showing
22 changed files
with
211 additions
and
157 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
12 changes: 12 additions & 0 deletions
12
cardano-cli/src/Cardano/CLI/Commands/Debug/TransactionView.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,12 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
|
||
module Cardano.CLI.Commands.Debug.TransactionView where | ||
|
||
import Cardano.CLI.Types.Common | ||
|
||
data TransactionViewCmdArgs = TransactionViewCmdArgs | ||
{ outputFormat :: !ViewOutputFormat | ||
, mOutFile :: !(Maybe (File () Out)) | ||
, inputTxBodyOrTxFile :: !InputTxBodyOrTxFile | ||
} | ||
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
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,47 @@ | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
|
||
module Cardano.CLI.Run.Debug.TransactionView | ||
( runTransactionViewCmd | ||
) | ||
where | ||
|
||
import Cardano.Api | ||
|
||
import Cardano.CLI.Commands.Debug.TransactionView | ||
import Cardano.CLI.Json.Friendly (friendlyTx, friendlyTxBody, | ||
viewOutputFormatToFriendlyFormat) | ||
import Cardano.CLI.Read | ||
import Cardano.CLI.Types.Common | ||
import Cardano.CLI.Types.Errors.TxCmdError | ||
|
||
import Data.Function ((&)) | ||
|
||
runTransactionViewCmd | ||
:: () | ||
=> TransactionViewCmdArgs | ||
-> ExceptT TxCmdError IO () | ||
runTransactionViewCmd | ||
TransactionViewCmdArgs | ||
{ outputFormat | ||
, mOutFile | ||
, inputTxBodyOrTxFile | ||
} = | ||
case inputTxBodyOrTxFile of | ||
InputTxBodyFile (File txbodyFilePath) -> do | ||
txbodyFile <- liftIO $ fileOrPipe txbodyFilePath | ||
unwitnessed <- | ||
firstExceptT TxCmdTextEnvCddlError . newExceptT $ | ||
readFileTxBody txbodyFile | ||
InAnyShelleyBasedEra era txbody <- pure $ unIncompleteCddlTxBody unwitnessed | ||
-- Why are we differentiating between a transaction body and a transaction? | ||
-- In the case of a transaction body, we /could/ simply call @makeSignedTransaction []@ | ||
-- to get a transaction which would allow us to reuse friendlyTxBS. However, | ||
-- this would mean that we'd have an empty list of witnesses mentioned in the output, which | ||
-- is arguably not part of the transaction body. | ||
firstExceptT TxCmdWriteFileError . newExceptT $ | ||
friendlyTxBody (viewOutputFormatToFriendlyFormat outputFormat) mOutFile (toCardanoEra era) txbody | ||
InputTxFile (File txFilePath) -> do | ||
txFile <- liftIO $ fileOrPipe txFilePath | ||
InAnyShelleyBasedEra era tx <- lift (readFileTx txFile) & onLeft (left . TxCmdTextEnvCddlError) | ||
firstExceptT TxCmdWriteFileError . newExceptT $ | ||
friendlyTx (viewOutputFormatToFriendlyFormat outputFormat) mOutFile (toCardanoEra era) 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,19 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
|
||
module Cardano.CLI.Types.Errors.DebugCmdError | ||
( DebugCmdError (..) | ||
) | ||
where | ||
|
||
import Cardano.Api | ||
|
||
import Cardano.CLI.Types.Errors.TxCmdError | ||
|
||
data DebugCmdError | ||
= DebugCmdFailed | ||
| DebugTxCmdError !TxCmdError | ||
|
||
instance Error DebugCmdError where | ||
prettyError = \case | ||
DebugCmdFailed -> "Debug command failed" | ||
DebugTxCmdError err -> renderTxCmdError err |
Oops, something went wrong.