Skip to content

Commit

Permalink
Infer protocol params in transaction build
Browse files Browse the repository at this point in the history
Fixes #4058
  • Loading branch information
Robert 'Probie' Offner authored and Jimbo4350 committed Jan 5, 2023
1 parent 4e083a5 commit 133ac29
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
3 changes: 3 additions & 0 deletions cardano-cli/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@

- Add `query tx-mempool` ([PR 4276](https://github.com/input-output-hk/cardano-node/pull/4276))


### Bugs

- Allow reading signing keys from a pipe ([PR 4342](https://github.com/input-output-hk/cardano-node/pull/4342))

- Query protocol parameters from the node in the `transaction build` command ([PR 4431](https://github.com/input-output-hk/cardano-node/pull/4431))

## 1.35.3 -- August 2022

- Update build and build-raw commands to accept simple reference minting scripts (#4087)
Expand Down
15 changes: 11 additions & 4 deletions cardano-cli/src/Cardano/CLI/Helpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

module Cardano.CLI.Helpers
( HelpersError(..)
, printWarning
, deprecationWarning
, ensureNewFile
, ensureNewFileLBS
Expand Down Expand Up @@ -60,12 +61,18 @@ decodeCBOR
decodeCBOR bs decoder =
first CBORDecodingError $ deserialiseFromBytes decoder bs

deprecationWarning :: String -> IO ()
deprecationWarning cmd = do
printWarning :: String -> IO ()
printWarning warning = do
ANSI.hSetSGR IO.stderr [SetColor Foreground Vivid Yellow]
IO.hPutStrLn IO.stderr $ "WARNING: This CLI command is deprecated. Please use "
<> cmd <> " command instead."
IO.hPutStrLn IO.stderr $ "WARNING: " <> warning
ANSI.hSetSGR IO.stderr [Reset]
-- We need to flush, or otherwise what's on stdout may have the wrong colour
-- since it's likely sharing a console with stderr
IO.hFlush IO.stderr

deprecationWarning :: String -> IO ()
deprecationWarning cmd = printWarning $
"This CLI command is deprecated. Please use " <> cmd <> " command instead."

-- | Checks if a path exists and throws and error if it does.
ensureNewFile :: (FilePath -> a -> IO ()) -> FilePath -> a -> ExceptT HelpersError IO ()
Expand Down
47 changes: 27 additions & 20 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Cardano.Api
import Cardano.Api.Byron hiding (SomeByronSigningKey (..))
import Cardano.Api.Shelley

import Cardano.CLI.Helpers (printWarning)
import Cardano.CLI.Run.Friendly (friendlyTxBS, friendlyTxBodyBS)
import Cardano.CLI.Shelley.Output
import Cardano.CLI.Shelley.Parsers
Expand Down Expand Up @@ -648,6 +649,10 @@ runTxBuild era (AnyConsensusModeParams cModeParams) networkId mScriptValidity
(TxOutChangeAddress changeAddr) valuesWithScriptWits mLowerBound mUpperBound
certsAndMaybeScriptWits withdrawals reqSigners txAuxScripts txMetadata mpparams
mUpdatePropF mOverrideWits outputOptions = do

liftIO $ forM_ mpparams $ \_ ->
printWarning "'--protocol-params-file' for 'transaction build' is deprecated"

let consensusMode = consensusModeOnly cModeParams
dummyFee = Just $ Lovelace 0
inputsThatRequireWitnessing = [input | (input,_) <- inputsAndMaybeScriptWits]
Expand All @@ -669,7 +674,6 @@ runTxBuild era (AnyConsensusModeParams cModeParams) networkId mScriptValidity
validatedBounds <- (,) <$> hoistEither (first ShelleyTxCmdTxValidityLowerBoundValidationError $ validateTxValidityLowerBound era mLowerBound)
<*> hoistEither (first ShelleyTxCmdTxValidityUpperBoundValidationError $ validateTxValidityUpperBound era mUpperBound)
validatedReqSigners <- hoistEither (first ShelleyTxCmdRequiredSignersValidationError $ validateRequiredSigners era reqSigners)
validatedPParams <- hoistEither (first ShelleyTxCmdProtocolParametersValidationError $ validateProtocolParameters era mpparams)
validatedTxWtdrwls <- hoistEither (first ShelleyTxCmdTxWithdrawalsValidationError $ validateTxWithdrawals era withdrawals)
validatedTxCerts <- hoistEither (first ShelleyTxCmdTxCertificatesValidationError $ validateTxCertificates era certsAndMaybeScriptWits)
validatedTxUpProp <- hoistEither (first ShelleyTxCmdTxUpdateProposalValidationError $ validateTxUpdateProposal era mUpdatePropF)
Expand All @@ -678,25 +682,6 @@ runTxBuild era (AnyConsensusModeParams cModeParams) networkId mScriptValidity

case (consensusMode, cardanoEraStyle era) of
(CardanoMode, ShelleyBasedEra _sbe) -> do
let txBodyContent = TxBodyContent
(validateTxIns inputsAndMaybeScriptWits)
validatedCollateralTxIns
validatedRefInputs
txouts
validatedTotCollateral
validatedRetCol
dFee
validatedBounds
txMetadata
txAuxScripts
validatedReqSigners
validatedPParams
validatedTxWtdrwls
validatedTxCerts
validatedTxUpProp
validatedMintValue
validatedTxScriptValidity

eInMode <- case toEraInMode era CardanoMode of
Just result -> return result
Nothing ->
Expand All @@ -720,6 +705,27 @@ runTxBuild era (AnyConsensusModeParams cModeParams) networkId mScriptValidity
firstExceptT ShelleyTxCmdQueryConvenienceError . newExceptT
$ queryStateForBalancedTx nodeEra networkId allTxInputs

validatedPParams <- hoistEither $ first ShelleyTxCmdProtocolParametersValidationError $ validateProtocolParameters era (Just pparams)

let txBodyContent = TxBodyContent
(validateTxIns inputsAndMaybeScriptWits)
validatedCollateralTxIns
validatedRefInputs
txouts
validatedTotCollateral
validatedRetCol
dFee
validatedBounds
txMetadata
txAuxScripts
validatedReqSigners
validatedPParams
validatedTxWtdrwls
validatedTxCerts
validatedTxUpProp
validatedMintValue
validatedTxScriptValidity

firstExceptT ShelleyTxCmdTxInsDoNotExist
. hoistEither $ txInsExistInUTxO allTxInputs nodeEraUTxO
firstExceptT ShelleyTxCmdQueryNotScriptLocked
Expand All @@ -736,6 +742,7 @@ runTxBuild era (AnyConsensusModeParams cModeParams) networkId mScriptValidity
Right txEraUtxo -> return txEraUtxo
Left e -> left e


balancedTxBody@(BalancedTxBody _ _ _ fee) <-
firstExceptT ShelleyTxCmdBalanceTxBody
. hoistEither
Expand Down

0 comments on commit 133ac29

Please sign in to comment.