Skip to content

Commit 351f3f3

Browse files
Merge #4303
4303: Deprecate intermediate txbody format r=Jimbo4350 a=Jimbo4350 - You can no longer create tx bodies with the cli's intermediate format. - The flags `--cddl-format` and `--cli-format` are no longer available, we default to the CDDL format closes [#4277](#4277) Co-authored-by: Jordan Millar <[email protected]>
2 parents ece659c + 6e0052b commit 351f3f3

File tree

25 files changed

+183
-102
lines changed

25 files changed

+183
-102
lines changed

Diff for: cardano-api/gen/Gen/Hedgehog/Roundtrip/CBOR.hs

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
module Gen.Hedgehog.Roundtrip.CBOR
44
( roundtrip_CBOR
5+
, roundtrip_CDDL_Tx
56
) where
67

78
import Cardano.Api
@@ -19,3 +20,11 @@ roundtrip_CBOR typeProxy gen =
1920
H.property $ do
2021
val <- H.forAll gen
2122
H.tripping val serialiseToCBOR (deserialiseFromCBOR typeProxy)
23+
24+
25+
roundtrip_CDDL_Tx
26+
:: IsCardanoEra era => CardanoEra era -> Gen (Tx era) -> Property
27+
roundtrip_CDDL_Tx era gen =
28+
H.property $ do
29+
val <- H.forAll gen
30+
H.tripping val serialiseTxLedgerCddl (deserialiseTxLedgerCddl era)

Diff for: cardano-api/src/Cardano/Api/Error.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ data FileError e = FileError FilePath e
4848
-- ^ Temporary path
4949
Handle
5050
| FileIOError FilePath IOException
51-
deriving Show
51+
deriving (Show, Eq)
5252

5353
instance Error e => Error (FileError e) where
5454
displayError (FileErrorTempFile targetPath tempPath h)=

Diff for: cardano-api/src/Cardano/Api/SerialiseLedgerCddl.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ instance Error TextEnvelopeCddlError where
115115
<> List.intercalate ", " (map Text.unpack expTypes)
116116
<> " Actual: " <> Text.unpack actType
117117
displayError (TextEnvelopeCddlErrUnknownType unknownType) =
118-
"Unknown TextEnvelopeCddl type:" <> Text.unpack unknownType
118+
"Unknown TextEnvelopeCddl type: " <> Text.unpack unknownType
119119
displayError TextEnvelopeCddlErrByronKeyWitnessUnsupported =
120120
"TextEnvelopeCddl error: Byron key witnesses are currently unsupported."
121121

@@ -132,7 +132,6 @@ serialiseTxLedgerCddl tx =
132132
genType tx' = case getTxWitnesses tx' of
133133
[] -> "Unwitnessed " <> genTxType
134134
_ -> "Witnessed " <> genTxType
135-
136135
genTxType :: Text
137136
genTxType =
138137
case cardanoEra :: CardanoEra era of

Diff for: cardano-api/src/Cardano/Api/Tx.hs

