Skip to content

Commit

Permalink
Propagate removal of type level tags SimpleScriptV1 and SimpleSccriptV2
Browse files Browse the repository at this point in the history
in cardano-cli
  • Loading branch information
Jimbo4350 committed Feb 27, 2023
1 parent 0fc287f commit 06238b7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 39 deletions.
2 changes: 2 additions & 0 deletions cardano-api/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

- **Breaking change** - `queryExpr` to return `IO (Either UnsupportedNtcVersionError a)` instead of `IO a`.
([PR4788](https://github.com/input-output-hk/cardano-node/pull/4788))

- **Breaking change** - Remove distinction between multisig and timelock scripts([PR4763](https://github.com/input-output-hk/cardano-node/pull/4763))

### Bugs

Expand Down
1 change: 0 additions & 1 deletion cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ import qualified Data.ByteString.Short as SBS
import Data.Coerce
import Data.Int (Int64)
import Data.Map.Strict (Map)
import Data.Maybe (maybeToList)
import Data.Ratio (Ratio, (%))
import Data.String
import Data.Word (Word64)
Expand Down
1 change: 0 additions & 1 deletion cardano-api/src/Cardano/Api/Script.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,6 @@ instance ToJSON SimpleScript where
instance FromJSON SimpleScript where
parseJSON = parseSimpleScript

-- TODO: Left off here. You need to comb through cardano-api's property tests concerning simple scripts
parseSimpleScript :: Value -> Aeson.Parser SimpleScript
parseSimpleScript v = parseScriptSig v <|>
parseScriptBefore v <|>
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2119,7 +2119,7 @@ pTxIn balance =
:: TxIn
-> ScriptWitnessFiles WitCtxTxIn
createSimpleReferenceScriptWitnessFiles refTxIn =
let simpleLang = AnyScriptLanguage (SimpleScriptLanguage SimpleScriptV2)
let simpleLang = AnyScriptLanguage SimpleScriptLanguage
in SimpleReferenceScriptWitnessFiles refTxIn simpleLang Nothing

pPlutusReferenceScriptWitness :: BalanceTxExecUnits -> Parser (ScriptWitnessFiles WitCtxTxIn)
Expand Down Expand Up @@ -2332,7 +2332,7 @@ pMintMultiAsset balanceExecUnits =
-> PolicyId
-> ScriptWitnessFiles WitCtxMint
createSimpleMintingReferenceScriptWitnessFiles refTxIn pid =
let simpleLang = AnyScriptLanguage (SimpleScriptLanguage SimpleScriptV2)
let simpleLang = AnyScriptLanguage SimpleScriptLanguage
in SimpleReferenceScriptWitnessFiles refTxIn simpleLang (Just pid)

pPlutusMintReferenceScriptWitnessFiles
Expand Down
42 changes: 12 additions & 30 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,8 @@ readScriptWitness era' (SimpleScriptWitnessFile (ScriptFile scriptFile)) = do
readFileScriptInAnyLang scriptFile
ScriptInEra langInEra script' <- validateScriptSupportedInEra era' script
case script' of
SimpleScript version sscript ->
return . SimpleScriptWitness
langInEra version $ SScript sscript
SimpleScript sscript ->
return . SimpleScriptWitness langInEra $ SScript sscript

-- If the supplied cli flags were for a simple script (i.e. the user did
-- not supply the datum, redeemer or ex units), but the script file turns
Expand Down Expand Up @@ -262,7 +261,7 @@ readScriptWitness era' (PlutusReferenceScriptWitnessFiles refTxIn
case scriptLanguageSupportedInEra era' anyScriptLanguage of
Just sLangInEra ->
case languageOfScriptLanguageInEra sLangInEra of
SimpleScriptLanguage _v ->
SimpleScriptLanguage ->
-- TODO: We likely need another datatype eg data ReferenceScriptWitness lang
-- in order to make this branch unrepresentable.
error "readScriptWitness: Should not be possible to specify a simple script"
Expand All @@ -287,8 +286,8 @@ readScriptWitness era' (SimpleReferenceScriptWitnessFiles refTxIn
case scriptLanguageSupportedInEra era' anyScriptLanguage of
Just sLangInEra ->
case languageOfScriptLanguageInEra sLangInEra of
SimpleScriptLanguage v ->
return . SimpleScriptWitness sLangInEra v
SimpleScriptLanguage ->
return . SimpleScriptWitness sLangInEra
$ SReferenceScript refTxIn (unPolicyId <$> mPid)
PlutusScriptLanguage{} ->
error "readScriptWitness: Should not be possible to specify a plutus script"
Expand Down Expand Up @@ -399,12 +398,11 @@ deserialiseScriptInAnyLang bs =
--
case deserialiseFromJSON AsTextEnvelope bs of
Left _ ->
-- The SimpleScript language has the property that it is backwards
-- compatible, so we can parse as the latest version and then downgrade
-- to the minimum version that has all the features actually used.
case deserialiseFromJSON (AsSimpleScript AsSimpleScriptV2) bs of
Left err -> Left (ScriptDecodeSimpleScriptError err)
Right script -> Right (toMinimumSimpleScriptVersion script)
-- In addition to the TextEnvelope format, we also try to
-- deserialize the JSON representation of SimpleScripts.
case Aeson.eitherDecodeStrict' bs of
Left err -> Left (ScriptDecodeSimpleScriptError $ JsonDecodeError err)
Right script -> Right $ ScriptInAnyLang SimpleScriptLanguage $ SimpleScript script

Right te ->
case deserialiseFromTextEnvelopeAnyOf textEnvTypes te of
Expand All @@ -416,11 +414,8 @@ deserialiseScriptInAnyLang bs =
-- script version.
textEnvTypes :: [FromSomeType HasTextEnvelope ScriptInAnyLang]
textEnvTypes =
[ FromSomeType (AsScript AsSimpleScriptV1)
(ScriptInAnyLang (SimpleScriptLanguage SimpleScriptV1))

, FromSomeType (AsScript AsSimpleScriptV2)
(ScriptInAnyLang (SimpleScriptLanguage SimpleScriptV2))
[ FromSomeType (AsScript AsSimpleScript)
(ScriptInAnyLang SimpleScriptLanguage)

, FromSomeType (AsScript AsPlutusScriptV1)
(ScriptInAnyLang (PlutusScriptLanguage PlutusScriptV1))
Expand All @@ -429,19 +424,6 @@ deserialiseScriptInAnyLang bs =
(ScriptInAnyLang (PlutusScriptLanguage PlutusScriptV2))
]

toMinimumSimpleScriptVersion :: SimpleScript SimpleScriptV2
-> ScriptInAnyLang
toMinimumSimpleScriptVersion s =
-- TODO alonzo: this will need to be adjusted when more versions are added
-- with appropriate helper functions it can probably be done in an
-- era-generic style
case adjustSimpleScriptVersion SimpleScriptV1 s of
Nothing -> ScriptInAnyLang (SimpleScriptLanguage SimpleScriptV2)
(SimpleScript SimpleScriptV2 s)
Just s' -> ScriptInAnyLang (SimpleScriptLanguage SimpleScriptV1)
(SimpleScript SimpleScriptV1 s')


-- Tx & TxBody

newtype CddlTx = CddlTx {unCddlTx :: InAnyCardanoEra Tx} deriving (Show, Eq)
Expand Down
10 changes: 5 additions & 5 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,8 @@ getAllReferenceInputs txins mintWitnesses certFiles withdrawals readOnlyRefIns =
case sWit of
PlutusScriptWitness _ _ (PReferenceScript refIn _) _ _ _ -> Just refIn
PlutusScriptWitness _ _ PScript{} _ _ _ -> Nothing
SimpleScriptWitness _ _ (SReferenceScript refIn _) -> Just refIn
SimpleScriptWitness _ _ SScript{} -> Nothing
SimpleScriptWitness _ (SReferenceScript refIn _) -> Just refIn
SimpleScriptWitness _ SScript{} -> Nothing

toAddressInAnyEra
:: CardanoEra era
Expand Down Expand Up @@ -1037,9 +1037,9 @@ createTxMintValue era (val, scriptWitnesses) =
witnessesExtra = Set.elems (witnessesProvided Set.\\ witnessesNeeded)

scriptWitnessPolicyId :: ScriptWitness witctx era -> Maybe PolicyId
scriptWitnessPolicyId (SimpleScriptWitness _ version (SScript script)) =
Just . scriptPolicyId $ SimpleScript version script
scriptWitnessPolicyId (SimpleScriptWitness _ _ (SReferenceScript _ mPid)) =
scriptWitnessPolicyId (SimpleScriptWitness _ (SScript script)) =
Just . scriptPolicyId $ SimpleScript script
scriptWitnessPolicyId (SimpleScriptWitness _ (SReferenceScript _ mPid)) =
PolicyId <$> mPid
scriptWitnessPolicyId (PlutusScriptWitness _ version (PScript script) _ _ _) =
Just . scriptPolicyId $ PlutusScript version script
Expand Down

0 comments on commit 06238b7

Please sign in to comment.