Skip to content

Commit

Permalink
#5052 Remove reading parameters from shelley genesis file
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Apr 11, 2023
1 parent c141b50 commit 35346b0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 55 deletions.
15 changes: 4 additions & 11 deletions cardano-cli/src/Cardano/CLI/Shelley/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module Cardano.CLI.Shelley.Commands
, OpCertCounterFile (..)
, OutputFile (..)
, ProtocolParamsFile (..)
, ProtocolParamsSourceSpec (..)
, WitnessFile (..)
, TxFile (..)
, InputTxBodyOrTxFile (..)
Expand Down Expand Up @@ -186,7 +185,7 @@ data TransactionCmd
[ScriptFile]
-- ^ Auxiliary scripts
[MetadataFile]
(Maybe ProtocolParamsSourceSpec)
(Maybe ProtocolParamsFile)
(Maybe UpdateProposalFile)
TxBodyFile

Expand Down Expand Up @@ -228,7 +227,7 @@ data TransactionCmd
[ScriptFile]
-- ^ Auxiliary scripts
[MetadataFile]
(Maybe ProtocolParamsSourceSpec)
(Maybe ProtocolParamsFile)
(Maybe UpdateProposalFile)
TxBuildOutputOptions
| TxSign InputTxBodyOrTxFile [WitnessSigningData] (Maybe NetworkId) TxFile
Expand All @@ -239,14 +238,14 @@ data TransactionCmd
| TxCalculateMinFee
TxBodyFile
(Maybe NetworkId)
ProtocolParamsSourceSpec
ProtocolParamsFile
TxInCount
TxOutCount
TxShelleyWitnessCount
TxByronWitnessCount
| TxCalculateMinRequiredUTxO
AnyCardanoEra
ProtocolParamsSourceSpec
ProtocolParamsFile
TxOutAnyEra
| TxHashScriptData
ScriptDataOrFile
Expand All @@ -256,12 +255,6 @@ data TransactionCmd
data InputTxBodyOrTxFile = InputTxBodyFile TxBodyFile | InputTxFile TxFile
deriving Show

data ProtocolParamsSourceSpec
= ParamsFromFile !ProtocolParamsFile
-- ^ Obtain protocol parameters from a file structured by the
-- 'cardano-api' 'ProtocolParameters' data type.
deriving Show

renderTransactionCmd :: TransactionCmd -> Text
renderTransactionCmd cmd =
case cmd of
Expand Down
13 changes: 4 additions & 9 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ pTransaction =
Nothing
"Filepath of auxiliary script(s)")
<*> many pMetadataFile
<*> optional pProtocolParamsSourceSpec
<*> optional pProtocolParamsFile
<*> optional pUpdateProposalFile
<*> (OutputTxBodyOnly <$> pTxBodyFile Output <|> pCalculatePlutusScriptCost)

Expand Down Expand Up @@ -764,7 +764,7 @@ pTransaction =
Nothing
"Filepath of auxiliary script(s)")
<*> many pMetadataFile
<*> optional pProtocolParamsSourceSpec
<*> optional pProtocolParamsFile
<*> optional pUpdateProposalFile
<*> pTxBodyFile Output

Expand Down Expand Up @@ -800,7 +800,7 @@ pTransaction =
TxCalculateMinFee
<$> pTxBodyFile Input
<*> optional pNetworkId
<*> pProtocolParamsSourceSpec
<*> pProtocolParamsFile
<*> pTxInCount
<*> pTxOutCount
<*> pTxShelleyWitnessCount
Expand All @@ -809,13 +809,9 @@ pTransaction =
pTransactionCalculateMinReqUTxO :: Parser TransactionCmd
pTransactionCalculateMinReqUTxO = TxCalculateMinRequiredUTxO
<$> pCardanoEra
<*> pProtocolParamsSourceSpec
<*> pProtocolParamsFile
<*> pTxOut

pProtocolParamsSourceSpec :: Parser ProtocolParamsSourceSpec
pProtocolParamsSourceSpec =
ParamsFromFile <$> pProtocolParamsFile

