Skip to content

Commit

Permalink
Add serialisation format flag to build-raw cli command
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Jan 18, 2022
1 parent d5e3257 commit 05506c5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ data TransactionCmd
[MetadataFile]
(Maybe ProtocolParamsSourceSpec)
(Maybe UpdateProposalFile)
OutputSerialisation
TxBodyFile

-- | Like 'TxBuildRaw' but without the fee, and with a change output.
Expand Down
11 changes: 11 additions & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ pTransaction =
<*> many pMetadataFile
<*> optional pProtocolParamsSourceSpec
<*> optional pUpdateProposalFile
<*> pOutputSerialisation
<*> pTxBodyFile Output

pTransactionSign :: Parser TransactionCmd
Expand Down Expand Up @@ -1589,6 +1590,16 @@ pOutputFormat =
<> Opt.value OutputFormatBech32
)

pOutputSerialisation :: Parser OutputSerialisation
pOutputSerialisation =
Opt.flag' OutputLedgerCDDLSerialisation
( Opt.long "cddl-format"
<> Opt.help "Serialise in the ledger CDDL specified CBOR format."
) <|>
Opt.flag OutputCliSerialisation OutputCliSerialisation
( Opt.long "cli-format"
<> Opt.help "Serialise in the cardano-cli CBOR format."
)

pMaybeOutputFile :: Parser (Maybe OutputFile)
pMaybeOutputFile =
Expand Down
16 changes: 12 additions & 4 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ runTransactionCmd cmd =
metadataFiles mpparams mUpProp out mOverrideWits
TxBuildRaw era mScriptValidity txins txinsc reqSigners txouts mValue mLowBound mUpperBound
fee certs wdrls metadataSchema scriptFiles
metadataFiles mpparams mUpProp out ->
metadataFiles mpparams mUpProp outputFormat out ->
runTxBuildRaw era mScriptValidity txins txinsc txouts mLowBound mUpperBound
fee mValue certs wdrls reqSigners metadataSchema
scriptFiles metadataFiles mpparams mUpProp out
scriptFiles metadataFiles mpparams mUpProp outputFormat out
TxSign txinfile skfiles network txoutfile ->
runTxSign txinfile skfiles network txoutfile
TxSubmit anyConensusModeParams network txFp ->
Expand Down Expand Up @@ -342,6 +342,7 @@ runTxBuildRaw
-> [MetadataFile]
-> Maybe ProtocolParamsSourceSpec
-> Maybe UpdateProposalFile
-> OutputSerialisation
-> TxBodyFile
-> ExceptT ShelleyTxCmdError IO ()
runTxBuildRaw (AnyCardanoEra era)
Expand All @@ -351,6 +352,7 @@ runTxBuildRaw (AnyCardanoEra era)
certFiles withdrawals reqSigners
metadataSchema scriptFiles
metadataFiles mpparams mUpdatePropFile
outputFormat
(TxBodyFile fpath) = do
txBodyContent <-
TxBodyContent
Expand All @@ -374,9 +376,15 @@ runTxBuildRaw (AnyCardanoEra era)
txBody <-
firstExceptT ShelleyTxCmdTxBodyError . hoistEither $
makeTransactionBody txBodyContent
case outputFormat of
OutputCliSerialisation ->
firstExceptT ShelleyTxCmdWriteFileError . newExceptT $
writeFileTextEnvelope fpath Nothing txBody
OutputLedgerCDDLSerialisation ->
let noWitTx = makeSignedTransaction [] txBody
in firstExceptT ShelleyTxCmdWriteFileError . newExceptT $
writeTxFileTextEnvelopeCddl fpath noWitTx

firstExceptT ShelleyTxCmdWriteFileError . newExceptT $
writeFileTextEnvelope fpath Nothing txBody

runTxBuild
:: AnyCardanoEra
Expand Down
10 changes: 10 additions & 0 deletions cardano-cli/src/Cardano/CLI/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Cardano.CLI.Types
, EpochLeadershipSchedule (..)
, GenesisFile (..)
, OutputFormat (..)
, OutputSerialisation (..)
, SigningKeyFile (..)
, SocketPath (..)
, ScriptFile (..)
Expand Down Expand Up @@ -73,6 +74,15 @@ data OutputFormat
| OutputFormatBech32
deriving (Eq, Show)

-- | Specify whether to serialise a value according to the ledger's CDDL spec
-- or the cli' intermediate format. Note the intermediate format is defined
-- within SerialiseAsCBOR instances. The plan is to merge TextEnvelope with
-- SerialiseAsCBOR.
data OutputSerialisation
= OutputLedgerCDDLSerialisation
| OutputCliSerialisation
deriving Show

-- | This data structure is used to allow nicely formatted output within the query stake-snapshot command.
--
-- "markPool", "setPool", "goPool" are the three ledger state stake snapshots (from most recent to least recent)
Expand Down

0 comments on commit 05506c5

Please sign in to comment.