Skip to content

Commit 99d2eaf

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 844e83f + b35e1fb commit 99d2eaf

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
@@ -192,6 +192,7 @@ test-suite cardano-cli-test
192192
, yaml
193193

194194
other-modules: Test.Config.Mainnet
195+
Test.Cli.CliIntermediateFormat
195196
Test.Cli.FilePermissions
196197
Test.Cli.ITN
197198
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
@@ -280,17 +281,17 @@ runTransactionCmd cmd =
280281
TxBuild era consensusModeParams nid mScriptValidity mOverrideWits txins readOnlyRefIns
281282
reqSigners txinsc mReturnColl mTotCollateral txouts changeAddr mValue mLowBound
282283
mUpperBound certs wdrls metadataSchema scriptFiles metadataFiles mpparams
283-
mUpProp outputFormat output ->
284+
mUpProp output ->
284285
runTxBuild era consensusModeParams nid mScriptValidity txins readOnlyRefIns txinsc
285286
mReturnColl mTotCollateral txouts changeAddr mValue mLowBound
286287
mUpperBound certs wdrls reqSigners metadataSchema scriptFiles
287-
metadataFiles mpparams mUpProp outputFormat mOverrideWits output
288+
metadataFiles mpparams mUpProp mOverrideWits output
288289
TxBuildRaw era mScriptValidity txins readOnlyRefIns txinsc mReturnColl mTotColl reqSigners
289290
txouts mValue mLowBound mUpperBound fee certs wdrls metadataSchema scriptFiles
290-
metadataFiles mpparams mUpProp outputFormat out ->
291+
metadataFiles mpparams mUpProp out ->
291292
runTxBuildRaw era mScriptValidity txins readOnlyRefIns txinsc mReturnColl mTotColl txouts
292293
mLowBound mUpperBound fee mValue certs wdrls reqSigners metadataSchema
293-
scriptFiles metadataFiles mpparams mUpProp outputFormat out
294+
scriptFiles metadataFiles mpparams mUpProp out
294295
TxSign txinfile skfiles network txoutfile ->
295296
runTxSign txinfile skfiles network txoutfile
296297
TxSubmit anyConensusModeParams network txFp ->
@@ -346,7 +347,6 @@ runTxBuildRaw
346347
-> [MetadataFile]
347348
-> Maybe ProtocolParamsSourceSpec
348349
-> Maybe UpdateProposalFile
349-
-> OutputSerialisation
350350
-> TxBodyFile
351351
-> ExceptT ShelleyTxCmdError IO ()
352352
runTxBuildRaw (AnyCardanoEra era)
@@ -358,7 +358,6 @@ runTxBuildRaw (AnyCardanoEra era)
358358
certFiles withdrawals reqSigners
359359
metadataSchema scriptFiles
360360
metadataFiles mpparams mUpdatePropFile
361-
outputFormat
362361
(TxBodyFile fpath) = do
363362

364363
allReferenceInputs
@@ -404,14 +403,10 @@ runTxBuildRaw (AnyCardanoEra era)
404403
txBody <-
405404
firstExceptT ShelleyTxCmdTxBodyError . hoistEither $
406405
makeTransactionBody txBodyContent
407-
case outputFormat of
408-
OutputCliSerialisation ->
409-
firstExceptT ShelleyTxCmdWriteFileError . newExceptT $
410-
writeFileTextEnvelope fpath Nothing txBody
411-
OutputLedgerCDDLSerialisation ->
412-
let noWitTx = makeSignedTransaction [] txBody
413-
in firstExceptT ShelleyTxCmdWriteFileError . newExceptT $
414-
writeTxFileTextEnvelopeCddl fpath noWitTx
406+
407+
let noWitTx = makeSignedTransaction [] txBody
408+
firstExceptT ShelleyTxCmdWriteFileError . newExceptT $
409+
writeTxFileTextEnvelopeCddl fpath noWitTx
415410

416411
runTxBuild
417412
:: AnyCardanoEra
@@ -449,14 +444,13 @@ runTxBuild
449444
-> [MetadataFile]
450445
-> Maybe ProtocolParamsSourceSpec
451446
-> Maybe UpdateProposalFile
452-
-> OutputSerialisation
453447
-> Maybe Word
454448
-> TxBuildOutputOptions
455449
-> ExceptT ShelleyTxCmdError IO ()
456450
runTxBuild (AnyCardanoEra era) (AnyConsensusModeParams cModeParams) networkId mScriptValidity
457451
inputsAndScriptFiles readOnlyRefIns txinsc mReturnCollateral mTotCollateral txouts (TxOutChangeAddress changeAddr) mValue mLowerBound mUpperBound
458452
certFiles withdrawals reqSigners metadataSchema scriptFiles metadataFiles mpparams
459-
mUpdatePropFile outputFormat mOverrideWits outputOptions = do
453+
mUpdatePropFile mOverrideWits outputOptions = do
460454
let consensusMode = consensusModeOnly cModeParams
461455
dummyFee = Just $ Lovelace 0
462456
inputsThatRequireWitnessing = [input | (input,_) <- inputsAndScriptFiles]
@@ -548,14 +542,9 @@ runTxBuild (AnyCardanoEra era) (AnyConsensusModeParams cModeParams) networkId mS
548542

