Skip to content

Commit f8281e5

Browse files
committed
Deduplicate the era case in readFileSimpleScript
Decode the JSON SimpleScript once and convert it to a Conway timelock before the era case, so each era branch is a single expression; this drops the obtainConwayConstraints wrapper and the TypeApplications pragma. Suggested by the review of #1427.
1 parent 1bae352 commit f8281e5

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

  • cardano-cli/src/Cardano/CLI/EraBased/Script/Read

cardano-cli/src/Cardano/CLI/EraBased/Script/Read/Common.hs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{-# LANGUAGE GADTs #-}
33
{-# LANGUAGE RankNTypes #-}
44
{-# LANGUAGE ScopedTypeVariables #-}
5-
{-# LANGUAGE TypeApplications #-}
65

76
module Cardano.CLI.EraBased.Script.Read.Common
87
( -- * Plutus Script Related
@@ -40,20 +39,16 @@ readFileSimpleScript
4039
readFileSimpleScript file era = do
4140
bs <- readFileCli file
4241
case deserialiseFromJSON bs of
43-
Left _ -> case era of
44-
Exp.DijkstraEra -> Exp.obtainCommonConstraints era $ do
45-
-- In addition to the TextEnvelope format, we also try to
46-
-- deserialize the JSON representation of SimpleScripts.
47-
script :: SimpleScript <- fromEitherCli $ Aeson.eitherDecodeStrict' bs
48-
let s :: L.NativeScript (Exp.LedgerEra era) =
49-
Dijkstra.upgradeTimelock (toAllegraTimelock @(Exp.LedgerEra Exp.ConwayEra) script)
50-
return $ Exp.SimpleScript s
51-
Exp.ConwayEra -> Exp.obtainConwayConstraints era $ do
52-
-- In addition to the TextEnvelope format, we also try to
53-
-- deserialize the JSON representation of SimpleScripts.
54-
script :: SimpleScript <- fromEitherCli $ Aeson.eitherDecodeStrict' bs
55-
let s :: L.NativeScript (Exp.LedgerEra era) = obtainCommonConstraints era $ toAllegraTimelock script
56-
return $ Exp.SimpleScript s
42+
Left _ -> do
43+
-- In addition to the TextEnvelope format, we also try to
44+
-- deserialize the JSON representation of SimpleScripts.
45+
script :: SimpleScript <- fromEitherCli $ Aeson.eitherDecodeStrict' bs
46+
let conwayTimelock :: L.NativeScript (Exp.LedgerEra Exp.ConwayEra)
47+
conwayTimelock = toAllegraTimelock script
48+
Exp.obtainCommonConstraints era $
49+
pure . Exp.SimpleScript $ case era of
50+
Exp.DijkstraEra -> Dijkstra.upgradeTimelock conwayTimelock
51+
Exp.ConwayEra -> conwayTimelock
5752
Right te -> do
5853
let scriptBs = teRawCBOR te
5954
obtainCommonConstraints era $

0 commit comments

Comments
 (0)