Skip to content

Commit

Permalink
Module split and rename suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Nov 21, 2024
1 parent 8453b12 commit fafcea1
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 97 deletions.
3 changes: 2 additions & 1 deletion cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -190,6 +101,7 @@ readMintScriptWitness
redeemer
execUnits

-- TODO: Remove me when exposed from cardano-api
sbeToSimpleScriptLangInEra
:: ShelleyBasedEra era -> ScriptLanguageInEra SimpleScript' era
sbeToSimpleScriptLangInEra ShelleyBasedEraShelley = SimpleScriptInShelley
Expand Down
104 changes: 104 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Script/Mint/Types.hs
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fafcea1

Please sign in to comment.