Skip to content

Commit 8a70e1c

Browse files
committed
Remove deprecated functions and update types and update serialiseTxLedgerCddl
1 parent ab6fc23 commit 8a70e1c

File tree

3 files changed

+14
-76
lines changed

3 files changed

+14
-76
lines changed

cardano-api/src/Cardano/Api.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,6 @@ module Cardano.Api
736736
, deserialiseFromTextEnvelopeCddlAnyOf
737737
, writeTxFileTextEnvelopeCddl
738738
, writeTxWitnessFileTextEnvelopeCddl
739-
, serialiseTxLedgerCddl
740-
, deserialiseTxLedgerCddl
741739
, deserialiseByronTxCddl
742740
, serialiseWitnessLedgerCddl
743741
, deserialiseWitnessLedgerCddl

cardano-api/src/Cardano/Api/Internal/SerialiseLedgerCddl.hs

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ module Cardano.Api.Internal.SerialiseLedgerCddl
2222
, writeTxFileTextEnvelopeCddl
2323
, writeTxWitnessFileTextEnvelopeCddl
2424
-- Exported for testing
25-
, serialiseTxLedgerCddl
26-
, deserialiseTxLedgerCddl
2725
, deserialiseByronTxCddl
2826
, serialiseWitnessLedgerCddl
2927
, deserialiseWitnessLedgerCddl
@@ -122,46 +120,6 @@ instance Error TextEnvelopeCddlError where
122120
TextEnvelopeCddlErrByronKeyWitnessUnsupported ->
123121
"TextEnvelopeCddl error: Byron key witnesses are currently unsupported."
124122