pTxHashScriptData :: Parser TransactionCmd
pTxHashScriptData = TxHashScriptData <$>
pScriptDataOrFile
Expand Down Expand Up @@ -1455,7 +1451,6 @@ pAddressKeyType =
<|>
pure AddressKeyShelley


pProtocolParamsFile :: Parser ProtocolParamsFile
pProtocolParamsFile =
ProtocolParamsFile <$>
Expand Down
9 changes: 1 addition & 8 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Cardano.CLI.Shelley.Run.Genesis
-- * Protocol Parameters
, ProtocolParamsError(..)
, renderProtocolParamsError
, readProtocolParametersSourceSpec
, readProtocolParameters
) where

import Control.DeepSeq (NFData, force)
Expand Down Expand Up @@ -1356,19 +1356,12 @@ readConwayGenesis fpath = do
data ProtocolParamsError
= ProtocolParamsErrorFile (FileError ())
| ProtocolParamsErrorJSON !FilePath !Text
| ProtocolParamsErrorGenesis !ShelleyGenesisCmdError

renderProtocolParamsError :: ProtocolParamsError -> Text
renderProtocolParamsError (ProtocolParamsErrorFile fileErr) =
Text.pack $ displayError fileErr
renderProtocolParamsError (ProtocolParamsErrorJSON fp jsonErr) =
"Error while decoding the protocol parameters at: " <> Text.pack fp <> " Error: " <> jsonErr
renderProtocolParamsError (ProtocolParamsErrorGenesis err) =
Text.pack $ displayError err

readProtocolParametersSourceSpec :: ProtocolParamsSourceSpec
-> ExceptT ProtocolParamsError IO ProtocolParameters
readProtocolParametersSourceSpec (ParamsFromFile f) = readProtocolParameters f

--TODO: eliminate this and get only the necessary params, and get them in a more
-- helpful way rather than requiring them as a local file.
Expand Down
48 changes: 21 additions & 27 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module Cardano.CLI.Shelley.Run.Transaction
, renderShelleyTxCmdError
, runTransactionCmd
, readFileTx
, readProtocolParametersSourceSpec
, toTxOutInAnyEra
) where

