From 6c6135151d13b5cc080fbd2e58dd1ebdfa24ef62 Mon Sep 17 00:00:00 2001 From: John Ky Date: Sat, 21 Jan 2023 14:59:28 +1100 Subject: [PATCH 1/8] Handle readEnvSocketPath with onLeft --- .../src/Cardano/CLI/Shelley/Run/Transaction.hs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs index 5050f9427e8..b5025ea14ec 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs @@ -20,9 +20,10 @@ module Cardano.CLI.Shelley.Run.Transaction import Control.Monad (forM_, void) import Control.Monad.IO.Class (MonadIO (..)) +import Control.Monad.Trans (MonadTrans (..)) import Control.Monad.Trans.Except (ExceptT) import Control.Monad.Trans.Except.Extra (firstExceptT, hoistEither, hoistMaybe, left, - newExceptT, onNothing) + newExceptT, onLeft, onNothing) import Data.Aeson.Encode.Pretty (encodePretty) import Data.Bifunctor (Bifunctor (..)) import qualified Data.ByteString.Char8 as BS @@ -349,8 +350,7 @@ runTxBuildCmd -- 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. - SocketPath sockPath <- firstExceptT ShelleyTxCmdSocketEnvError - $ newExceptT readEnvSocketPath + SocketPath sockPath <- lift readEnvSocketPath & onLeft (left . ShelleyTxCmdSocketEnvError) let localNodeConnInfo = LocalNodeConnectInfo { localConsensusModeParams = cModeParams @@ -706,8 +706,7 @@ runTxBuild era (AnyConsensusModeParams cModeParams) networkId mScriptValidity & onNothing (left (ShelleyTxCmdEraConsensusModeMismatchTxBalance outputOptions (AnyConsensusMode CardanoMode) (AnyCardanoEra era))) - SocketPath sockPath <- firstExceptT ShelleyTxCmdSocketEnvError - $ newExceptT readEnvSocketPath + SocketPath sockPath <- lift readEnvSocketPath & onLeft (left . ShelleyTxCmdSocketEnvError) let allTxInputs = inputsThatRequireWitnessing ++ allReferenceInputs ++ txinsc localNodeConnInfo = LocalNodeConnectInfo @@ -1141,9 +1140,7 @@ runTxSubmit -> FilePath -> ExceptT ShelleyTxCmdError IO () runTxSubmit (AnyConsensusModeParams cModeParams) network txFilePath = do - - SocketPath sockPath <- firstExceptT ShelleyTxCmdSocketEnvError - $ newExceptT readEnvSocketPath + SocketPath sockPath <- lift readEnvSocketPath & onLeft (left . ShelleyTxCmdSocketEnvError) txFile <- liftIO $ fileOrPipe txFilePath InAnyCardanoEra era tx <- firstExceptT ShelleyTxCmdCddlError . newExceptT From 5467e80b7b00fc0c6eab9077e1c363db01f5d893 Mon Sep 17 00:00:00 2001 From: John Ky Date: Sat, 21 Jan 2023 15:01:28 +1100 Subject: [PATCH 2/8] Handle readFileTx with onLeft --- .../src/Cardano/CLI/Shelley/Run/Transaction.hs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs index b5025ea14ec..bfa974319cd 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs @@ -1070,9 +1070,9 @@ runTxSign txOrTxBody witSigningData mnw (TxFile outTxFile) = do let (sksByron, sksShelley) = partitionSomeWitnesses $ map categoriseSomeWitness sks case txOrTxBody of - (InputTxFile (TxFile inputTxFilePath)) -> do + InputTxFile (TxFile inputTxFilePath) -> do inputTxFile <- liftIO $ fileOrPipe inputTxFilePath - anyTx <- firstExceptT ShelleyTxCmdCddlError . newExceptT $ readFileTx inputTxFile + anyTx <- lift (readFileTx inputTxFile) & onLeft (left . ShelleyTxCmdCddlError) InAnyShelleyBasedEra _era tx <- onlyInShelleyBasedEras "sign for Byron era transactions" anyTx @@ -1090,7 +1090,7 @@ runTxSign txOrTxBody witSigningData mnw (TxFile outTxFile) = do firstExceptT ShelleyTxCmdWriteFileError . newExceptT $ writeTxFileTextEnvelopeCddl outTxFile signedTx - (InputTxBodyFile (TxBodyFile txbodyFilePath)) -> do + InputTxBodyFile (TxBodyFile txbodyFilePath) -> do txbodyFile <- liftIO $ fileOrPipe txbodyFilePath unwitnessed <- firstExceptT ShelleyTxCmdCddlError . newExceptT $ readFileTxBody txbodyFile @@ -1143,8 +1143,7 @@ runTxSubmit (AnyConsensusModeParams cModeParams) network txFilePath = do SocketPath sockPath <- lift readEnvSocketPath & onLeft (left . ShelleyTxCmdSocketEnvError) txFile <- liftIO $ fileOrPipe txFilePath - InAnyCardanoEra era tx <- firstExceptT ShelleyTxCmdCddlError . newExceptT - $ readFileTx txFile + InAnyCardanoEra era tx <- lift (readFileTx txFile) & onLeft (left . ShelleyTxCmdCddlError) let cMode = AnyConsensusMode $ consensusModeOnly cModeParams eraInMode <- hoistMaybe (ShelleyTxCmdEraConsensusModeMismatch (Just txFilePath) cMode (AnyCardanoEra era)) @@ -1336,8 +1335,7 @@ runTxGetTxId txfile = do InputTxFile (TxFile txFilePath) -> do txFile <- liftIO $ fileOrPipe txFilePath - InAnyCardanoEra era tx <- firstExceptT ShelleyTxCmdCddlError . newExceptT - $ readFileTx txFile + InAnyCardanoEra era tx <- lift (readFileTx txFile) & onLeft (left . ShelleyTxCmdCddlError) return . InAnyCardanoEra era $ getTxBody tx liftIO $ BS.putStrLn $ serialiseToRawBytesHex (getTxId txbody) @@ -1359,8 +1357,7 @@ runTxView = \case liftIO $ BS.putStr $ friendlyTxBodyBS era txbody InputTxFile (TxFile txFilePath) -> do txFile <- liftIO $ fileOrPipe txFilePath - InAnyCardanoEra era tx <- firstExceptT ShelleyTxCmdCddlError . newExceptT - $ readFileTx txFile + InAnyCardanoEra era tx <- lift (readFileTx txFile) & onLeft (left . ShelleyTxCmdCddlError) liftIO $ BS.putStr $ friendlyTxBS era tx From afb7b1a1c06d4b21e67411a31b6e1cd08d107a97 Mon Sep 17 00:00:00 2001 From: John Ky Date: Sat, 21 Jan 2023 15:04:24 +1100 Subject: [PATCH 3/8] Handle writeTxFileTextEnvelopeCddl with onLeft --- .../Cardano/CLI/Shelley/Run/Transaction.hs | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs index bfa974319cd..4fc996e09ce 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs @@ -457,8 +457,9 @@ runTxBuildCmd Nothing -> left ShelleyTxCmdProtocolParametersNotPresentInTxBody OutputTxBodyOnly (TxBodyFile fpath) -> let noWitTx = makeSignedTransaction [] balancedTxBody - in firstExceptT ShelleyTxCmdWriteFileError . newExceptT $ - writeTxFileTextEnvelopeCddl fpath noWitTx + in lift (writeTxFileTextEnvelopeCddl fpath noWitTx) + & onLeft (left . ShelleyTxCmdWriteFileError) + runTxBuildRawCmd :: AnyCardanoEra @@ -527,8 +528,9 @@ runTxBuildRawCmd txMetadata pparams mProp let noWitTx = makeSignedTransaction [] txBody - firstExceptT ShelleyTxCmdWriteFileError . newExceptT $ - getIsCardanoEraConstraint cEra $ writeTxFileTextEnvelopeCddl out noWitTx + lift (getIsCardanoEraConstraint cEra $ writeTxFileTextEnvelopeCddl out noWitTx) + & onLeft (left . ShelleyTxCmdWriteFileError) + runTxBuildRaw :: CardanoEra era @@ -1087,8 +1089,8 @@ runTxSign txOrTxBody witSigningData mnw (TxFile outTxFile) = do allKeyWits = existingTxKeyWits ++ newShelleyKeyWits ++ byronWitnesses signedTx = makeSignedTransaction allKeyWits txbody - firstExceptT ShelleyTxCmdWriteFileError . newExceptT $ - writeTxFileTextEnvelopeCddl outTxFile signedTx + lift (writeTxFileTextEnvelopeCddl outTxFile signedTx) + & onLeft (left . ShelleyTxCmdWriteFileError) InputTxBodyFile (TxBodyFile txbodyFilePath) -> do txbodyFile <- liftIO $ fileOrPipe txbodyFilePath @@ -1110,8 +1112,8 @@ runTxSign txOrTxBody witSigningData mnw (TxFile outTxFile) = do let shelleyKeyWitnesses = map (makeShelleyKeyWitness txbody) sksShelley tx = makeSignedTransaction (byronWitnesses ++ shelleyKeyWitnesses) txbody - firstExceptT ShelleyTxCmdWriteFileError . newExceptT $ - writeTxFileTextEnvelopeCddl outTxFile tx + lift (writeTxFileTextEnvelopeCddl outTxFile tx) + & onLeft (left . ShelleyTxCmdWriteFileError) UnwitnessedCliFormattedTxBody anyTxbody -> do InAnyShelleyBasedEra _era txbody <- @@ -1464,8 +1466,7 @@ runTxSignWitness (TxBodyFile txbodyFilePath) witnessFiles (OutputFile oFp) = do let tx = makeSignedTransaction witnesses txbody - firstExceptT ShelleyTxCmdWriteFileError . newExceptT $ - writeTxFileTextEnvelopeCddl oFp tx + lift (writeTxFileTextEnvelopeCddl oFp tx) & onLeft (left . ShelleyTxCmdWriteFileError) -- | Constrain the era to be Shelley based. Fail for the Byron era. From e3b72e8931b41def4407de7650f3fb6367cb417c Mon Sep 17 00:00:00 2001 From: John Ky Date: Sat, 21 Jan 2023 15:05:31 +1100 Subject: [PATCH 4/8] Handle determineEra with onLeft --- cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs index 4fc996e09ce..bda4803da8c 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs @@ -358,9 +358,8 @@ runTxBuildCmd , localNodeSocketPath = sockPath } - AnyCardanoEra nodeEra - <- firstExceptT (ShelleyTxCmdQueryConvenienceError . AcqFailure) - . newExceptT $ determineEra cModeParams localNodeConnInfo + AnyCardanoEra nodeEra <- lift (determineEra cModeParams localNodeConnInfo) + & onLeft (left . ShelleyTxCmdQueryConvenienceError . AcqFailure) inputsAndMaybeScriptWits <- firstExceptT ShelleyTxCmdScriptWitnessError $ readScriptWitnessFiles cEra txins certFilesAndMaybeScriptWits <- firstExceptT ShelleyTxCmdScriptWitnessError $ readScriptWitnessFiles cEra certs @@ -716,9 +715,8 @@ runTxBuild era (AnyConsensusModeParams cModeParams) networkId mScriptValidity , localNodeNetworkId = networkId , localNodeSocketPath = sockPath } - AnyCardanoEra nodeEra - <- firstExceptT (ShelleyTxCmdQueryConvenienceError . AcqFailure) - . newExceptT $ determineEra cModeParams localNodeConnInfo + AnyCardanoEra nodeEra <- lift (determineEra cModeParams localNodeConnInfo) + & onLeft (left . ShelleyTxCmdQueryConvenienceError . AcqFailure) (nodeEraUTxO, pparams, eraHistory, systemStart, stakePools) <- firstExceptT ShelleyTxCmdQueryConvenienceError . newExceptT From 4c482a95d8a3996459193dec7a619350e0405513 Mon Sep 17 00:00:00 2001 From: John Ky Date: Sat, 21 Jan 2023 15:13:36 +1100 Subject: [PATCH 5/8] Prefer forM over case match over Maybe --- .../Cardano/CLI/Shelley/Run/Transaction.hs | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs index bda4803da8c..3813ef236f3 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs @@ -18,7 +18,7 @@ module Cardano.CLI.Shelley.Run.Transaction , toTxOutInAnyEra ) where -import Control.Monad (forM_, void) +import Control.Monad (forM, forM_, void) import Control.Monad.IO.Class (MonadIO (..)) import Control.Monad.Trans (MonadTrans (..)) import Control.Monad.Trans.Except (ExceptT) @@ -376,19 +376,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 @@ -504,18 +498,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 From c0f593e16c5f522d806c0b095cf2900cf1f5e2d6 Mon Sep 17 00:00:00 2001 From: John Ky Date: Sat, 21 Jan 2023 17:51:28 +1100 Subject: [PATCH 6/8] Straight line style for runTxBuildCmd --- .../Cardano/CLI/Shelley/Run/Transaction.hs | 71 +++++++++---------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs index 3813ef236f3..e867005e8e5 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs @@ -412,42 +412,41 @@ runTxBuildCmd case outputOptions of OutputScriptCostOnly fp -> do let BuildTxWith mTxProtocolParams = txProtocolParams txBodycontent - case mTxProtocolParams of - Just pparams -> - case protocolParamPrices pparams of - Just executionUnitPrices -> do - let consensusMode = consensusModeOnly cModeParams - bpp = bundleProtocolParams cEra pparams - case consensusMode of - CardanoMode -> do - (nodeEraUTxO, _, eraHistory, systemStart, _) - <- firstExceptT ShelleyTxCmdQueryConvenienceError - . newExceptT $ queryStateForBalancedTx nodeEra nid allTxInputs - -- Why do we cast the era? 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. - txEraUtxo <- - case first ShelleyTxCmdTxEraCastErr (eraCast cEra nodeEraUTxO) of - Right txEraUtxo -> return txEraUtxo - Left e -> left e - - scriptExecUnitsMap <- - firstExceptT ShelleyTxCmdTxExecUnitsErr $ hoistEither - $ evaluateTransactionExecutionUnits - systemStart (toLedgerEpochInfo eraHistory) - bpp txEraUtxo balancedTxBody - - scriptCostOutput <- - firstExceptT ShelleyTxCmdPlutusScriptCostErr $ hoistEither - $ renderScriptCosts - txEraUtxo - executionUnitPrices - (collectTxBodyScriptWitnesses txBodycontent) - scriptExecUnitsMap - liftIO $ LBS.writeFile fp $ encodePretty scriptCostOutput - _ -> left ShelleyTxCmdPlutusScriptsRequireCardanoMode - Nothing -> left ShelleyTxCmdPParamExecutionUnitsNotAvailable - Nothing -> left ShelleyTxCmdProtocolParametersNotPresentInTxBody + + pparams <- pure mTxProtocolParams & onNothing (left ShelleyTxCmdProtocolParametersNotPresentInTxBody) + + + executionUnitPrices <- pure (protocolParamPrices pparams) & onNothing (left ShelleyTxCmdPParamExecutionUnitsNotAvailable) + + let consensusMode = consensusModeOnly cModeParams + bpp = bundleProtocolParams cEra pparams + + case consensusMode of + CardanoMode -> do + (nodeEraUTxO, _, eraHistory, systemStart, _) + <- firstExceptT ShelleyTxCmdQueryConvenienceError + . newExceptT $ queryStateForBalancedTx nodeEra nid allTxInputs + -- Why do we cast the era? 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. + txEraUtxo <- pure (eraCast cEra nodeEraUTxO) & onLeft (left . ShelleyTxCmdTxEraCastErr) + + scriptExecUnitsMap <- + firstExceptT ShelleyTxCmdTxExecUnitsErr $ hoistEither + $ evaluateTransactionExecutionUnits + systemStart (toLedgerEpochInfo eraHistory) + bpp txEraUtxo balancedTxBody + + scriptCostOutput <- + firstExceptT ShelleyTxCmdPlutusScriptCostErr $ hoistEither + $ renderScriptCosts + txEraUtxo + executionUnitPrices + (collectTxBodyScriptWitnesses txBodycontent) + scriptExecUnitsMap + liftIO $ LBS.writeFile fp $ encodePretty scriptCostOutput + _ -> left ShelleyTxCmdPlutusScriptsRequireCardanoMode + OutputTxBodyOnly (TxBodyFile fpath) -> let noWitTx = makeSignedTransaction [] balancedTxBody in lift (writeTxFileTextEnvelopeCddl fpath noWitTx) From e13bd9dc6ff9bf484f7620a43f9e3529b7a79106 Mon Sep 17 00:00:00 2001 From: John Ky Date: Sat, 21 Jan 2023 17:55:33 +1100 Subject: [PATCH 7/8] Handle eraCast errors with onLeft --- .../src/Cardano/CLI/Shelley/Run/Transaction.hs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs index e867005e8e5..8b2b4c5f86e 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs @@ -423,9 +423,10 @@ runTxBuildCmd case consensusMode of CardanoMode -> do - (nodeEraUTxO, _, eraHistory, systemStart, _) - <- firstExceptT ShelleyTxCmdQueryConvenienceError - . newExceptT $ queryStateForBalancedTx nodeEra nid allTxInputs + (nodeEraUTxO, _, eraHistory, systemStart, _) <- + lift (queryStateForBalancedTx nodeEra nid allTxInputs) + & onLeft (left . ShelleyTxCmdQueryConvenienceError) + -- Why do we cast the era? 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. @@ -746,10 +747,7 @@ runTxBuild era (AnyConsensusModeParams cModeParams) networkId mScriptValidity -- Why do we cast the era? 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. - txEraUtxo <- case first ShelleyTxCmdTxEraCastErr (eraCast era nodeEraUTxO) of - Right txEraUtxo -> return txEraUtxo - Left e -> left e - + txEraUtxo <- pure (eraCast era nodeEraUTxO) & onLeft (left . ShelleyTxCmdTxEraCastErr) balancedTxBody@(BalancedTxBody _ _ _ fee) <- firstExceptT ShelleyTxCmdBalanceTxBody From 8cf9027e5880917a511a210773bcd3a2205d321b Mon Sep 17 00:00:00 2001 From: John Ky Date: Sun, 19 Mar 2023 22:29:16 +1100 Subject: [PATCH 8/8] Handle anyAddressInEra with onLeft --- cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs index 8b2b4c5f86e..c621b059d16 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs @@ -740,9 +740,8 @@ runTxBuild era (AnyConsensusModeParams cModeParams) networkId mScriptValidity firstExceptT ShelleyTxCmdQueryNotScriptLocked . hoistEither $ notScriptLockedTxIns txinsc nodeEraUTxO - let cAddr = case anyAddressInEra era changeAddr of - Right addr -> addr - Left _ -> error $ "runTxBuild: Byron address used: " <> show changeAddr + cAddr <- pure (anyAddressInEra era changeAddr) + & onLeft (error $ "runTxBuild: Byron address used: " <> show changeAddr) -- should this throw instead? -- Why do we cast the era? 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