549543
Nothing -> left ShelleyTxCmdPParamExecutionUnitsNotAvailable
550544
OutputTxBodyOnly (TxBodyFile fpath) ->
551-
case outputFormat of
552-
OutputCliSerialisation ->
553-
firstExceptT ShelleyTxCmdWriteFileError . newExceptT $
554-
writeFileTextEnvelope fpath Nothing balancedTxBody
555-
OutputLedgerCDDLSerialisation ->
556-
let noWitTx = makeSignedTransaction [] balancedTxBody
557-
in firstExceptT ShelleyTxCmdWriteFileError . newExceptT $
558-
writeTxFileTextEnvelopeCddl fpath noWitTx
545+
let noWitTx = makeSignedTransaction [] balancedTxBody
546+
in firstExceptT ShelleyTxCmdWriteFileError . newExceptT $
547+
writeTxFileTextEnvelopeCddl fpath noWitTx
559548

560549
(CardanoMode, LegacyByronEra) -> left ShelleyTxCmdByronEra
561550

@@ -1217,7 +1206,7 @@ runTxSign txOrTxBody witSigningData mnw (TxFile outTxFile) = do
12171206
signedTx = makeSignedTransaction allKeyWits txbody
12181207

12191208
firstExceptT ShelleyTxCmdWriteFileError . newExceptT $
1220-
writeFileTextEnvelope outTxFile Nothing signedTx
1209+
writeTxFileTextEnvelopeCddl outTxFile signedTx
12211210

12221211
(InputTxBodyFile (TxBodyFile txbodyFile)) -> do
12231212
unwitnessed <- readFileTxBody txbodyFile
@@ -1770,10 +1759,29 @@ readFileWitness fp =
17701759
-- (respectively needs additional witnesses or totally unwitnessed)
17711760
-- while UnwitnessedCliFormattedTxBody is CLI formatted TxBody and
17721761
-- needs to be key witnessed.
1762+
17731763
data IncompleteTx
17741764
= UnwitnessedCliFormattedTxBody (InAnyCardanoEra TxBody)
17751765
| IncompleteCddlFormattedTx (InAnyCardanoEra Tx)
17761766

1767+
1768+
readCddlTx :: FilePath -> IO (Either (FileError TextEnvelopeCddlError) CddlTx)
1769+
readCddlTx = readFileTextEnvelopeCddlAnyOf teTypes
1770+
where
1771+
teTypes = [ FromCDDLTx "Witnessed Tx ByronEra" CddlTx
1772+
, FromCDDLTx "Witnessed Tx ShelleyEra" CddlTx
1773+
, FromCDDLTx "Witnessed Tx AllegraEra" CddlTx
1774+
, FromCDDLTx "Witnessed Tx MaryEra" CddlTx
1775+
, FromCDDLTx "Witnessed Tx AlonzoEra" CddlTx
1776+
, FromCDDLTx "Witnessed Tx BabbageEra" CddlTx
1777+
, FromCDDLTx "Unwitnessed Tx ByronEra" CddlTx
1778+
, FromCDDLTx "Unwitnessed Tx ShelleyEra" CddlTx
1779+
, FromCDDLTx "Unwitnessed Tx AllegraEra" CddlTx
1780+
, FromCDDLTx "Unwitnessed Tx MaryEra" CddlTx
1781+
, FromCDDLTx "Unwitnessed Tx AlonzoEra" CddlTx
1782+
, FromCDDLTx "Unwitnessed Tx BabbageEra" CddlTx
1783+
]
1784+
17771785
readFileTxBody :: FilePath -> ExceptT ShelleyTxCmdError IO IncompleteTx
17781786
readFileTxBody fp =
17791787
handleLeftT
@@ -1819,7 +1827,6 @@ readFileTx fp =
18191827
(\e -> unCddlTx <$> acceptTxCDDLSerialisation e)
18201828
(readFileInAnyCardanoEra AsTx fp)
18211829

1822-
18231830
readFileInAnyCardanoEra
18241831
:: ( HasTextEnvelope (thing ByronEra)
18251832
, 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 (..)
@@ -75,7 +74,7 @@ data CBORObject = CBORBlockByron Byron.EpochSlots
7574
| CBORVoteByron
7675
deriving Show
7776

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

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

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

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

0 commit comments

Comments
 (0)