From fafcea1c61a0e45561391b9354c11b6104db9806 Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Wed, 20 Nov 2024 15:13:56 -0400 Subject: [PATCH] Module split and rename suggestions --- cardano-cli/cardano-cli.cabal | 3 +- .../CLI/EraBased/Commands/Transaction.hs | 2 +- .../Cardano/CLI/EraBased/Options/Common.hs | 2 +- .../Cardano/CLI/EraBased/Run/Transaction.hs | 3 +- .../Script/Mint/Read.hs} | 96 +--------------- .../Cardano/CLI/EraBased/Script/Mint/Types.hs | 104 ++++++++++++++++++ .../Cardano/CLI/Types/Errors/TxCmdError.hs | 2 +- 7 files changed, 115 insertions(+), 97 deletions(-) rename cardano-cli/src/Cardano/CLI/{Plutus/Minting.hs => EraBased/Script/Mint/Read.hs} (58%) create mode 100644 cardano-cli/src/Cardano/CLI/EraBased/Script/Mint/Types.hs diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index 175fefa4d..437bb156e 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -116,6 +116,8 @@ library Cardano.CLI.EraBased.Run.StakePool Cardano.CLI.EraBased.Run.TextView Cardano.CLI.EraBased.Run.Transaction + Cardano.CLI.EraBased.Script.Mint.Read + Cardano.CLI.EraBased.Script.Mint.Types Cardano.CLI.EraBased.Transaction.HashCheck Cardano.CLI.Helpers Cardano.CLI.IO.Lazy @@ -135,7 +137,6 @@ library Cardano.CLI.Options.Key Cardano.CLI.Options.Node Cardano.CLI.Options.Ping - Cardano.CLI.Plutus.Minting Cardano.CLI.Orphans Cardano.CLI.Parser Cardano.CLI.Read diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs index 5cc225d40..de11edc37 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs @@ -25,7 +25,7 @@ import qualified Cardano.Api.Experimental as Exp import Cardano.Api.Ledger (Coin) import Cardano.Api.Shelley -import Cardano.CLI.Plutus.Minting +import Cardano.CLI.EraBased.Script.Mint.Types import Cardano.CLI.Types.Common import Cardano.CLI.Types.Governance diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs index 35aeaa702..fe5a1fd73 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs @@ -18,8 +18,8 @@ import qualified Cardano.Api.Network as Consensus import Cardano.Api.Shelley import Cardano.CLI.Environment (EnvCli (..), envCliAnyEon) +import Cardano.CLI.EraBased.Script.Mint.Types import Cardano.CLI.Parser -import Cardano.CLI.Plutus.Minting import Cardano.CLI.Read import Cardano.CLI.Types.Common import Cardano.CLI.Types.Governance diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs index 3940f377f..398c6816a 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs @@ -48,9 +48,10 @@ import Cardano.CLI.EraBased.Commands.Transaction import qualified Cardano.CLI.EraBased.Commands.Transaction as Cmd import Cardano.CLI.EraBased.Run.Genesis.Common (readProtocolParameters) import Cardano.CLI.EraBased.Run.Query +import Cardano.CLI.EraBased.Script.Mint.Read +import Cardano.CLI.EraBased.Script.Mint.Types import Cardano.CLI.EraBased.Transaction.HashCheck (checkCertificateHashes, checkProposalHashes, checkVotingProcedureHashes) -import Cardano.CLI.Plutus.Minting import Cardano.CLI.Read import Cardano.CLI.Types.Common import Cardano.CLI.Types.Errors.BootstrapWitnessError diff --git a/cardano-cli/src/Cardano/CLI/Plutus/Minting.hs b/cardano-cli/src/Cardano/CLI/EraBased/Script/Mint/Read.hs similarity index 58% rename from cardano-cli/src/Cardano/CLI/Plutus/Minting.hs rename to cardano-cli/src/Cardano/CLI/EraBased/Script/Mint/Read.hs index 5e5edaf01..3ff7db7e9 100644 --- a/cardano-cli/src/Cardano/CLI/Plutus/Minting.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Script/Mint/Read.hs @@ -1,106 +1,17 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} -{-# LANGUAGE LambdaCase #-} -module Cardano.CLI.Plutus.Minting - ( CliMintScriptRequirements (..) - , MintScriptWitnessWithPolicyId (..) - , createSimpleOrPlutusScriptFromCliArgs - , createSimpleReferenceScriptFromCliArgs - , createPlutusReferenceScriptFromCliArgs - , CliScriptWitnessError - , readMintScriptWitness +module Cardano.CLI.EraBased.Script.Mint.Read + ( readMintScriptWitness ) where import Cardano.Api import Cardano.Api.Shelley +import Cardano.CLI.EraBased.Script.Mint.Types import Cardano.CLI.Read -import Cardano.CLI.Types.Common (ScriptDataOrFile) - --- We always need the policy id when constructing a transaction that mints. --- In the case of reference scripts, the user currently must provide the policy id (script hash) --- in order to correctly construct the transaction. -data MintScriptWitnessWithPolicyId era - = MintScriptWitnessWithPolicyId - { mswPolId :: PolicyId - , mswScriptWitness :: ScriptWitness WitCtxMint era - } - deriving Show - -data CliMintScriptRequirements - = OnDiskSimpleOrPlutusScript OnDiskSimpleOrPlutusScriptCliArgs - | OnDiskSimpleRefScript SimpleRefScriptCliArgs - | OnDiskPlutusRefScript PlutusRefScriptCliArgs - deriving Show - -data OnDiskSimpleOrPlutusScriptCliArgs - = OnDiskSimpleScriptCliArgs - (File ScriptInAnyLang In) - | OnDiskPlutusScriptCliArgs - (File ScriptInAnyLang In) - ScriptDataOrFile - ExecutionUnits - deriving Show - -createSimpleOrPlutusScriptFromCliArgs - :: File ScriptInAnyLang In - -> Maybe (ScriptDataOrFile, ExecutionUnits) - -> CliMintScriptRequirements -createSimpleOrPlutusScriptFromCliArgs scriptFp Nothing = - OnDiskSimpleOrPlutusScript $ OnDiskSimpleScriptCliArgs scriptFp -createSimpleOrPlutusScriptFromCliArgs scriptFp (Just (redeemerFile, execUnits)) = - OnDiskSimpleOrPlutusScript $ OnDiskPlutusScriptCliArgs scriptFp redeemerFile execUnits - -data SimpleRefScriptCliArgs - = SimpleRefScriptCliArgs - TxIn - PolicyId - deriving Show - -createSimpleReferenceScriptFromCliArgs - :: TxIn - -> PolicyId - -> CliMintScriptRequirements -createSimpleReferenceScriptFromCliArgs txin polid = - OnDiskSimpleRefScript $ SimpleRefScriptCliArgs txin polid - -data PlutusRefScriptCliArgs - = PlutusRefScriptCliArgs - TxIn - AnyPlutusScriptVersion - ScriptDataOrFile - ExecutionUnits - PolicyId - deriving Show - -createPlutusReferenceScriptFromCliArgs - :: TxIn - -> AnyPlutusScriptVersion - -> ScriptDataOrFile - -> ExecutionUnits - -> PolicyId - -> CliMintScriptRequirements -createPlutusReferenceScriptFromCliArgs txin scriptVersion scriptData execUnits polid = - OnDiskPlutusRefScript $ PlutusRefScriptCliArgs txin scriptVersion scriptData execUnits polid - -data CliScriptWitnessError - = SimpleScriptWitnessDecodeError ScriptDecodeError - | PlutusScriptWitnessDecodeError PlutusScriptDecodeError - | PlutusScriptWitnessLanguageNotSupportedInEra - AnyPlutusScriptVersion - AnyShelleyBasedEra - | PlutusScriptWitnessRedeemerError ScriptDataError - -instance Error CliScriptWitnessError where - prettyError = \case - SimpleScriptWitnessDecodeError err -> prettyError err - PlutusScriptWitnessDecodeError err -> prettyError err - PlutusScriptWitnessLanguageNotSupportedInEra version era -> - "Plutus script version " <> pshow version <> " is not supported in era " <> pshow era - PlutusScriptWitnessRedeemerError err -> renderScriptDataError err readMintScriptWitness :: MonadIOTransError (FileError CliScriptWitnessError) t m @@ -190,6 +101,7 @@ readMintScriptWitness redeemer execUnits +-- TODO: Remove me when exposed from cardano-api sbeToSimpleScriptLangInEra :: ShelleyBasedEra era -> ScriptLanguageInEra SimpleScript' era sbeToSimpleScriptLangInEra ShelleyBasedEraShelley = SimpleScriptInShelley diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Script/Mint/Types.hs b/cardano-cli/src/Cardano/CLI/EraBased/Script/Mint/Types.hs new file mode 100644 index 000000000..c4c93b9e8 --- /dev/null +++ b/cardano-cli/src/Cardano/CLI/EraBased/Script/Mint/Types.hs @@ -0,0 +1,104 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE LambdaCase #-} + +module Cardano.CLI.EraBased.Script.Mint.Types + ( CliScriptWitnessError (..) + , CliMintScriptRequirements (..) + , SimpleOrPlutusScriptCliArgs (..) + , createSimpleOrPlutusScriptFromCliArgs + , PlutusRefScriptCliArgs (..) + , createPlutusReferenceScriptFromCliArgs + , SimpleRefScriptCliArgs (..) + , createSimpleReferenceScriptFromCliArgs + , MintScriptWitnessWithPolicyId (..) + ) +where + +import Cardano.Api + +import Cardano.CLI.Read +import Cardano.CLI.Types.Common (ScriptDataOrFile) + +-- We always need the policy id when constructing a transaction that mints. +-- In the case of reference scripts, the user currently must provide the policy id (script hash) +-- in order to correctly construct the transaction. +data MintScriptWitnessWithPolicyId era + = MintScriptWitnessWithPolicyId + { mswPolId :: PolicyId + , mswScriptWitness :: ScriptWitness WitCtxMint era + } + deriving Show + +data CliMintScriptRequirements + = OnDiskSimpleOrPlutusScript SimpleOrPlutusScriptCliArgs + | OnDiskSimpleRefScript SimpleRefScriptCliArgs + | OnDiskPlutusRefScript PlutusRefScriptCliArgs + deriving Show + +data SimpleOrPlutusScriptCliArgs + = OnDiskSimpleScriptCliArgs + (File ScriptInAnyLang In) + | OnDiskPlutusScriptCliArgs + (File ScriptInAnyLang In) + ScriptDataOrFile + ExecutionUnits + deriving Show + +createSimpleOrPlutusScriptFromCliArgs + :: File ScriptInAnyLang In + -> Maybe (ScriptDataOrFile, ExecutionUnits) + -> CliMintScriptRequirements +createSimpleOrPlutusScriptFromCliArgs scriptFp Nothing = + OnDiskSimpleOrPlutusScript $ OnDiskSimpleScriptCliArgs scriptFp +createSimpleOrPlutusScriptFromCliArgs scriptFp (Just (redeemerFile, execUnits)) = + OnDiskSimpleOrPlutusScript $ OnDiskPlutusScriptCliArgs scriptFp redeemerFile execUnits + +data SimpleRefScriptCliArgs + = SimpleRefScriptCliArgs + TxIn + PolicyId + deriving Show + +createSimpleReferenceScriptFromCliArgs + :: TxIn + -> PolicyId + -> CliMintScriptRequirements +createSimpleReferenceScriptFromCliArgs txin polid = + OnDiskSimpleRefScript $ SimpleRefScriptCliArgs txin polid + +data PlutusRefScriptCliArgs + = PlutusRefScriptCliArgs + TxIn + AnyPlutusScriptVersion + ScriptDataOrFile + ExecutionUnits + PolicyId + deriving Show + +createPlutusReferenceScriptFromCliArgs + :: TxIn + -> AnyPlutusScriptVersion + -> ScriptDataOrFile + -> ExecutionUnits + -> PolicyId + -> CliMintScriptRequirements +createPlutusReferenceScriptFromCliArgs txin scriptVersion scriptData execUnits polid = + OnDiskPlutusRefScript $ PlutusRefScriptCliArgs txin scriptVersion scriptData execUnits polid + +data CliScriptWitnessError + = SimpleScriptWitnessDecodeError ScriptDecodeError + | PlutusScriptWitnessDecodeError PlutusScriptDecodeError + | PlutusScriptWitnessLanguageNotSupportedInEra + AnyPlutusScriptVersion + AnyShelleyBasedEra + | PlutusScriptWitnessRedeemerError ScriptDataError + +instance Error CliScriptWitnessError where + prettyError = \case + SimpleScriptWitnessDecodeError err -> prettyError err + PlutusScriptWitnessDecodeError err -> prettyError err + PlutusScriptWitnessLanguageNotSupportedInEra version era -> + "Plutus script version " <> pshow version <> " is not supported in era " <> pshow era + PlutusScriptWitnessRedeemerError err -> renderScriptDataError err diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs index 87820b3b7..4e5767742 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs @@ -19,7 +19,7 @@ import Cardano.Api.Consensus (EraMismatch (..)) import qualified Cardano.Api.Ledger as L import Cardano.Api.Shelley -import Cardano.CLI.Plutus.Minting +import Cardano.CLI.EraBased.Script.Mint.Types import Cardano.CLI.Read import Cardano.CLI.Types.Common import Cardano.CLI.Types.Errors.BootstrapWitnessError