+13
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module Cardano.Api.Tx (
2929
toShelleySigningKey,
3030
signByronTransaction,
3131
signShelleyTransaction,
32+
3233
-- ** Incremental signing and separate witnesses
3334
makeSignedTransaction,
3435
KeyWitness(..),
@@ -57,7 +58,9 @@ import qualified Data.ByteString.Lazy as LBS
5758
import Data.Functor.Identity (Identity)
5859
import qualified Data.Map.Strict as Map
5960
import qualified Data.Set as Set
61+
import Data.Type.Equality (TestEquality (..), (:~:) (Refl))
6062
import qualified Data.Vector as Vector
63+
6164
--
6265
-- Common types, consensus, network
6366
--
@@ -127,6 +130,16 @@ data Tx era where
127130
-> Ledger.Tx (ShelleyLedgerEra era)
128131
-> Tx era
129132

133+
134+
instance Show (InAnyCardanoEra Tx) where
135+
show (InAnyCardanoEra _ tx) = show tx
136+
137+
instance Eq (InAnyCardanoEra Tx) where
138+
(==) (InAnyCardanoEra eraA txA) (InAnyCardanoEra eraB txB) =
139+
case testEquality eraA eraB of
140+
Nothing -> False
141+
Just Refl -> txA == txB
142+
130143
-- The GADT in the ShelleyTx case requires a custom instance
131144
instance Eq (Tx era) where
132145
(==) (ByronTx txA)

Diff for: cardano-api/test/Test/Cardano/Api/Typed/CBOR.hs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ module Test.Cardano.Api.Typed.CBOR
88

99
import Cardano.Api
1010
import Cardano.Prelude
11-
import Data.String (IsString(..))
11+
import Data.String (IsString (..))
1212
import Gen.Cardano.Api.Typed
13-
import Gen.Hedgehog.Roundtrip.CBOR (roundtrip_CBOR)
13+
import Gen.Hedgehog.Roundtrip.CBOR (roundtrip_CBOR, roundtrip_CDDL_Tx)
1414
import Hedgehog (Property, forAll, property, success, tripping)
1515
import Test.Cardano.Api.Typed.Orphans ()
1616
import Test.Tasty (TestTree, testGroup)
@@ -24,14 +24,14 @@ import Test.Tasty.Hedgehog (testPropertyNamed)
2424
test_roundtrip_txbody_CBOR :: [TestTree]
2525
test_roundtrip_txbody_CBOR =
2626
[ testPropertyNamed (show era) (fromString (show era)) $
27-
roundtrip_CBOR (proxyToAsType Proxy) (genTxBody era)
28-
| AnyCardanoEra era <- [minBound..(AnyCardanoEra AlonzoEra)] -- TODO: Babbage era
27+
roundtrip_CDDL_Tx era (makeSignedTransaction [] <$> genTxBody era)
28+
| AnyCardanoEra era <- [minBound..(AnyCardanoEra BabbageEra)]
2929
]
3030

3131
test_roundtrip_tx_CBOR :: [TestTree]
3232
test_roundtrip_tx_CBOR =
3333
[ testPropertyNamed (show era) (fromString (show era)) $ roundtrip_CBOR (proxyToAsType Proxy) (genTx era)
34-
| AnyCardanoEra era <- [minBound..(AnyCardanoEra AlonzoEra)] -- TODO: Babbage era
34+
| AnyCardanoEra era <- [minBound..(AnyCardanoEra BabbageEra)]
3535
]
3636

3737
prop_roundtrip_witness_byron_CBOR :: Property

Diff for: cardano-cli/ChangeLog.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## vNext
44

5+
Default to the ledger's CDDL format for transaction body creation by removing flags `--cddl-format` and `--cli-format` from `build` and `build-raw` ([PR 4303](https://github.com/input-output-hk/cardano-node/pull/4303))
6+
57
### Bugs
68

79
- Allow reading signing keys from a pipe ([PR 4342](https://github.com/input-output-hk/cardano-node/pull/4342))

Diff for: cardano-cli/cardano-cli.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ test-suite cardano-cli-test
194194
, yaml
195195

196196
other-modules: Test.Config.Mainnet
197+
Test.Cli.CliIntermediateFormat
197198
Test.Cli.FilePermissions
198199
Test.Cli.ITN
199200
Test.Cli.JSON

Diff for: cardano-cli/src/Cardano/CLI/Shelley/Commands.hs

-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ data TransactionCmd
190190
[MetadataFile]
191191
(Maybe ProtocolParamsSourceSpec)
192192
(Maybe UpdateProposalFile)
193-
OutputSerialisation
194193
TxBodyFile
195194

196195
-- | Like 'TxBuildRaw' but without the fee, and with a change output.
@@ -233,7 +232,6 @@ data TransactionCmd
233232
[MetadataFile]
234233
(Maybe ProtocolParamsSourceSpec)
235234
(Maybe UpdateProposalFile)
236-
OutputSerialisation
237235
TxBuildOutputOptions
238236
| TxSign InputTxBodyOrTxFile [WitnessSigningData] (Maybe NetworkId) TxFile
239237
| TxCreateWitness TxBodyFile WitnessSigningData (Maybe NetworkId) OutputFile

Diff for: cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs

-13
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,6 @@ pTransaction =
718718
<*> many pMetadataFile
719719
<*> optional pProtocolParamsSourceSpec
720720
<*> optional pUpdateProposalFile
721-
<*> pOutputSerialisation
722721
<*> (OutputTxBodyOnly <$> pTxBodyFile Output <|> pCalculatePlutusScriptCost)
723722

724723
pChangeAddress :: Parser TxOutChangeAddress
@@ -755,7 +754,6 @@ pTransaction =
755754
<*> many pMetadataFile
756755
<*> optional pProtocolParamsSourceSpec
757756
<*> optional pUpdateProposalFile
758-
<*> pOutputSerialisation
759757
<*> pTxBodyFile Output
760758

761759
pTransactionSign :: Parser TransactionCmd
@@ -1768,17 +1766,6 @@ pOutputFormat =
17681766
<> Opt.value OutputFormatBech32
17691767
)
17701768

1771-
pOutputSerialisation :: Parser OutputSerialisation
1772-
pOutputSerialisation =
1773-
Opt.flag' OutputLedgerCDDLSerialisation
1774-
( Opt.long "cddl-format"
1775-
<> Opt.help "Serialise in the ledger CDDL specified CBOR format."
1776-
) <|>
1777-
Opt.flag OutputCliSerialisation OutputCliSerialisation
1778-
( Opt.long "cli-format"
1779-
<> Opt.help "Serialise in the cardano-cli CBOR format."
1780-
)
1781-
17821769
pMaybeOutputFile :: Parser (Maybe OutputFile)
17831770
pMaybeOutputFile =
17841771
optional $

Diff for: cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs

+33-26
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Cardano.CLI.Shelley.Run.Transaction
1212
( ShelleyTxCmdError(..)
1313
, renderShelleyTxCmdError
1414
, runTransactionCmd
15+
, readCddlTx
1516
, readFileTx
1617
, readProtocolParametersSourceSpec
1718
, toTxOutInAnyEra
@@ -317,17 +318,17 @@ runTransactionCmd cmd =
317318
TxBuild era consensusModeParams nid mScriptValidity mOverrideWits txins readOnlyRefIns
318319
reqSigners txinsc mReturnColl mTotCollateral txouts changeAddr mValue mLowBound
319320
mUpperBound certs wdrls metadataSchema scriptFiles metadataFiles mpparams
320-
mUpProp outputFormat output ->
321+
mUpProp output ->
321322
runTxBuild era consensusModeParams nid mScriptValidity txins readOnlyRefIns txinsc
322323
mReturnColl mTotCollateral txouts changeAddr mValue mLowBound
323324
mUpperBound certs wdrls reqSigners metadataSchema scriptFiles
324-
metadataFiles mpparams mUpProp outputFormat mOverrideWits output
325+
metadataFiles mpparams mUpProp mOverrideWits output
325326
TxBuildRaw era mScriptValidity txins readOnlyRefIns txinsc mReturnColl mTotColl reqSigners
326327
txouts mValue mLowBound mUpperBound fee certs wdrls metadataSchema scriptFiles
327-
metadataFiles mpparams mUpProp outputFormat out ->
328+
metadataFiles mpparams mUpProp out ->
328329
runTxBuildRaw era mScriptValidity txins readOnlyRefIns txinsc mReturnColl mTotColl txouts
329330
mLowBound mUpperBound fee mValue certs wdrls reqSigners metadataSchema
330-
scriptFiles metadataFiles mpparams mUpProp outputFormat out
331+
scriptFiles metadataFiles mpparams mUpProp out
331332
TxSign txinfile skfiles network txoutfile ->
332333
runTxSign txinfile skfiles network txoutfile
333334
TxSubmit anyConensusModeParams network txFp ->
@@ -383,7 +384,6 @@ runTxBuildRaw
383384
-> [MetadataFile]
384385
-> Maybe ProtocolParamsSourceSpec
385386
-> Maybe UpdateProposalFile
386-
-> OutputSerialisation
387387
-> TxBodyFile
388388
-> ExceptT ShelleyTxCmdError IO ()
389389
runTxBuildRaw (AnyCardanoEra era)
@@ -395,7 +395,6 @@ runTxBuildRaw (AnyCardanoEra era)
395395
certFiles withdrawals reqSigners
396396
metadataSchema scriptFiles
397397
metadataFiles mpparams mUpdatePropFile
398-
outputFormat
399398
(TxBodyFile fpath) = do
400399

401400
allReferenceInputs
@@ -426,14 +425,10 @@ runTxBuildRaw (AnyCardanoEra era)
426425
txBody <-
427426
firstExceptT ShelleyTxCmdTxBodyError . hoistEither $
428427
makeTransactionBody txBodyContent
429-
case outputFormat of
430-
OutputCliSerialisation ->
431-
firstExceptT ShelleyTxCmdWriteFileError . newExceptT $
432-
writeFileTextEnvelope fpath Nothing txBody
433-
OutputLedgerCDDLSerialisation ->
434-
let noWitTx = makeSignedTransaction [] txBody
435-
in firstExceptT ShelleyTxCmdWriteFileError . newExceptT $
436-
writeTxFileTextEnvelopeCddl fpath noWitTx
428+
429+
let noWitTx = makeSignedTransaction [] txBody
430+
firstExceptT ShelleyTxCmdWriteFileError . newExceptT $
431+
writeTxFileTextEnvelopeCddl fpath noWitTx
437432

438433
getSbe :: Monad m => CardanoEraStyle era -> ExceptT ShelleyTxCmdError m (Api.ShelleyBasedEra era)
439434
getSbe LegacyByronEra = left ShelleyTxCmdByronEra
@@ -490,14 +485,13 @@ runTxBuild
490485
-> [MetadataFile]
491486
-> Maybe ProtocolParamsSourceSpec
492487
-> Maybe UpdateProposalFile
493-
-> OutputSerialisation
494488
-> Maybe Word
495489
-> TxBuildOutputOptions
496490
-> ExceptT ShelleyTxCmdError IO ()
497491
runTxBuild (AnyCardanoEra era) (AnyConsensusModeParams cModeParams) networkId mScriptValidity
498492
txins readOnlyRefIns txinsc mReturnCollateral mtotcoll txouts (TxOutChangeAddress changeAddr) mValue mLowerBound mUpperBound
499493
certFiles withdrawals reqSigners metadataSchema scriptFiles metadataFiles mpparams
500-
mUpdatePropFile outputFormat mOverrideWits outputOptions = do
494+
mUpdatePropFile mOverrideWits outputOptions = do
501495
SocketPath sockPath <- firstExceptT ShelleyTxCmdSocketEnvError readEnvSocketPath
502496
let localNodeConnInfo = LocalNodeConnectInfo cModeParams networkId sockPath
503497
consensusMode = consensusModeOnly cModeParams
@@ -594,14 +588,9 @@ runTxBuild (AnyCardanoEra era) (AnyConsensusModeParams cModeParams) networkId mS
594588

595589
Nothing -> left ShelleyTxCmdPParamExecutionUnitsNotAvailable
596590
OutputTxBodyOnly (TxBodyFile fpath) ->
597-
case outputFormat of
598-
OutputCliSerialisation ->
599-
firstExceptT ShelleyTxCmdWriteFileError . newExceptT $
600-
writeFileTextEnvelope fpath Nothing balancedTxBody
601-
OutputLedgerCDDLSerialisation ->
602-
let noWitTx = makeSignedTransaction [] balancedTxBody
603-
in firstExceptT ShelleyTxCmdWriteFileError . newExceptT $
604-
writeTxFileTextEnvelopeCddl fpath noWitTx
591+
let noWitTx = makeSignedTransaction [] balancedTxBody
592+
in firstExceptT ShelleyTxCmdWriteFileError . newExceptT $
593+
writeTxFileTextEnvelopeCddl fpath noWitTx
605594

606595
(CardanoMode, LegacyByronEra) -> left ShelleyTxCmdByronEra
607596

@@ -1286,7 +1275,7 @@ runTxSign txOrTxBody witSigningData mnw (TxFile outTxFile) = do
12861275
signedTx = makeSignedTransaction allKeyWits txbody
12871276

12881277
firstExceptT ShelleyTxCmdWriteFileError . newExceptT $
1289-
writeFileTextEnvelope outTxFile Nothing signedTx
1278+
writeTxFileTextEnvelopeCddl outTxFile signedTx
12901279

12911280
(InputTxBodyFile (TxBodyFile txbodyFile)) -> do
12921281
unwitnessed <- readFileTxBody txbodyFile
@@ -1838,10 +1827,29 @@ readFileWitness fp =
18381827
-- (respectively needs additional witnesses or totally unwitnessed)
18391828
-- while UnwitnessedCliFormattedTxBody is CLI formatted TxBody and
18401829
-- needs to be key witnessed.
1830+
18411831
data IncompleteTx
18421832
= UnwitnessedCliFormattedTxBody (InAnyCardanoEra TxBody)
18431833
| IncompleteCddlFormattedTx (InAnyCardanoEra Tx)
18441834

1835+
1836+
readCddlTx :: FilePath -> IO (Either (FileError TextEnvelopeCddlError) CddlTx)
1837+
readCddlTx = readFileTextEnvelopeCddlAnyOf teTypes
1838+
where
1839+
teTypes = [ FromCDDLTx "Witnessed Tx ByronEra" CddlTx
1840+
, FromCDDLTx "Witnessed Tx ShelleyEra" CddlTx
1841+
, FromCDDLTx "Witnessed Tx AllegraEra" CddlTx
1842+
, FromCDDLTx "Witnessed Tx MaryEra" CddlTx
1843+
, FromCDDLTx "Witnessed Tx AlonzoEra" CddlTx
1844+
, FromCDDLTx "Witnessed Tx BabbageEra" CddlTx
1845+
, FromCDDLTx "Unwitnessed Tx ByronEra" CddlTx
1846+
, FromCDDLTx "Unwitnessed Tx ShelleyEra" CddlTx
1847+
, FromCDDLTx "Unwitnessed Tx AllegraEra" CddlTx
1848+
, FromCDDLTx "Unwitnessed Tx MaryEra" CddlTx
1849+
, FromCDDLTx "Unwitnessed Tx AlonzoEra" CddlTx
1850+
, FromCDDLTx "Unwitnessed Tx BabbageEra" CddlTx
1851+
]
1852+
18451853
readFileTxBody :: FilePath -> ExceptT ShelleyTxCmdError IO IncompleteTx
18461854
readFileTxBody fp =
18471855
handleLeftT
@@ -1887,7 +1895,6 @@ readFileTx fp =
18871895
(\e -> unCddlTx <$> acceptTxCDDLSerialisation e)
18881896
(readFileInAnyCardanoEra AsTx fp)
18891897

1890-
18911898
readFileInAnyCardanoEra
18921899
:: ( HasTextEnvelope (thing ByronEra)
18931900
, HasTextEnvelope (thing ShelleyEra)

Diff for: cardano-cli/src/Cardano/CLI/Types.hs

+1-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ module Cardano.CLI.Types
1919
, OpCertNodeStateCounter (..)
2020
, OpCertStartingKesPeriod (..)
2121
, OutputFormat (..)
22-
, OutputSerialisation (..)
2322
, TxBuildOutputOptions(..)
2423
, ReferenceScriptAnyEra (..)
2524
, SigningKeyFile (..)
@@ -76,7 +75,7 @@ data CBORObject = CBORBlockByron Byron.EpochSlots
7675
| CBORVoteByron
7776
deriving Show
7877

79-
newtype CddlTx = CddlTx {unCddlTx :: InAnyCardanoEra Tx}
78+
newtype CddlTx = CddlTx {unCddlTx :: InAnyCardanoEra Tx} deriving (Show, Eq)
8079

8180
-- Encompasses stake certificates, stake pool certificates,
8281
-- genesis delegate certificates and MIR certificates.
@@ -186,14 +185,6 @@ data OutputFormat
186185
| OutputFormatBech32
187186
deriving (Eq, Show)
188187

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

198189
-- | This data structure is used to allow nicely formatted output within the query stake-snapshot command.
199190
--

0 commit comments

Comments
 (0)