Skip to content

Commit

Permalink
New transaction echo command
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Jun 15, 2024
1 parent 1f81d15 commit c288b0e
Show file tree
Hide file tree
Showing 18 changed files with 222 additions and 1 deletion.
8 changes: 8 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Cardano.CLI.EraBased.Commands.Transaction
, TransactionBuildRawCmdArgs(..)
, TransactionBuildCmdArgs(..)
, TransactionBuildEstimateCmdArgs(..)
, TransactionEchoCmdArgs(..)
, TransactionSignCmdArgs(..)
, TransactionWitnessCmdArgs(..)
, TransactionSignWitnessCmdArgs(..)
Expand All @@ -33,6 +34,7 @@ data TransactionCmds era
= TransactionBuildRawCmd !(TransactionBuildRawCmdArgs era)
| TransactionBuildCmd !(TransactionBuildCmdArgs era)
| TransactionBuildEstimateCmd !(TransactionBuildEstimateCmdArgs era)
| TransactionEchoCmd !TransactionEchoCmdArgs
| TransactionSignCmd !TransactionSignCmdArgs
| TransactionWitnessCmd !TransactionWitnessCmdArgs
| TransactionSignWitnessCmd !TransactionSignWitnessCmdArgs
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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"
Expand Down
13 changes: 12 additions & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Options/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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 $
Expand Down
40 changes: 40 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Cardano.CLI.EraBased.Run.Transaction
( runTransactionCmds
, runTransactionBuildCmd
, runTransactionBuildRawCmd
, runTransactionEchoCmd
, runTransactionSignCmd
, runTransactionSubmitCmd
, runTransactionCalculateMinFeeCmd
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
--
Expand Down
60 changes: 60 additions & 0 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ Usage: cardano-cli shelley transaction
( build-raw
| build
| sign
| echo
| witness
| assemble
| submit
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -2018,6 +2027,7 @@ Usage: cardano-cli allegra transaction
( build-raw
| build
| sign
| echo
| witness
| assemble
| submit
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -3205,6 +3223,7 @@ Usage: cardano-cli mary transaction
| build
| build-estimate
| sign
| echo
| witness
| assemble
| submit
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -4527,6 +4551,7 @@ Usage: cardano-cli alonzo transaction
| build
| build-estimate
| sign
| echo
| witness
| assemble
| submit
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -5881,6 +5914,7 @@ Usage: cardano-cli babbage transaction
| build
| build-estimate
| sign
| echo
| witness
| assemble
| submit
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -7683,6 +7725,7 @@ Usage: cardano-cli conway transaction
| build
| build-estimate
| sign
| echo
| witness
| assemble
| submit
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -9075,6 +9126,7 @@ Usage: cardano-cli latest transaction
| build
| build-estimate
| sign
| echo
| witness
| assemble
| submit
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Usage: cardano-cli allegra transaction
( build-raw
| build
| sign
| echo
| witness
| assemble
| submit
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Usage: cardano-cli alonzo transaction
| build
| build-estimate
| sign
| echo
| witness
| assemble
| submit
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Usage: cardano-cli babbage transaction
| build
| build-estimate
| sign
| echo
| witness
| assemble
| submit
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Usage: cardano-cli conway transaction
| build
| build-estimate
| sign
| echo
| witness
| assemble
| submit
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit c288b0e

Please sign in to comment.