From 69979f33aad0d6080d8440d0e58250f407c5bf74 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Fri, 20 Sep 2024 00:50:04 +0200 Subject: [PATCH] Generate `TextEnvelope` types using `textEnvelopeType` directly --- cardano-cli/src/Cardano/CLI/Read.hs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Read.hs b/cardano-cli/src/Cardano/CLI/Read.hs index 68d1730ffc..dc5ab17416 100644 --- a/cardano-cli/src/Cardano/CLI/Read.hs +++ b/cardano-cli/src/Cardano/CLI/Read.hs @@ -124,6 +124,7 @@ import qualified Data.ByteString.Lazy.Char8 as LBS import Data.Function ((&)) import Data.IORef (IORef, newIORef, readIORef, writeIORef) import qualified Data.List as List +import Data.Proxy (Proxy (..)) import Data.String import Data.Text (Text) import qualified Data.Text as T @@ -627,10 +628,13 @@ readCddlTx = txTextEnvelopeTypes :: [Text] txTextEnvelopeTypes = - "TxSignedShelley" - : [ "Tx " <> T.pack (show $ toCardanoEra sbe) - | AnyShelleyBasedEra sbe <- [AnyShelleyBasedEra ShelleyBasedEraAllegra ..] - ] + [ let TextEnvelopeType d = shelleyBasedEraConstraints sbe $ textEnvelopeType (proxyToAsType (makeTxProxy sbe)) + in T.pack d + | AnyShelleyBasedEra sbe <- [minBound .. maxBound] + ] + where + makeTxProxy :: ShelleyBasedEra era -> Proxy (Tx era) + makeTxProxy _ = Proxy -- Tx witnesses @@ -690,9 +694,13 @@ readCddlWitness fp = do txWitnessTextEnvelopeTypes :: [Text] txWitnessTextEnvelopeTypes = - [ "TxWitness " <> T.pack (show $ toCardanoEra sbe) - | AnyShelleyBasedEra sbe <- [AnyShelleyBasedEra ShelleyBasedEraShelley ..] + [ let TextEnvelopeType d = shelleyBasedEraConstraints sbe $ textEnvelopeType (proxyToAsType (makeWitnessProxy sbe)) + in T.pack d + | AnyShelleyBasedEra sbe <- [minBound .. maxBound] ] + where + makeWitnessProxy :: ShelleyBasedEra era -> Proxy (KeyWitness era) + makeWitnessProxy _ = Proxy -- Witness handling