125-
{-# DEPRECATED
126-
serialiseTxLedgerCddl
127-
"Use 'serialiseToTextEnvelope' from 'Cardano.Api.Internal.SerialiseTextEnvelope' instead."
128-
#-}
129-
serialiseTxLedgerCddl :: ShelleyBasedEra era -> Tx era -> TextEnvelope
130-
serialiseTxLedgerCddl era tx =
131-
shelleyBasedEraConstraints era $
132-
(serialiseToTextEnvelope (Just (TextEnvelopeDescr "Ledger Cddl Format")) tx)
133-
{ teType = TextEnvelopeType $ T.unpack $ genType tx
134-
}
135-
where
136-
genType :: Tx era -> Text
137-
genType tx' = case getTxWitnesses tx' of
138-
[] -> "Unwitnessed " <> genTxType
139-
_ -> "Witnessed " <> genTxType
140-
genTxType :: Text
141-
genTxType =
142-
case era of
143-
ShelleyBasedEraShelley -> "Tx ShelleyEra"
144-
ShelleyBasedEraAllegra -> "Tx AllegraEra"
145-
ShelleyBasedEraMary -> "Tx MaryEra"
146-
ShelleyBasedEraAlonzo -> "Tx AlonzoEra"
147-
ShelleyBasedEraBabbage -> "Tx BabbageEra"
148-
ShelleyBasedEraConway -> "Tx ConwayEra"
149-
150-
{-# DEPRECATED
151-
deserialiseTxLedgerCddl
152-
"Use 'deserialiseFromTextEnvelope' from 'Cardano.Api.Internal.SerialiseTextEnvelope' instead."
153-
#-}
154-
deserialiseTxLedgerCddl
155-
:: forall era
156-
. ShelleyBasedEra era
157-
-> TextEnvelope
158-
-> Either TextEnvelopeError (Tx era)
159-
deserialiseTxLedgerCddl era =
160-
shelleyBasedEraConstraints era $ deserialiseFromTextEnvelope asType
161-
where
162-
asType :: AsType (Tx era)
163-
asType = shelleyBasedEraConstraints era $ proxyToAsType Proxy
164-
165123
writeByronTxFileTextEnvelopeCddl
166124
:: File content Out
167125
-> Byron.ATxAux ByteString
@@ -254,6 +212,11 @@ writeTxFileTextEnvelopeCddl era path tx =
254212
where
255213
txJson = encodePretty' textEnvelopeCddlJSONConfig (serialiseTxLedgerCddl era tx) <> "\n"
256214

215+
serialiseTxLedgerCddl :: ShelleyBasedEra era -> Tx era -> TextEnvelope
216+
serialiseTxLedgerCddl era' tx' =
217+
shelleyBasedEraConstraints era' $
218+
serialiseToTextEnvelope (Just (TextEnvelopeDescr "Ledger Cddl Format")) tx'
219+
257220
writeTxWitnessFileTextEnvelopeCddl
258221
:: ShelleyBasedEra era
259222
-> File () Out
@@ -312,6 +275,15 @@ deserialiseFromTextEnvelopeCddlAnyOf types teCddl =
312275
matching (FromCDDLTx ttoken _f) = TextEnvelopeType (T.unpack ttoken) `legacyComparison` teType teCddl
313276
matching (FromCDDLWitness ttoken _f) = TextEnvelopeType (T.unpack ttoken) `legacyComparison` teType teCddl
314277

278+
deserialiseTxLedgerCddl
279+
:: forall era
280+
. ShelleyBasedEra era
281+
-> TextEnvelope
282+
-> Either TextEnvelopeError (Tx era)
283+
deserialiseTxLedgerCddl era =
284+
shelleyBasedEraConstraints era $
285+
deserialiseFromTextEnvelope (shelleyBasedEraConstraints era $ proxyToAsType Proxy)
286+
315287
-- Parse the text into types because this will increase code readability and
316288
-- will make it easier to keep track of the different Cddl descriptions via
317289
-- a single sum data type.

cardano-api/test/cardano-api-test/Test/Cardano/Api/CBOR.hs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ where
1313
import Cardano.Api
1414
import Cardano.Api.Internal.Script
1515
import Cardano.Api.Internal.SerialiseLedgerCddl (cddlTypeToEra)
16-
import Cardano.Api.Internal.SerialiseTextEnvelope (TextEnvelopeDescr (TextEnvelopeDescr))
1716
import Cardano.Api.Shelley (AsType (..))
1817

1918
import qualified Data.ByteString.Base16 as Base16
@@ -41,28 +40,6 @@ import Test.Tasty.Hedgehog (testProperty)
4140
-- TODO: Need to add PaymentExtendedKey roundtrip tests however
4241
-- we can't derive an Eq instance for Crypto.HD.XPrv
4342

44-
-- This is the same test as prop_roundtrip_witness_CBOR but uses the
45-
-- new function `serialiseTxLedgerCddl` instead of the deprecated
46-
-- `serialiseToTextEnvelope`. `deserialiseTxLedgerCddl` must be
47-
-- compatible with both during the transition.
48-
prop_forward_compatibility_txbody_CBOR :: Property
49-
prop_forward_compatibility_txbody_CBOR = H.property $ do
50-
AnyShelleyBasedEra era <- H.noteShowM . H.forAll $ Gen.element [minBound .. maxBound]
51-
x <- H.forAll $ makeSignedTransaction [] . fst <$> genValidTxBody era
52-
shelleyBasedEraConstraints
53-
era
54-
( H.tripping
55-
x
56-
(serialiseToTextEnvelope (Just (TextEnvelopeDescr "Ledger Cddl Format")))
57-
(deserialiseTxLedgerCddl era)
58-
)
59-
60-
prop_roundtrip_txbody_CBOR :: Property
61-
prop_roundtrip_txbody_CBOR = H.property $ do
62-
AnyShelleyBasedEra era <- H.noteShowM . H.forAll $ Gen.element [minBound .. maxBound]
63-
x <- H.forAll $ makeSignedTransaction [] . fst <$> genValidTxBody era
64-
H.tripping x (serialiseTxLedgerCddl era) (deserialiseTxLedgerCddl era)
65-
6643
prop_roundtrip_tx_CBOR :: Property
6744
prop_roundtrip_tx_CBOR = H.property $ do
6845
AnyShelleyBasedEra era <- H.noteShowM . H.forAll $ Gen.element [minBound .. maxBound]
@@ -289,12 +266,6 @@ prop_TxWitness_cddlTypeToEra = H.property $ do
289266
getProxy :: forall a. a -> Proxy a
290267
getProxy _ = Proxy
291268

292-
prop_roundtrip_Tx_Cddl :: Property
293-
prop_roundtrip_Tx_Cddl = H.property $ do
294-
AnyShelleyBasedEra era <- H.noteShowM . H.forAll $ Gen.element [minBound .. maxBound]
295-
x <- forAll $ genTx era
296-
H.tripping x (serialiseTxLedgerCddl era) (deserialiseTxLedgerCddl era)
297-
298269
prop_roundtrip_TxWitness_Cddl :: Property
299270
prop_roundtrip_TxWitness_Cddl = H.property $ do
300271
AnyShelleyBasedEra sbe <- H.noteShowM . H.forAll $ Gen.element [minBound .. maxBound]
@@ -404,9 +375,6 @@ tests =
404375
"roundtrip UpdateProposal CBOR"
405376
prop_roundtrip_UpdateProposal_CBOR
406377
, testProperty "roundtrip ScriptData CBOR" prop_roundtrip_ScriptData_CBOR
407-
, testProperty "roundtrip txbody forward compatibility CBOR" prop_forward_compatibility_txbody_CBOR
408-
, testProperty "roundtrip txbody CBOR" prop_roundtrip_txbody_CBOR
409-
, testProperty "roundtrip Tx Cddl" prop_roundtrip_Tx_Cddl
410378
, testProperty "roundtrip TxWitness Cddl" prop_roundtrip_TxWitness_Cddl
411379
, testProperty "roundtrip tx CBOR" prop_roundtrip_tx_CBOR
412380
, testProperty

0 commit comments

Comments
 (0)