diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs index 40a6420dad..4e47271108 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs @@ -7,6 +7,7 @@ module Cardano.CLI.EraBased.Commands.Transaction , TransactionBuildRawCmdArgs(..) , TransactionBuildCmdArgs(..) , TransactionBuildEstimateCmdArgs(..) + , TransactionEchoCmdArgs(..) , TransactionSignCmdArgs(..) , TransactionWitnessCmdArgs(..) , TransactionSignWitnessCmdArgs(..) @@ -33,6 +34,7 @@ data TransactionCmds era = TransactionBuildRawCmd !(TransactionBuildRawCmdArgs era) | TransactionBuildCmd !(TransactionBuildCmdArgs era) | TransactionBuildEstimateCmd !(TransactionBuildEstimateCmdArgs era) + | TransactionEchoCmd !TransactionEchoCmdArgs | TransactionSignCmd !TransactionSignCmdArgs | TransactionWitnessCmd !TransactionWitnessCmdArgs | TransactionSignWitnessCmd !TransactionSignWitnessCmdArgs @@ -177,6 +179,11 @@ data TransactionBuildEstimateCmdArgs era = TransactionBuildEstimateCmdArgs , txBodyOutFile :: !(TxBodyFile Out) } +data TransactionEchoCmdArgs = TransactionEchoCmdArgs + { txOrTxBodyFile :: !InputTxBodyOrTxFile + , outTxFile :: !(TxFile Out) + } deriving Show + data TransactionSignCmdArgs = TransactionSignCmdArgs { txOrTxBodyFile :: !InputTxBodyOrTxFile , witnessSigningData :: ![WitnessSigningData] @@ -242,6 +249,7 @@ renderTransactionCmds = \case TransactionBuildCmd {} -> "transaction build" TransactionBuildEstimateCmd {} -> "transaction build-estimate" TransactionBuildRawCmd {} -> "transaction build-raw" + TransactionEchoCmd {} -> "transaction echo" TransactionSignCmd {} -> "transaction sign" TransactionWitnessCmd {} -> "transaction witness" TransactionSignWitnessCmd {} -> "transaction sign-witness" diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Transaction.hs index 5d8df3f99b..1511ecbfbb 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Transaction.hs @@ -54,6 +54,10 @@ pTransactionCmds era envCli = $ subParser "sign" $ Opt.info (pTransactionSign envCli) $ Opt.progDesc "Sign a transaction" + , Just + $ subParser "echo" + $ Opt.info pTransactionEcho + $ Opt.progDesc "Echo a transaction" , Just $ subParser "witness" $ Opt.info (pTransactionCreateWitness envCli) @@ -274,7 +278,7 @@ pTransactionBuildRaw era = <*> pProposalFiles era ManualBalance <*> pTxBodyFileOut -pTransactionSign :: EnvCli -> Parser (TransactionCmds era) +pTransactionSign :: EnvCli -> Parser (TransactionCmds era) pTransactionSign envCli = fmap TransactionSignCmd $ TransactionSignCmdArgs @@ -283,6 +287,13 @@ pTransactionSign envCli = <*> optional (pNetworkId envCli) <*> pTxFileOut +pTransactionEcho :: Parser (TransactionCmds era) +pTransactionEcho = + fmap TransactionEchoCmd $ + TransactionEchoCmdArgs + <$> pInputTxOrTxBodyFile + <*> pTxFileOut + pTransactionCreateWitness :: EnvCli -> Parser (TransactionCmds era) pTransactionCreateWitness envCli = fmap TransactionWitnessCmd $ diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs index 2d55cd2bd6..cc5f373a97 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs @@ -20,6 +20,7 @@ module Cardano.CLI.EraBased.Run.Transaction ( runTransactionCmds , runTransactionBuildCmd , runTransactionBuildRawCmd + , runTransactionEchoCmd , runTransactionSignCmd , runTransactionSubmitCmd , runTransactionCalculateMinFeeCmd @@ -83,6 +84,7 @@ runTransactionCmds = \case Cmd.TransactionBuildCmd args -> runTransactionBuildCmd args Cmd.TransactionBuildEstimateCmd args -> runTransactionBuildEstimateCmd args Cmd.TransactionBuildRawCmd args -> runTransactionBuildRawCmd args + Cmd.TransactionEchoCmd args -> runTransactionEchoCmd args Cmd.TransactionSignCmd args -> runTransactionSignCmd args Cmd.TransactionSubmitCmd args -> runTransactionSubmitCmd args Cmd.TransactionCalculateMinFeeCmd args -> runTransactionCalculateMinFeeCmd args @@ -1182,6 +1184,44 @@ runTransactionSignCmd lift (writeTxFileTextEnvelopeCddl sbe outTxFile tx) & onLeft (left . TxCmdWriteFileError) +-- ---------------------------------------------------------------------------- +-- Transaction echoing +-- + +runTransactionEchoCmd :: () + => Cmd.TransactionEchoCmdArgs + -> ExceptT TxCmdError IO () +runTransactionEchoCmd + Cmd.TransactionEchoCmdArgs + { txOrTxBodyFile = txOrTxBody + , outTxFile = outTxFile + } = do + + case txOrTxBody of + InputTxFile (File inputTxFilePath) -> do + inputTxFile <- liftIO $ fileOrPipe inputTxFilePath + anyTx <- lift (readFileTx inputTxFile) & onLeft (left . TxCmdTextEnvCddlError) + + InAnyShelleyBasedEra sbe tx <- pure anyTx + + lift (writeTxFileTextEnvelopeCddl sbe outTxFile tx) + & onLeft (left . TxCmdWriteFileError) + + InputTxBodyFile (File txbodyFilePath) -> do + txbodyFile <- liftIO $ fileOrPipe txbodyFilePath + unwitnessed <- firstExceptT TxCmdTextEnvCddlError . newExceptT $ readFileTxBody txbodyFile + + case unwitnessed of + IncompleteCddlTxBody anyTxBody -> do + InAnyShelleyBasedEra sbe txbody <- pure anyTxBody + + let tx = makeSignedTransaction [] txbody + + firstExceptT TxCmdWriteFileError . newExceptT + $ writeLazyByteStringFile outTxFile + $ shelleyBasedEraConstraints sbe + $ textEnvelopeToJSON Nothing tx + -- ---------------------------------------------------------------------------- -- Transaction submission -- diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli index 7b90873625..9b22c31a40 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -823,6 +823,7 @@ Usage: cardano-cli shelley transaction ( build-raw | build | sign + | echo | witness | assemble | submit @@ -1101,6 +1102,14 @@ Usage: cardano-cli shelley transaction sign Sign a transaction +Usage: cardano-cli shelley transaction echo + ( --tx-body-file FILE + | --tx-file FILE + ) + --out-file FILE + + Echo a transaction + Usage: cardano-cli shelley transaction witness --tx-body-file FILE --signing-key-file FILE [--address STRING] @@ -2018,6 +2027,7 @@ Usage: cardano-cli allegra transaction ( build-raw | build | sign + | echo | witness | assemble | submit @@ -2296,6 +2306,14 @@ Usage: cardano-cli allegra transaction sign Sign a transaction +Usage: cardano-cli allegra transaction echo + ( --tx-body-file FILE + | --tx-file FILE + ) + --out-file FILE + + Echo a transaction + Usage: cardano-cli allegra transaction witness --tx-body-file FILE --signing-key-file FILE [--address STRING] @@ -3205,6 +3223,7 @@ Usage: cardano-cli mary transaction | build | build-estimate | sign + | echo | witness | assemble | submit @@ -3608,6 +3627,11 @@ Usage: cardano-cli mary transaction sign (--tx-body-file FILE | --tx-file FILE) Sign a transaction +Usage: cardano-cli mary transaction echo (--tx-body-file FILE | --tx-file FILE) + --out-file FILE + + Echo a transaction + Usage: cardano-cli mary transaction witness --tx-body-file FILE --signing-key-file FILE [--address STRING] @@ -4527,6 +4551,7 @@ Usage: cardano-cli alonzo transaction | build | build-estimate | sign + | echo | witness | assemble | submit @@ -4937,6 +4962,14 @@ Usage: cardano-cli alonzo transaction sign Sign a transaction +Usage: cardano-cli alonzo transaction echo + ( --tx-body-file FILE + | --tx-file FILE + ) + --out-file FILE + + Echo a transaction + Usage: cardano-cli alonzo transaction witness --tx-body-file FILE --signing-key-file FILE [--address STRING] @@ -5881,6 +5914,7 @@ Usage: cardano-cli babbage transaction | build | build-estimate | sign + | echo | witness | assemble | submit @@ -6291,6 +6325,14 @@ Usage: cardano-cli babbage transaction sign Sign a transaction +Usage: cardano-cli babbage transaction echo + ( --tx-body-file FILE + | --tx-file FILE + ) + --out-file FILE + + Echo a transaction + Usage: cardano-cli babbage transaction witness --tx-body-file FILE --signing-key-file FILE [--address STRING] @@ -7683,6 +7725,7 @@ Usage: cardano-cli conway transaction | build | build-estimate | sign + | echo | witness | assemble | submit @@ -8134,6 +8177,14 @@ Usage: cardano-cli conway transaction sign Sign a transaction +Usage: cardano-cli conway transaction echo + ( --tx-body-file FILE + | --tx-file FILE + ) + --out-file FILE + + Echo a transaction + Usage: cardano-cli conway transaction witness --tx-body-file FILE --signing-key-file FILE [--address STRING] @@ -9075,6 +9126,7 @@ Usage: cardano-cli latest transaction | build | build-estimate | sign + | echo | witness | assemble | submit @@ -9485,6 +9537,14 @@ Usage: cardano-cli latest transaction sign Sign a transaction +Usage: cardano-cli latest transaction echo + ( --tx-body-file FILE + | --tx-file FILE + ) + --out-file FILE + + Echo a transaction + Usage: cardano-cli latest transaction witness --tx-body-file FILE --signing-key-file FILE [--address STRING] diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_transaction.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_transaction.cli index aedd2c5223..0dab120242 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_transaction.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_transaction.cli @@ -2,6 +2,7 @@ Usage: cardano-cli allegra transaction ( build-raw | build | sign + | echo | witness | assemble | submit @@ -26,6 +27,7 @@ Available commands: Please note the order[93;22;23;24m of some cmd options is crucial. If used incorrectly may produce undesired tx body. See nested [] notation above for details.[0;22;23;24m sign Sign a transaction + echo Echo a transaction witness Create a transaction witness assemble Assemble a tx body and witness(es) to form a transaction diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_transaction_echo.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_transaction_echo.cli new file mode 100644 index 0000000000..894035cd90 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_transaction_echo.cli @@ -0,0 +1,13 @@ +Usage: cardano-cli allegra transaction echo + ( --tx-body-file FILE + | --tx-file FILE + ) + --out-file FILE + + Echo a transaction + +Available options: + --tx-body-file FILE Input filepath of the JSON TxBody. + --tx-file FILE Input filepath of the JSON Tx. + --out-file FILE Output filepath of the JSON Tx. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_transaction.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_transaction.cli index f4069516e8..bcb0c24e6f 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_transaction.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_transaction.cli @@ -3,6 +3,7 @@ Usage: cardano-cli alonzo transaction | build | build-estimate | sign + | echo | witness | assemble | submit @@ -30,6 +31,7 @@ Available commands: Please note the order[93;22;23;24m of some cmd options is crucial. If used incorrectly may produce undesired tx body. See nested [] notation above for details.[0;22;23;24m sign Sign a transaction + echo Echo a transaction witness Create a transaction witness assemble Assemble a tx body and witness(es) to form a transaction diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_transaction_echo.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_transaction_echo.cli new file mode 100644 index 0000000000..5eb209f41b --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_transaction_echo.cli @@ -0,0 +1,13 @@ +Usage: cardano-cli alonzo transaction echo + ( --tx-body-file FILE + | --tx-file FILE + ) + --out-file FILE + + Echo a transaction + +Available options: + --tx-body-file FILE Input filepath of the JSON TxBody. + --tx-file FILE Input filepath of the JSON Tx. + --out-file FILE Output filepath of the JSON Tx. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_transaction.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_transaction.cli index d999ca5ec8..b3bb932ee1 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_transaction.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_transaction.cli @@ -3,6 +3,7 @@ Usage: cardano-cli babbage transaction | build | build-estimate | sign + | echo | witness | assemble | submit @@ -30,6 +31,7 @@ Available commands: Please note the order[93;22;23;24m of some cmd options is crucial. If used incorrectly may produce undesired tx body. See nested [] notation above for details.[0;22;23;24m sign Sign a transaction + echo Echo a transaction witness Create a transaction witness assemble Assemble a tx body and witness(es) to form a transaction diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_transaction_echo.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_transaction_echo.cli new file mode 100644 index 0000000000..309a665c72 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_transaction_echo.cli @@ -0,0 +1,13 @@ +Usage: cardano-cli babbage transaction echo + ( --tx-body-file FILE + | --tx-file FILE + ) + --out-file FILE + + Echo a transaction + +Available options: + --tx-body-file FILE Input filepath of the JSON TxBody. + --tx-file FILE Input filepath of the JSON Tx. + --out-file FILE Output filepath of the JSON Tx. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_transaction.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_transaction.cli index 44c0dd0abe..1944caffb5 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_transaction.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_transaction.cli @@ -3,6 +3,7 @@ Usage: cardano-cli conway transaction | build | build-estimate | sign + | echo | witness | assemble | submit @@ -30,6 +31,7 @@ Available commands: Please note the order[93;22;23;24m of some cmd options is crucial. If used incorrectly may produce undesired tx body. See nested [] notation above for details.[0;22;23;24m sign Sign a transaction + echo Echo a transaction witness Create a transaction witness assemble Assemble a tx body and witness(es) to form a transaction diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_transaction_echo.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_transaction_echo.cli new file mode 100644 index 0000000000..3a7cfcd341 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_transaction_echo.cli @@ -0,0 +1,13 @@ +Usage: cardano-cli conway transaction echo + ( --tx-body-file FILE + | --tx-file FILE + ) + --out-file FILE + + Echo a transaction + +Available options: + --tx-body-file FILE Input filepath of the JSON TxBody. + --tx-file FILE Input filepath of the JSON Tx. + --out-file FILE Output filepath of the JSON Tx. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_transaction.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_transaction.cli index b420a63295..dc1b470fb8 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_transaction.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_transaction.cli @@ -3,6 +3,7 @@ Usage: cardano-cli latest transaction | build | build-estimate | sign + | echo | witness | assemble | submit @@ -30,6 +31,7 @@ Available commands: Please note the order[93;22;23;24m of some cmd options is crucial. If used incorrectly may produce undesired tx body. See nested [] notation above for details.[0;22;23;24m sign Sign a transaction + echo Echo a transaction witness Create a transaction witness assemble Assemble a tx body and witness(es) to form a transaction diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_transaction_echo.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_transaction_echo.cli new file mode 100644 index 0000000000..9557a2ba18 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_transaction_echo.cli @@ -0,0 +1,13 @@ +Usage: cardano-cli latest transaction echo + ( --tx-body-file FILE + | --tx-file FILE + ) + --out-file FILE + + Echo a transaction + +Available options: + --tx-body-file FILE Input filepath of the JSON TxBody. + --tx-file FILE Input filepath of the JSON Tx. + --out-file FILE Output filepath of the JSON Tx. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_transaction.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_transaction.cli index 24bfb695aa..1d8b4aa4bd 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_transaction.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_transaction.cli @@ -3,6 +3,7 @@ Usage: cardano-cli mary transaction | build | build-estimate | sign + | echo | witness | assemble | submit @@ -30,6 +31,7 @@ Available commands: Please note the order[93;22;23;24m of some cmd options is crucial. If used incorrectly may produce undesired tx body. See nested [] notation above for details.[0;22;23;24m sign Sign a transaction + echo Echo a transaction witness Create a transaction witness assemble Assemble a tx body and witness(es) to form a transaction diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_transaction_echo.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_transaction_echo.cli new file mode 100644 index 0000000000..ef5e7c3804 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_transaction_echo.cli @@ -0,0 +1,10 @@ +Usage: cardano-cli mary transaction echo (--tx-body-file FILE | --tx-file FILE) + --out-file FILE + + Echo a transaction + +Available options: + --tx-body-file FILE Input filepath of the JSON TxBody. + --tx-file FILE Input filepath of the JSON Tx. + --out-file FILE Output filepath of the JSON Tx. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_transaction.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_transaction.cli index 56647438fb..a0d0c34495 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_transaction.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_transaction.cli @@ -2,6 +2,7 @@ Usage: cardano-cli shelley transaction ( build-raw | build | sign + | echo | witness | assemble | submit @@ -26,6 +27,7 @@ Available commands: Please note the order[93;22;23;24m of some cmd options is crucial. If used incorrectly may produce undesired tx body. See nested [] notation above for details.[0;22;23;24m sign Sign a transaction + echo Echo a transaction witness Create a transaction witness assemble Assemble a tx body and witness(es) to form a transaction diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_transaction_echo.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_transaction_echo.cli new file mode 100644 index 0000000000..007ad713a4 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_transaction_echo.cli @@ -0,0 +1,13 @@ +Usage: cardano-cli shelley transaction echo + ( --tx-body-file FILE + | --tx-file FILE + ) + --out-file FILE + + Echo a transaction + +Available options: + --tx-body-file FILE Input filepath of the JSON TxBody. + --tx-file FILE Input filepath of the JSON Tx. + --out-file FILE Output filepath of the JSON Tx. + -h,--help Show this help text