From 1bae3525f9aab675b39312e2e1091b6640d608a0 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Thu, 27 Aug 2026 12:51:50 +0200 Subject: [PATCH 1/2] Support Dijkstra simple scripts read from JSON Reading a JSON simple script in the Dijkstra era hit an error stub; upgrade the parsed Allegra-format timelock to the era's native script type via upgradeTimelock, the same conversion the api itself uses. Co-Authored-By: Mateusz Galazyn --- ...029_cardano-cli_palas_dijkstra_simple_scripts.yml | 6 ++++++ .../src/Cardano/CLI/EraBased/Script/Read/Common.hs | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 .changes/20260827_121029_cardano-cli_palas_dijkstra_simple_scripts.yml diff --git a/.changes/20260827_121029_cardano-cli_palas_dijkstra_simple_scripts.yml b/.changes/20260827_121029_cardano-cli_palas_dijkstra_simple_scripts.yml new file mode 100644 index 0000000000..f6ce790194 --- /dev/null +++ b/.changes/20260827_121029_cardano-cli_palas_dijkstra_simple_scripts.yml @@ -0,0 +1,6 @@ +description: | + Simple scripts read from JSON files now work in the Dijkstra era, instead of aborting with an internal TODO error. +kind: +- feature +pr: 1427 +project: cardano-cli diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Script/Read/Common.hs b/cardano-cli/src/Cardano/CLI/EraBased/Script/Read/Common.hs index 7c3254ad8c..72ad9fba19 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Script/Read/Common.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Script/Read/Common.hs @@ -2,6 +2,7 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeApplications #-} module Cardano.CLI.EraBased.Script.Read.Common ( -- * Plutus Script Related @@ -21,6 +22,7 @@ import Cardano.CLI.Read (readFileCli) import Cardano.CLI.Type.Common import Cardano.CLI.Type.Error.ScriptDataError import Cardano.Ledger.Core qualified as L +import Cardano.Ledger.Dijkstra.Scripts qualified as Dijkstra import Prelude @@ -39,10 +41,16 @@ readFileSimpleScript file era = do bs <- readFileCli file case deserialiseFromJSON bs of Left _ -> case era of - Exp.DijkstraEra -> error "TODO Dijkstra: Simple script not supported" + Exp.DijkstraEra -> Exp.obtainCommonConstraints era $ do + -- In addition to the TextEnvelope format, we also try to + -- deserialize the JSON representation of SimpleScripts. + script :: SimpleScript <- fromEitherCli $ Aeson.eitherDecodeStrict' bs + let s :: L.NativeScript (Exp.LedgerEra era) = + Dijkstra.upgradeTimelock (toAllegraTimelock @(Exp.LedgerEra Exp.ConwayEra) script) + return $ Exp.SimpleScript s Exp.ConwayEra -> Exp.obtainConwayConstraints era $ do -- In addition to the TextEnvelope format, we also try to - -- deserialize the JSON representation of SimpleScripts.. + -- deserialize the JSON representation of SimpleScripts. script :: SimpleScript <- fromEitherCli $ Aeson.eitherDecodeStrict' bs let s :: L.NativeScript (Exp.LedgerEra era) = obtainCommonConstraints era $ toAllegraTimelock script return $ Exp.SimpleScript s From f8281e5f7ee003e2924b16ff84b520ceaf754aaa Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Fri, 28 Aug 2026 12:01:09 +0000 Subject: [PATCH 2/2] 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. --- .../CLI/EraBased/Script/Read/Common.hs | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Script/Read/Common.hs b/cardano-cli/src/Cardano/CLI/EraBased/Script/Read/Common.hs index 72ad9fba19..c150f9a7d9 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Script/Read/Common.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Script/Read/Common.hs @@ -2,7 +2,6 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeApplications #-} module Cardano.CLI.EraBased.Script.Read.Common ( -- * Plutus Script Related @@ -40,20 +39,16 @@ readFileSimpleScript readFileSimpleScript file era = do bs <- readFileCli file case deserialiseFromJSON bs of - Left _ -> case era of - Exp.DijkstraEra -> Exp.obtainCommonConstraints era $ do - -- In addition to the TextEnvelope format, we also try to - -- deserialize the JSON representation of SimpleScripts. - script :: SimpleScript <- fromEitherCli $ Aeson.eitherDecodeStrict' bs - let s :: L.NativeScript (Exp.LedgerEra era) = - Dijkstra.upgradeTimelock (toAllegraTimelock @(Exp.LedgerEra Exp.ConwayEra) script) - return $ Exp.SimpleScript s - Exp.ConwayEra -> Exp.obtainConwayConstraints era $ do - -- In addition to the TextEnvelope format, we also try to - -- deserialize the JSON representation of SimpleScripts. - script :: SimpleScript <- fromEitherCli $ Aeson.eitherDecodeStrict' bs - let s :: L.NativeScript (Exp.LedgerEra era) = obtainCommonConstraints era $ toAllegraTimelock script - return $ Exp.SimpleScript s + Left _ -> do + -- In addition to the TextEnvelope format, we also try to + -- deserialize the JSON representation of SimpleScripts. + script :: SimpleScript <- fromEitherCli $ Aeson.eitherDecodeStrict' bs + let conwayTimelock :: L.NativeScript (Exp.LedgerEra Exp.ConwayEra) + conwayTimelock = toAllegraTimelock script + Exp.obtainCommonConstraints era $ + pure . Exp.SimpleScript $ case era of + Exp.DijkstraEra -> Dijkstra.upgradeTimelock conwayTimelock + Exp.ConwayEra -> conwayTimelock Right te -> do let scriptBs = teRawCBOR te obtainCommonConstraints era $