{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeApplications #-}
module Cardano.CLI.EraIndependent.Debug.TransactionView.Run
( runTransactionViewCmd
)
where
import Cardano.Api
import Cardano.CLI.Compatible.Exception
import Cardano.CLI.Compatible.Json.Friendly
( friendlyTx
, friendlyTxBody
)
import Cardano.CLI.EraIndependent.Debug.TransactionView.Command
import Cardano.CLI.Read
import Cardano.CLI.Type.Common
runTransactionViewCmd
:: ()
=> TransactionViewCmdArgs
-> CIO e ()
runTransactionViewCmd :: forall e. TransactionViewCmdArgs -> CIO e ()
runTransactionViewCmd
TransactionViewCmdArgs
{ Vary '[FormatJson, FormatYaml]
outputFormat :: Vary '[FormatJson, FormatYaml]
outputFormat :: TransactionViewCmdArgs -> Vary '[FormatJson, FormatYaml]
outputFormat
, Maybe (File () 'Out)
mOutFile :: Maybe (File () 'Out)
mOutFile :: TransactionViewCmdArgs -> Maybe (File () 'Out)
mOutFile
, InputTxBodyOrTxFile
inputTxBodyOrTxFile :: InputTxBodyOrTxFile
inputTxBodyOrTxFile :: TransactionViewCmdArgs -> InputTxBodyOrTxFile
inputTxBodyOrTxFile
} =
case InputTxBodyOrTxFile
inputTxBodyOrTxFile of
InputTxBodyFile (File FilePath
txbodyFilePath) -> do
txbodyFile <- IO FileOrPipe -> RIO e FileOrPipe
forall a. IO a -> RIO e a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO FileOrPipe -> RIO e FileOrPipe)
-> IO FileOrPipe -> RIO e FileOrPipe
forall a b. (a -> b) -> a -> b
$ FilePath -> IO FileOrPipe
fileOrPipe FilePath
txbodyFilePath
unwitnessed <-
fromEitherIOCli $
readFileTxBody txbodyFile
InAnyShelleyBasedEra era txbody <- pure $ unIncompleteTxBody unwitnessed
fromEitherIOCli @(FileError ()) $
friendlyTxBody outputFormat mOutFile era txbody
InputTxFile (File FilePath
txFilePath) -> do
txFile <- IO FileOrPipe -> RIO e FileOrPipe
forall a. IO a -> RIO e a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO FileOrPipe -> RIO e FileOrPipe)
-> IO FileOrPipe -> RIO e FileOrPipe
forall a b. (a -> b) -> a -> b
$ FilePath -> IO FileOrPipe
fileOrPipe FilePath
txFilePath
InAnyShelleyBasedEra era tx <- fromEitherIOCli (readFileTx txFile)
fromEitherIOCli @(FileError ()) $
friendlyTx outputFormat mOutFile era tx