Skip to content

Commit

Permalink
With the implementation and use MintScriptWitnessWithPolicyId era to
Browse files Browse the repository at this point in the history
handle all minting scripts (simple and plutus) we no longer have to
accomodate for the PolicyId in the constructors
PlutusReferenceScriptWitnessFiles and SimpleReferenceScriptWitnessFiles

This is evidenced by the diff of this commit

The goal is to deprecate ScriptWitnessFiles and replace it with a
collection of types for the different script purposes. The first example
of this is MintScriptWitnessWithPolicyId era
  • Loading branch information
Jimbo4350 committed Nov 21, 2024
1 parent 6c4869f commit bfee1ce
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
18 changes: 3 additions & 15 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,6 @@ pPlutusStakeReferenceScriptWitnessFilesVotingProposing prefix autoBalanceExecUni
AutoBalance -> pure (ExecutionUnits 0 0)
ManualBalance -> pExecutionUnits $ prefix ++ "reference-tx-in"
)
<*> pure Nothing

pPlutusStakeReferenceScriptWitnessFiles
:: String
Expand All @@ -1556,7 +1555,6 @@ pPlutusStakeReferenceScriptWitnessFiles prefix autoBalanceExecUnits =
AutoBalance -> pure (ExecutionUnits 0 0)
ManualBalance -> pExecutionUnits $ prefix ++ "reference-tx-in"
)
<*> pure Nothing

pPlutusScriptLanguage :: String -> Parser AnyPlutusScriptVersion
pPlutusScriptLanguage prefix = plutusP prefix PlutusScriptV2 "v2" <|> plutusP prefix PlutusScriptV3 "v3"
Expand Down Expand Up @@ -1947,14 +1945,14 @@ pTxIn sbe balance =
-> ScriptWitnessFiles WitCtxTxIn
createSimpleReferenceScriptWitnessFiles refTxIn =
let simpleLang = AnyScriptLanguage SimpleScriptLanguage
in SimpleReferenceScriptWitnessFiles refTxIn simpleLang Nothing
in SimpleReferenceScriptWitnessFiles refTxIn simpleLang

pPlutusReferenceScriptWitness
:: ShelleyBasedEra era -> BalanceTxExecUnits -> Parser (ScriptWitnessFiles WitCtxTxIn)
pPlutusReferenceScriptWitness sbe' autoBalanceExecUnits =
caseShelleyToBabbageOrConwayEraOnwards
( const $
createPlutusReferenceScriptWitnessFiles
PlutusReferenceScriptWitnessFiles
<$> pReferenceTxIn "spending-" "plutus"
<*> pPlutusScriptLanguage "spending-"
<*> pScriptDatumOrFile "spending-reference-tx-in" WitCtxTxIn
Expand All @@ -1965,7 +1963,7 @@ pTxIn sbe balance =
)
)
( const $
createPlutusReferenceScriptWitnessFiles
PlutusReferenceScriptWitnessFiles
<$> pReferenceTxIn "spending-" "plutus"
<*> pPlutusScriptLanguage "spending-"
<*> pScriptDatumOrFileCip69 "spending-reference-tx-in" WitCtxTxIn
Expand All @@ -1976,16 +1974,6 @@ pTxIn sbe balance =
)
)
sbe'
where
createPlutusReferenceScriptWitnessFiles
:: TxIn
-> AnyPlutusScriptVersion
-> ScriptDatumOrFile WitCtxTxIn
-> ScriptRedeemerOrFile
-> ExecutionUnits
-> ScriptWitnessFiles WitCtxTxIn
createPlutusReferenceScriptWitnessFiles refIn sLang sDatum sRedeemer execUnits =
PlutusReferenceScriptWitnessFiles refIn sLang sDatum sRedeemer execUnits Nothing

pEmbeddedPlutusScriptWitness :: Parser (ScriptWitnessFiles WitCtxTxIn)
pEmbeddedPlutusScriptWitness =
Expand Down
6 changes: 2 additions & 4 deletions cardano-cli/src/Cardano/CLI/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ readScriptWitness
datumOrFile
redeemerOrFile
execUnits
mPid
) = do
caseShelleyToAlonzoOrBabbageEraOnwards
( const $
Expand All @@ -381,7 +380,7 @@ readScriptWitness
PlutusScriptWitness
sLangInEra
version
(PReferenceScript refTxIn (unPolicyId <$> mPid))
(PReferenceScript refTxIn)
datum
redeemer
execUnits
Expand All @@ -397,7 +396,6 @@ readScriptWitness
( SimpleReferenceScriptWitnessFiles
refTxIn
anyScrLang@(AnyScriptLanguage anyScriptLanguage)
mPid
) = do
caseShelleyToAlonzoOrBabbageEraOnwards
( const $
Expand All @@ -411,7 +409,7 @@ readScriptWitness
case languageOfScriptLanguageInEra sLangInEra of
SimpleScriptLanguage ->
return . SimpleScriptWitness sLangInEra $
SReferenceScript refTxIn (unPolicyId <$> mPid)
SReferenceScript refTxIn
PlutusScriptLanguage{} ->
error "readScriptWitness: Should not be possible to specify a plutus script"
Nothing ->
Expand Down
14 changes: 5 additions & 9 deletions cardano-cli/src/Cardano/CLI/Types/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,7 @@ type ScriptRedeemerOrFile = ScriptDataOrFile
-- the script witness data representation.
--
-- It is era-independent, but witness context-dependent.
--
-- TODO: Potentially update to WitnessFiles so we can get
-- rid of Maybe (ScriptWitnessFiles). This will be clearer
-- in conveying that we either expect a script witness
-- or a key witness is provided at the signing stage.
-- NB: This is in the process of being deprecated
data ScriptWitnessFiles witctx where
SimpleScriptWitnessFile
:: ScriptFile
Expand All @@ -414,21 +410,21 @@ data ScriptWitnessFiles witctx where
-> ScriptRedeemerOrFile
-> ExecutionUnits
-> ScriptWitnessFiles witctx
-- TODO: Need to figure out how to exclude PlutusV1 scripts at the type level
-- NB: This no longer is used for minting scripts
-- Use MintScriptWitnessWithPolicyId instead
PlutusReferenceScriptWitnessFiles
:: TxIn
-> AnyPlutusScriptVersion
-> ScriptDatumOrFile witctx
-> ScriptRedeemerOrFile
-> ExecutionUnits
-> Maybe PolicyId
-- ^ For minting reference scripts
-> ScriptWitnessFiles witctx
-- NB: This no longer is used for minting scripts
-- Use MintScriptWitnessWithPolicyId instead
SimpleReferenceScriptWitnessFiles
:: TxIn
-> AnyScriptLanguage
-> Maybe PolicyId
-- ^ For minting reference scripts
-> ScriptWitnessFiles witctx

deriving instance Show (ScriptWitnessFiles witctx)
Expand Down

0 comments on commit bfee1ce

Please sign in to comment.