Expand Down Expand Up @@ -271,27 +270,24 @@ runTransactionCmd cmd =
case cmd of
TxBuild era consensusModeParams nid mScriptValidity mOverrideWits txins readOnlyRefIns
reqSigners txinsc mReturnColl mTotCollateral txouts changeAddr mValue mLowBound
mUpperBound certs wdrls metadataSchema scriptFiles metadataFiles mPparams
mUpperBound certs wdrls metadataSchema scriptFiles metadataFiles mProtocolParamsFile
mUpProp outputOptions -> do
runTxBuildCmd era consensusModeParams nid mScriptValidity mOverrideWits txins readOnlyRefIns
reqSigners txinsc mReturnColl mTotCollateral txouts changeAddr mValue mLowBound
mUpperBound certs wdrls metadataSchema scriptFiles metadataFiles mPparams
mUpProp outputOptions
mUpperBound certs wdrls metadataSchema scriptFiles metadataFiles mProtocolParamsFile mUpProp outputOptions
TxBuildRaw era mScriptValidity txins readOnlyRefIns txinsc mReturnColl
mTotColl reqSigners txouts mValue mLowBound mUpperBound fee certs wdrls
metadataSchema scriptFiles metadataFiles mpparams mUpProp out -> do
metadataSchema scriptFiles metadataFiles mProtocolParamsFile mUpProp out -> do
runTxBuildRawCmd era mScriptValidity txins readOnlyRefIns txinsc mReturnColl
mTotColl reqSigners txouts mValue mLowBound mUpperBound fee certs wdrls
metadataSchema scriptFiles metadataFiles mpparams mUpProp out
metadataSchema scriptFiles metadataFiles mProtocolParamsFile mUpProp out
TxSign txinfile skfiles network txoutfile ->
runTxSign txinfile skfiles network txoutfile
TxSubmit anyConsensusModeParams network txFp ->
runTxSubmit anyConsensusModeParams network txFp
TxCalculateMinFee txbody mnw pGenesisOrParamsFile nInputs nOutputs
nShelleyKeyWitnesses nByronKeyWitnesses ->
runTxCalculateMinFee txbody mnw pGenesisOrParamsFile nInputs nOutputs
nShelleyKeyWitnesses nByronKeyWitnesses
TxCalculateMinRequiredUTxO era pParamSpec txOuts -> runTxCalculateMinRequiredUTxO era pParamSpec txOuts
TxCalculateMinFee txbody mnw pParamsFile nInputs nOutputs nShelleyKeyWitnesses nByronKeyWitnesses ->
runTxCalculateMinFee txbody mnw pParamsFile nInputs nOutputs nShelleyKeyWitnesses nByronKeyWitnesses
TxCalculateMinRequiredUTxO era pParamsFile txOuts -> runTxCalculateMinRequiredUTxO era pParamsFile txOuts
TxHashScriptData scriptDataOrFile -> runTxHashScriptData scriptDataOrFile
TxGetTxId txinfile -> runTxGetTxId txinfile
TxView txinfile -> runTxView txinfile
Expand Down Expand Up @@ -327,14 +323,14 @@ runTxBuildCmd
-> TxMetadataJsonSchema
-> [ScriptFile]
-> [MetadataFile]
-> Maybe ProtocolParamsSourceSpec
-> Maybe ProtocolParamsFile
-> Maybe UpdateProposalFile
-> TxBuildOutputOptions
-> ExceptT ShelleyTxCmdError IO ()
runTxBuildCmd
(AnyCardanoEra cEra) consensusModeParams@(AnyConsensusModeParams cModeParams) nid mScriptValidity mOverrideWits txins readOnlyRefIns
reqSigners txinsc mReturnColl mTotCollateral txouts changeAddr mValue mLowBound
mUpperBound certs wdrls metadataSchema scriptFiles metadataFiles mPparams mUpProp outputOptions = do
mUpperBound certs wdrls metadataSchema scriptFiles metadataFiles mProtocolParamsFile mUpProp outputOptions = do
-- The user can specify an era prior to the era that the node is currently in.
-- We cannot use the user specified era to construct a query against a node because it may differ
-- from the node's era and this will result in the 'QueryEraMismatch' failure.
Expand Down Expand Up @@ -365,8 +361,8 @@ runTxBuildCmd
scripts <- firstExceptT ShelleyTxCmdScriptFileError $
mapM (readFileScriptInAnyLang . unScriptFile) scriptFiles
txAuxScripts <- hoistEither $ first ShelleyTxCmdAuxScriptsValidationError $ validateTxAuxScripts cEra scripts
mpparams <- forM mPparams $ \ppFp ->
firstExceptT ShelleyTxCmdProtocolParamsError (readProtocolParametersSourceSpec ppFp)
mpparams <- forM mProtocolParamsFile $ \ppf ->
firstExceptT ShelleyTxCmdProtocolParamsError (readProtocolParameters ppf)

mProp <- forM mUpProp $ \(UpdateProposalFile upFp) ->
firstExceptT ShelleyTxCmdReadTextViewFileError (newExceptT $ readFileTextEnvelope AsUpdateProposal upFp)
Expand Down Expand Up @@ -462,14 +458,14 @@ runTxBuildRawCmd
-> TxMetadataJsonSchema
-> [ScriptFile]
-> [MetadataFile]
-> Maybe ProtocolParamsSourceSpec
-> Maybe ProtocolParamsFile
-> Maybe UpdateProposalFile
-> TxBodyFile
-> ExceptT ShelleyTxCmdError IO ()
runTxBuildRawCmd
(AnyCardanoEra cEra) mScriptValidity txins readOnlyRefIns txinsc mReturnColl
mTotColl reqSigners txouts mValue mLowBound mUpperBound fee certs wdrls
metadataSchema scriptFiles metadataFiles mpparams mUpProp (TxBodyFile out) = do
metadataSchema scriptFiles metadataFiles mpParamsFile mUpProp (TxBodyFile out) = do
inputsAndMaybeScriptWits <- firstExceptT ShelleyTxCmdScriptWitnessError
$ readScriptWitnessFiles cEra txins
certFilesAndMaybeScriptWits <- firstExceptT ShelleyTxCmdScriptWitnessError
Expand All @@ -488,8 +484,8 @@ runTxBuildRawCmd
mapM (readFileScriptInAnyLang . unScriptFile) scriptFiles
txAuxScripts <- hoistEither $ first ShelleyTxCmdAuxScriptsValidationError $ validateTxAuxScripts cEra scripts

