Skip to content

Commit

Permalink
Prefer forM over case match over Maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Feb 8, 2023
1 parent cf33207 commit 2c41f5c
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs
Expand Up @@ -363,19 +363,13 @@ runTxBuildCmd
scripts <- firstExceptT ShelleyTxCmdScriptFileError $
mapM (readFileScriptInAnyLang . unScriptFile) scriptFiles
txAuxScripts <- hoistEither $ first ShelleyTxCmdAuxScriptsValidationError $ validateTxAuxScripts cEra scripts
mpparams <- case mPparams of
Just ppFp -> Just <$> firstExceptT ShelleyTxCmdProtocolParamsError (readProtocolParametersSourceSpec ppFp)
Nothing -> return Nothing

mProp <- case mUpProp of
Just (UpdateProposalFile upFp) ->
Just <$> firstExceptT ShelleyTxCmdReadTextViewFileError
(newExceptT $ readFileTextEnvelope AsUpdateProposal upFp)
Nothing -> return Nothing
mpparams <- forM mPparams $ \ppFp ->
firstExceptT ShelleyTxCmdProtocolParamsError (readProtocolParametersSourceSpec ppFp)

mProp <- forM mUpProp $ \(UpdateProposalFile upFp) ->
firstExceptT ShelleyTxCmdReadTextViewFileError (newExceptT $ readFileTextEnvelope AsUpdateProposal upFp)
requiredSigners <- mapM (firstExceptT ShelleyTxCmdRequiredSignerError . newExceptT . readRequiredSigner) reqSigners
mReturnCollateral <- case mReturnColl of
Just retCol -> Just <$> toTxOutInAnyEra cEra retCol
Nothing -> return Nothing
mReturnCollateral <- forM mReturnColl $ toTxOutInAnyEra cEra

txOuts <- mapM (toTxOutInAnyEra cEra) txouts

Expand Down Expand Up @@ -489,18 +483,15 @@ runTxBuildRawCmd
scripts <- firstExceptT ShelleyTxCmdScriptFileError $
mapM (readFileScriptInAnyLang . unScriptFile) scriptFiles
txAuxScripts <- hoistEither $ first ShelleyTxCmdAuxScriptsValidationError $ validateTxAuxScripts cEra scripts
pparams <- case mpparams of
Just ppFp -> Just <$> firstExceptT ShelleyTxCmdProtocolParamsError (readProtocolParametersSourceSpec ppFp)
Nothing -> return Nothing
mProp <- case mUpProp of
Just (UpdateProposalFile upFp) ->
Just <$> firstExceptT ShelleyTxCmdReadTextViewFileError
(newExceptT $ readFileTextEnvelope AsUpdateProposal upFp)
Nothing -> return Nothing

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

mProp <- forM mUpProp $ \(UpdateProposalFile upFp) ->
firstExceptT ShelleyTxCmdReadTextViewFileError (newExceptT $ readFileTextEnvelope AsUpdateProposal upFp)

requiredSigners <- mapM (firstExceptT ShelleyTxCmdRequiredSignerError . newExceptT . readRequiredSigner) reqSigners
mReturnCollateral <- case mReturnColl of
Just retCol -> Just <$> toTxOutInAnyEra cEra retCol
Nothing -> return Nothing
mReturnCollateral <- forM mReturnColl $ toTxOutInAnyEra cEra
txOuts <- mapM (toTxOutInAnyEra cEra) txouts

-- the same collateral input can be used for several plutus scripts
Expand Down

0 comments on commit 2c41f5c

Please sign in to comment.