Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new types to list of accepted types and remove deprecated ones #892

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 27 additions & 25 deletions cardano-cli/src/Cardano/CLI/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
Expand Down Expand Up @@ -37,6 +38,7 @@ module Cardano.CLI.Read
, readFileTx
, readFileTxBody
, readCddlTx -- For testing purposes
, txTextEnvelopeTypes -- For testing purposes

-- * Tx witnesses
, ReadWitnessSigningDataError (..)
Expand All @@ -47,6 +49,7 @@ module Cardano.CLI.Read
, CddlWitnessError (..)
, readFileTxKeyWitness
, readWitnessSigningData
, txWitnessTextEnvelopeTypes -- For testing purposes

-- * Required signer
, RequiredSignerError (..)
Expand Down Expand Up @@ -121,8 +124,10 @@ 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
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import qualified Data.Text.Encoding.Error as Text
Expand Down Expand Up @@ -617,23 +622,19 @@ instance Error CddlError where
prettyError e

readCddlTx :: FileOrPipe -> IO (Either (FileError TextEnvelopeCddlError) CddlTx)
readCddlTx = readFileOrPipeTextEnvelopeCddlAnyOf teTypes
readCddlTx =
readFileOrPipeTextEnvelopeCddlAnyOf $
map (`FromCDDLTx` CddlTx) txTextEnvelopeTypes

txTextEnvelopeTypes :: [Text]
txTextEnvelopeTypes =
[ let TextEnvelopeType d = shelleyBasedEraConstraints sbe $ textEnvelopeType (proxyToAsType (makeTxProxy sbe))
palas marked this conversation as resolved.
Show resolved Hide resolved
in T.pack d
| AnyShelleyBasedEra sbe <- [minBound .. maxBound]
]
where
teTypes =
[ FromCDDLTx "Witnessed Tx ShelleyEra" CddlTx
palas marked this conversation as resolved.
Show resolved Hide resolved
, FromCDDLTx "Witnessed Tx AllegraEra" CddlTx
, FromCDDLTx "Witnessed Tx MaryEra" CddlTx
, FromCDDLTx "Witnessed Tx AlonzoEra" CddlTx
, FromCDDLTx "Witnessed Tx BabbageEra" CddlTx
, FromCDDLTx "Witnessed Tx ConwayEra" CddlTx
, FromCDDLTx "Unwitnessed Tx ByronEra" CddlTx
, FromCDDLTx "Unwitnessed Tx ShelleyEra" CddlTx
, FromCDDLTx "Unwitnessed Tx AllegraEra" CddlTx
, FromCDDLTx "Unwitnessed Tx MaryEra" CddlTx
, FromCDDLTx "Unwitnessed Tx AlonzoEra" CddlTx
, FromCDDLTx "Unwitnessed Tx BabbageEra" CddlTx
, FromCDDLTx "Unwitnessed Tx ConwayEra" CddlTx
]
makeTxProxy :: ShelleyBasedEra era -> Proxy (Tx era)
makeTxProxy _ = Proxy

-- Tx witnesses

Expand Down Expand Up @@ -689,16 +690,17 @@ readCddlWitness
:: FilePath
-> IO (Either (FileError TextEnvelopeCddlError) CddlWitness)
readCddlWitness fp = do
readFileTextEnvelopeCddlAnyOf teTypes fp
readFileTextEnvelopeCddlAnyOf (map (`FromCDDLWitness` CddlWitness) txWitnessTextEnvelopeTypes) fp

txWitnessTextEnvelopeTypes :: [Text]
txWitnessTextEnvelopeTypes =
[ let TextEnvelopeType d = shelleyBasedEraConstraints sbe $ textEnvelopeType (proxyToAsType (makeWitnessProxy sbe))
in T.pack d
| AnyShelleyBasedEra sbe <- [minBound .. maxBound]
]
where
teTypes =
[ FromCDDLWitness "TxWitness ShelleyEra" CddlWitness
, FromCDDLWitness "TxWitness AllegraEra" CddlWitness
, FromCDDLWitness "TxWitness MaryEra" CddlWitness
, FromCDDLWitness "TxWitness AlonzoEra" CddlWitness
, FromCDDLWitness "TxWitness BabbageEra" CddlWitness
, FromCDDLWitness "TxWitness ConwayEra" CddlWitness
]
makeWitnessProxy :: ShelleyBasedEra era -> Proxy (KeyWitness era)
makeWitnessProxy _ = Proxy

-- Witness handling

Expand Down
Loading