From d19f3257abdcee0350921bcbb6ba5664029cef4c Mon Sep 17 00:00:00 2001 From: Mateusz Galazyn Date: Thu, 16 May 2024 15:15:10 +0200 Subject: [PATCH] Make `--fee` mandatory in `transaction build-raw` --- .../CLI/EraBased/Commands/Transaction.hs | 2 +- .../CLI/EraBased/Options/Transaction.hs | 2 +- .../Cardano/CLI/EraBased/Run/Transaction.hs | 22 +++++++++--------- .../src/Cardano/CLI/Legacy/Run/Transaction.hs | 3 ++- .../Cardano/CLI/Types/Errors/TxCmdError.hs | 3 --- .../CLI/Types/Errors/TxValidationError.hs | 23 ------------------- .../cardano-cli-golden/files/golden/help.cli | 14 +++++------ .../help/allegra_transaction_build-raw.cli | 2 +- .../help/alonzo_transaction_build-raw.cli | 2 +- .../help/babbage_transaction_build-raw.cli | 2 +- .../help/conway_transaction_build-raw.cli | 2 +- .../help/latest_transaction_build-raw.cli | 2 +- .../help/mary_transaction_build-raw.cli | 2 +- .../help/shelley_transaction_build-raw.cli | 2 +- 14 files changed, 29 insertions(+), 54 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs index 6011ccc897..40a6420dad 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs @@ -67,7 +67,7 @@ data TransactionBuildRawCmdArgs era = TransactionBuildRawCmdArgs -- ^ Transaction validity lower bound , mValidityUpperBound :: !(TxValidityUpperBound era) -- ^ Transaction validity upper bound - , fee :: !(Maybe Coin) + , fee :: !Coin -- ^ Transaction fee , certificates :: ![(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))] -- ^ Certificates with potential script witness diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Transaction.hs index 125bcea88a..5d8df3f99b 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Transaction.hs @@ -262,7 +262,7 @@ pTransactionBuildRaw era = <*> optional (pMintMultiAsset ManualBalance) <*> optional pInvalidBefore <*> pInvalidHereafter era - <*> optional pTxFee + <*> pTxFee <*> many (pCertificateFile ManualBalance ) <*> many (pWithdrawal ManualBalance) <*> pTxMetadataJsonSchema diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs index cb43df39d6..75f054c670 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs @@ -349,7 +349,7 @@ runTransactionBuildEstimateCmd certsAndMaybeScriptWits withdrawalsAndMaybeScriptWits requiredSigners - Nothing + 0 txAuxScripts txMetadata txUpdateProposal @@ -360,7 +360,7 @@ runTransactionBuildEstimateCmd poolsToDeregister = Set.fromList $ catMaybes [getPoolDeregistrationInfo cert | (cert,_) <- certsAndMaybeScriptWits] totCol = fromMaybe 0 plutusCollateral pScriptExecUnits = Map.fromList [ (sWitIndex, execUnits) - | (sWitIndex, (AnyScriptWitness (PlutusScriptWitness _ _ _ _ _ execUnits))) <- collectTxBodyScriptWitnesses sbe txBodyContent + | (sWitIndex, AnyScriptWitness (PlutusScriptWitness _ _ _ _ _ execUnits)) <- collectTxBodyScriptWitnesses sbe txBodyContent ] BalancedTxBody _ balancedTxBody _ _ <- @@ -368,7 +368,7 @@ runTransactionBuildEstimateCmd estimateBalancedTxBody eon txBodyContent (unLedgerProtocolParameters ledgerPParams) poolsToDeregister stakeCredentialsToDeregisterMap drepsToDeregisterMap pScriptExecUnits totCol shelleyWitnesses (fromMaybe 0 mByronWitnesses) - (fromMaybe 0 (unReferenceScriptSize <$> totalReferenceScriptSize)) (anyAddressInShelleyBasedEra sbe changeAddr) + (maybe 0 unReferenceScriptSize totalReferenceScriptSize) (anyAddressInShelleyBasedEra sbe changeAddr) totalUTxOValue let noWitTx = makeSignedTransaction [] balancedTxBody @@ -576,7 +576,7 @@ runTxBuildRaw :: () -- ^ Tx lower bound -> TxValidityUpperBound era -- ^ Tx upper bound - -> Maybe L.Coin + -> L.Coin -- ^ Tx fee -> (Value, [ScriptWitness WitCtxMint era]) -- ^ Multi-Asset value(s) @@ -597,13 +597,13 @@ runTxBuildRaw sbe readOnlyRefIns txinsc mReturnCollateral mTotCollateral txouts mLowerBound mUpperBound - mFee valuesWithScriptWits + fee valuesWithScriptWits certsAndMaybeSriptWits withdrawals reqSigners txAuxScripts txMetadata mpparams txUpdateProposal votingProcedures proposals = do txBodyContent <- constructTxBodyContent sbe mScriptValidity (unLedgerProtocolParameters <$> mpparams) inputsAndMaybeScriptWits readOnlyRefIns txinsc mReturnCollateral mTotCollateral txouts mLowerBound mUpperBound valuesWithScriptWits - certsAndMaybeSriptWits withdrawals reqSigners mFee txAuxScripts txMetadata txUpdateProposal + certsAndMaybeSriptWits withdrawals reqSigners fee txAuxScripts txMetadata txUpdateProposal votingProcedures proposals first TxCmdTxBodyError $ createAndValidateTransactionBody sbe txBodyContent @@ -636,7 +636,7 @@ constructTxBodyContent -- ^ Withdrawals -> [Hash PaymentKey] -- ^ Required signers - -> Maybe L.Coin + -> L.Coin -- ^ Tx fee -> TxAuxScripts era -> TxMetadataInEra era @@ -647,7 +647,7 @@ constructTxBodyContent constructTxBodyContent sbe mScriptValidity mPparams inputsAndMaybeScriptWits readOnlyRefIns txinsc mReturnCollateral mTotCollateral txouts mLowerBound mUpperBound valuesWithScriptWits certsAndMaybeScriptWits withdrawals - reqSigners mFee txAuxScripts txMetadata txUpdateProposal + reqSigners fee txAuxScripts txMetadata txUpdateProposal votingProcedures proposals = do let era = toCardanoEra sbe -- TODO: Propagate SBE @@ -666,7 +666,7 @@ constructTxBodyContent sbe mScriptValidity mPparams inputsAndMaybeScriptWits rea <- first TxCmdTotalCollateralValidationError $ validateTxTotalCollateral era mTotCollateral validatedRetCol <- first TxCmdReturnCollateralValidationError $ validateTxReturnCollateral era mReturnCollateral - dFee <- first TxCmdTxFeeValidationError . validateTxFee sbe . Just $ fromMaybe (L.Coin 0) mFee + let txFee = TxFeeExplicit sbe fee validatedLowerBound <- first TxCmdTxValidityLowerBoundValidationError (validateTxValidityLowerBound era mLowerBound) validatedReqSigners <- first TxCmdRequiredSignersValidationError $ validateRequiredSigners era reqSigners validatedTxWtdrwls <- first TxCmdTxWithdrawalsValidationError $ validateTxWithdrawals era withdrawals @@ -683,7 +683,7 @@ constructTxBodyContent sbe mScriptValidity mPparams inputsAndMaybeScriptWits rea & setTxOuts txouts & setTxTotalCollateral validatedTotCollateral & setTxReturnCollateral validatedRetCol - & setTxFee dFee + & setTxFee txFee & setTxValidityLowerBound validatedLowerBound & setTxValidityUpperBound mUpperBound & setTxMetadata txMetadata @@ -809,7 +809,7 @@ runTxBuild certsAndMaybeScriptWits withdrawals reqSigners - Nothing + 0 txAuxScripts txMetadata txUpdateProposal diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/Legacy/Run/Transaction.hs index 39741be1a1..c25d48fe8a 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Run/Transaction.hs @@ -22,6 +22,7 @@ import Cardano.CLI.Types.Errors.TxValidationError import Cardano.CLI.Types.Governance import Data.Function +import Data.Maybe runLegacyTransactionCmds :: LegacyTransactionCmds -> ExceptT TxCmdError IO () runLegacyTransactionCmds = \case @@ -175,7 +176,7 @@ runLegacyTransactionBuildRawCmd runTransactionBuildRawCmd ( Cmd.TransactionBuildRawCmdArgs sbe mScriptValidity txins readOnlyRefIns txinsc mReturnColl - mTotColl reqSigners txouts mValue mLowBound upperBound fee certs wdrls + mTotColl reqSigners txouts mValue mLowBound upperBound (fromMaybe 0 fee) certs wdrls metadataSchema scriptFiles metadataFiles mProtocolParamsFile mUpdateProposalFile [] [] outFile ) diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs index fdbfbdcdd9..dde1e66f80 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs @@ -84,7 +84,6 @@ data TxCmdError | TxCmdAuxScriptsValidationError TxAuxScriptsValidationError | TxCmdTotalCollateralValidationError TxTotalCollateralValidationError | TxCmdReturnCollateralValidationError TxReturnCollateralValidationError - | TxCmdTxFeeValidationError TxFeeValidationError | TxCmdTxValidityLowerBoundValidationError TxValidityLowerBoundValidationError | TxCmdTxValidityUpperBoundValidationError TxValidityUpperBoundValidationError | TxCmdRequiredSignersValidationError TxRequiredSignersValidationError @@ -220,8 +219,6 @@ renderTxCmdError = \case prettyError e TxCmdReturnCollateralValidationError e -> prettyError e - TxCmdTxFeeValidationError e -> - prettyError e TxCmdTxValidityLowerBoundValidationError e -> prettyError e TxCmdTxValidityUpperBoundValidationError e -> diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs index 3e789a9318..bd9d1a9447 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs @@ -9,7 +9,6 @@ module Cardano.CLI.Types.Errors.TxValidationError ( TxAuxScriptsValidationError(..) , TxCertificatesValidationError(..) - , TxFeeValidationError(..) , TxGovDuplicateVotes(..) , TxProtocolParametersValidationError , TxScriptValidityValidationError(..) @@ -26,7 +25,6 @@ module Cardano.CLI.Types.Errors.TxValidationError , validateScriptSupportedInEra , validateTxAuxScripts , validateTxCertificates - , validateTxFee , validateRequiredSigners , validateTxReturnCollateral , validateTxScriptValidity @@ -72,27 +70,6 @@ validateScriptSupportedInEra era script@(ScriptInAnyLang lang _) = (AnyScriptLanguage lang) (anyCardanoEra $ toCardanoEra era) Just script' -> pure script' - -data TxFeeValidationError - = TxFeatureImplicitFeesE AnyCardanoEra -- ^ Expected an explicit fee - | TxFeatureExplicitFeesE AnyCardanoEra -- ^ Expected an implicit fee - deriving Show - -instance Error TxFeeValidationError where - prettyError (TxFeatureImplicitFeesE era) = - "Implicit transaction fee not supported in " <> pretty era - prettyError (TxFeatureExplicitFeesE era) = - "Explicit transaction fee not supported in " <> pretty era - -validateTxFee :: ShelleyBasedEra era - -> Maybe L.Coin -- TODO: Make this mandatory in the cli (Remove Maybe) - -> Either TxFeeValidationError (TxFee era) -validateTxFee era = \case - Nothing -> - let cEra = toCardanoEra era - in Left . TxFeatureImplicitFeesE $ cardanoEraConstraints cEra $ AnyCardanoEra cEra - Just fee -> pure (TxFeeExplicit era fee) - newtype TxTotalCollateralValidationError = TxTotalCollateralNotSupported AnyCardanoEra deriving Show diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli index a89fcd02b1..7b90873625 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -912,7 +912,7 @@ Usage: cardano-cli shelley transaction build-raw )] [--invalid-before SLOT] [--invalid-hereafter SLOT] - [--fee LOVELACE] + --fee LOVELACE [--certificate-file FILE [ --certificate-script-file FILE [ @@ -2107,7 +2107,7 @@ Usage: cardano-cli allegra transaction build-raw )] [--invalid-before SLOT] [--invalid-hereafter SLOT] - [--fee LOVELACE] + --fee LOVELACE [--certificate-file FILE [ --certificate-script-file FILE [ @@ -3294,7 +3294,7 @@ Usage: cardano-cli mary transaction build-raw )] [--invalid-before SLOT] [--invalid-hereafter SLOT] - [--fee LOVELACE] + --fee LOVELACE [--certificate-file FILE [ --certificate-script-file FILE [ @@ -4616,7 +4616,7 @@ Usage: cardano-cli alonzo transaction build-raw )] [--invalid-before SLOT] [--invalid-hereafter SLOT] - [--fee LOVELACE] + --fee LOVELACE [--certificate-file FILE [ --certificate-script-file FILE [ @@ -5970,7 +5970,7 @@ Usage: cardano-cli babbage transaction build-raw )] [--invalid-before SLOT] [--invalid-hereafter SLOT] - [--fee LOVELACE] + --fee LOVELACE [--certificate-file FILE [ --certificate-script-file FILE [ @@ -7772,7 +7772,7 @@ Usage: cardano-cli conway transaction build-raw )] [--invalid-before SLOT] [--invalid-hereafter SLOT] - [--fee LOVELACE] + --fee LOVELACE [--certificate-file FILE [ --certificate-script-file FILE [ @@ -9164,7 +9164,7 @@ Usage: cardano-cli latest transaction build-raw )] [--invalid-before SLOT] [--invalid-hereafter SLOT] - [--fee LOVELACE] + --fee LOVELACE [--certificate-file FILE [ --certificate-script-file FILE [ diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_transaction_build-raw.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_transaction_build-raw.cli index 4fb229df3f..d926f2e361 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_transaction_build-raw.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_transaction_build-raw.cli @@ -74,7 +74,7 @@ Usage: cardano-cli allegra transaction build-raw )] [--invalid-before SLOT] [--invalid-hereafter SLOT] - [--fee LOVELACE] + --fee LOVELACE [--certificate-file FILE [ --certificate-script-file FILE [ diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_transaction_build-raw.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_transaction_build-raw.cli index c72973c94f..bb9ec44825 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_transaction_build-raw.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_transaction_build-raw.cli @@ -74,7 +74,7 @@ Usage: cardano-cli alonzo transaction build-raw )] [--invalid-before SLOT] [--invalid-hereafter SLOT] - [--fee LOVELACE] + --fee LOVELACE [--certificate-file FILE [ --certificate-script-file FILE [ diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_transaction_build-raw.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_transaction_build-raw.cli index 5b9f747548..a57524b5ab 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_transaction_build-raw.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_transaction_build-raw.cli @@ -74,7 +74,7 @@ Usage: cardano-cli babbage transaction build-raw )] [--invalid-before SLOT] [--invalid-hereafter SLOT] - [--fee LOVELACE] + --fee LOVELACE [--certificate-file FILE [ --certificate-script-file FILE [ diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_transaction_build-raw.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_transaction_build-raw.cli index 451298fda0..5eb678a0b8 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_transaction_build-raw.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_transaction_build-raw.cli @@ -74,7 +74,7 @@ Usage: cardano-cli conway transaction build-raw )] [--invalid-before SLOT] [--invalid-hereafter SLOT] - [--fee LOVELACE] + --fee LOVELACE [--certificate-file FILE [ --certificate-script-file FILE [ diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_transaction_build-raw.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_transaction_build-raw.cli index da2e6fdf67..fe457219d3 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_transaction_build-raw.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_transaction_build-raw.cli @@ -74,7 +74,7 @@ Usage: cardano-cli latest transaction build-raw )] [--invalid-before SLOT] [--invalid-hereafter SLOT] - [--fee LOVELACE] + --fee LOVELACE [--certificate-file FILE [ --certificate-script-file FILE [ diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_transaction_build-raw.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_transaction_build-raw.cli index 26bb3285ca..35cb34e552 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_transaction_build-raw.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_transaction_build-raw.cli @@ -74,7 +74,7 @@ Usage: cardano-cli mary transaction build-raw )] [--invalid-before SLOT] [--invalid-hereafter SLOT] - [--fee LOVELACE] + --fee LOVELACE [--certificate-file FILE [ --certificate-script-file FILE [ diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_transaction_build-raw.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_transaction_build-raw.cli index f53b3d77d6..c8fa466a11 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_transaction_build-raw.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_transaction_build-raw.cli @@ -74,7 +74,7 @@ Usage: cardano-cli shelley transaction build-raw )] [--invalid-before SLOT] [--invalid-hereafter SLOT] - [--fee LOVELACE] + --fee LOVELACE [--certificate-file FILE [ --certificate-script-file FILE [