Skip to content

Commit 1bae352

Browse files
palascarbolymer
andcommitted
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 <mateusz.galazyn@iohk.io>
1 parent 6605fa1 commit 1bae352

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
description: |
2+
Simple scripts read from JSON files now work in the Dijkstra era, instead of aborting with an internal TODO error.
3+
kind:
4+
- feature
5+
pr: 1427
6+
project: cardano-cli

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

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

67
module Cardano.CLI.EraBased.Script.Read.Common
78
( -- * Plutus Script Related
@@ -21,6 +22,7 @@ import Cardano.CLI.Read (readFileCli)
2122
import Cardano.CLI.Type.Common
2223
import Cardano.CLI.Type.Error.ScriptDataError
2324
import Cardano.Ledger.Core qualified as L
25+
import Cardano.Ledger.Dijkstra.Scripts qualified as Dijkstra
2426

2527
import Prelude
2628

@@ -39,10 +41,16 @@ readFileSimpleScript file era = do
3941
bs <- readFileCli file
4042
case deserialiseFromJSON bs of
4143
Left _ -> case era of
42-
Exp.DijkstraEra -> error "TODO Dijkstra: Simple script not supported"
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
4351
Exp.ConwayEra -> Exp.obtainConwayConstraints era $ do
4452
-- In addition to the TextEnvelope format, we also try to
45-
-- deserialize the JSON representation of SimpleScripts..
53+
-- deserialize the JSON representation of SimpleScripts.
4654
script :: SimpleScript <- fromEitherCli $ Aeson.eitherDecodeStrict' bs
4755
let s :: L.NativeScript (Exp.LedgerEra era) = obtainCommonConstraints era $ toAllegraTimelock script
4856
return $ Exp.SimpleScript s

0 commit comments

Comments
 (0)