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 Jan 10, 2023
1 parent a4badce commit 6edf77c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 37 deletions.
2 changes: 2 additions & 0 deletions cardano-api/ChangeLog.md
Expand Up @@ -14,6 +14,8 @@

- **Breaking change** - Reduce exposed modules in cardano-api ([PR4546](https://github.com/input-output-hk/cardano-node/pull/4546))

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

### Bugs

- Allow reading text envelopes from pipes ([PR 4384](https://github.com/input-output-hk/cardano-node/pull/4384))
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Expand Up @@ -2084,7 +2084,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 @@ -2273,7 +2273,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
Expand Up @@ -210,9 +210,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 @@ -261,7 +260,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 @@ -286,8 +285,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 @@ -398,12 +397,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 @@ -415,11 +413,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 @@ -428,19 +423,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
Expand Up @@ -866,8 +866,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 @@ -1020,9 +1020,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 6edf77c

Please sign in to comment.