pparams <- forM mpparams $ \ppFp ->
firstExceptT ShelleyTxCmdProtocolParamsError (readProtocolParametersSourceSpec ppFp)
pparams <- forM mpParamsFile $ \ppf ->
firstExceptT ShelleyTxCmdProtocolParamsError (readProtocolParameters ppf)

mProp <- forM mUpProp $ \(UpdateProposalFile upFp) ->
firstExceptT ShelleyTxCmdReadTextViewFileError (newExceptT $ readFileTextEnvelope AsUpdateProposal upFp)
Expand Down Expand Up @@ -1146,22 +1142,21 @@ runTxSubmit (AnyConsensusModeParams cModeParams) network txFilePath = do
runTxCalculateMinFee
:: TxBodyFile
-> Maybe NetworkId
-> ProtocolParamsSourceSpec
-> ProtocolParamsFile
-> TxInCount
-> TxOutCount
-> TxShelleyWitnessCount
-> TxByronWitnessCount
-> ExceptT ShelleyTxCmdError IO ()
runTxCalculateMinFee (TxBodyFile txbodyFilePath) nw protocolParamsSourceSpec
runTxCalculateMinFee (TxBodyFile txbodyFilePath) nw pParamsFile
(TxInCount nInputs) (TxOutCount nOutputs)
(TxShelleyWitnessCount nShelleyKeyWitnesses)
(TxByronWitnessCount nByronKeyWitnesses) = do

txbodyFile <- liftIO $ fileOrPipe txbodyFilePath
unwitnessed <- firstExceptT ShelleyTxCmdCddlError . newExceptT
$ readFileTxBody txbodyFile
pparams <- firstExceptT ShelleyTxCmdProtocolParamsError
$ readProtocolParametersSourceSpec protocolParamsSourceSpec
pparams <- firstExceptT ShelleyTxCmdProtocolParamsError $ readProtocolParameters pParamsFile
case unwitnessed of
IncompleteCddlFormattedTx anyTx -> do
InAnyShelleyBasedEra _era unwitTx <-
Expand Down Expand Up @@ -1200,12 +1195,11 @@ runTxCalculateMinFee (TxBodyFile txbodyFilePath) nw protocolParamsSourceSpec

runTxCalculateMinRequiredUTxO
:: AnyCardanoEra
-> ProtocolParamsSourceSpec
-> ProtocolParamsFile
-> TxOutAnyEra
-> ExceptT ShelleyTxCmdError IO ()
runTxCalculateMinRequiredUTxO (AnyCardanoEra era) protocolParamsSourceSpec txOut = do
pp <- firstExceptT ShelleyTxCmdProtocolParamsError
$ readProtocolParametersSourceSpec protocolParamsSourceSpec
runTxCalculateMinRequiredUTxO (AnyCardanoEra era) pParamsFile txOut = do
pp <- firstExceptT ShelleyTxCmdProtocolParamsError (readProtocolParameters pParamsFile)
out <- toTxOutInAnyEra era txOut
case cardanoEraStyle era of
LegacyByronEra -> error "runTxCalculateMinRequiredUTxO: Byron era not implemented yet"
Expand Down

0 comments on commit 35346b0

Please sign in to comment.