Skip to content

Commit bc88bb5

Browse files
authored
Merge pull request #4431 from input-output-hk/ludvikgalois/infer-pparams-in-build
Infer protocol params in transaction build
2 parents a8e51de + a18b1b4 commit bc88bb5

File tree

3 files changed

+42
-24
lines changed

3 files changed

+42
-24
lines changed

cardano-cli/ChangeLog.md

+3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010

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

13+
1314
### Bugs
1415

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

18+
- Query protocol parameters from the node in the `transaction build` command ([PR 4431](https://github.com/input-output-hk/cardano-node/pull/4431))
19+
1720
## 1.35.3 -- August 2022
1821

1922
- Update build and build-raw commands to accept simple reference minting scripts (#4087)

cardano-cli/src/Cardano/CLI/Helpers.hs

+11-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
module Cardano.CLI.Helpers
55
( HelpersError(..)
6+
, printWarning
67
, deprecationWarning
78
, ensureNewFile
89
, ensureNewFileLBS
@@ -60,12 +61,18 @@ decodeCBOR
6061
decodeCBOR bs decoder =
6162
first CBORDecodingError $ deserialiseFromBytes decoder bs
6263

63-
deprecationWarning :: String -> IO ()
64-
deprecationWarning cmd = do
64+
printWarning :: String -> IO ()
65+
printWarning warning = do
6566
ANSI.hSetSGR IO.stderr [SetColor Foreground Vivid Yellow]
66-
IO.hPutStrLn IO.stderr $ "WARNING: This CLI command is deprecated. Please use "
67-
<> cmd <> " command instead."
67+
IO.hPutStrLn IO.stderr $ "WARNING: " <> warning
6868
ANSI.hSetSGR IO.stderr [Reset]
69+
-- We need to flush, or otherwise what's on stdout may have the wrong colour
70+
-- since it's likely sharing a console with stderr
71+
IO.hFlush IO.stderr
72+
73+
deprecationWarning :: String -> IO ()
74+
deprecationWarning cmd = printWarning $
75+
"This CLI command is deprecated. Please use " <> cmd <> " command instead."
6976

7077
-- | Checks if a path exists and throws and error if it does.
7178
ensureNewFile :: (FilePath -> a -> IO ()) -> FilePath -> a -> ExceptT HelpersError IO ()

cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs

+28-20
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import Cardano.Api
3838
import Cardano.Api.Byron hiding (SomeByronSigningKey (..))
3939
import Cardano.Api.Shelley
4040

41+
import Cardano.CLI.Helpers (printWarning)
4142
import Cardano.CLI.Run.Friendly (friendlyTxBS, friendlyTxBodyBS)
4243
import Cardano.CLI.Shelley.Output
4344
import Cardano.CLI.Shelley.Parsers
@@ -648,6 +649,10 @@ runTxBuild era (AnyConsensusModeParams cModeParams) networkId mScriptValidity
648649
(TxOutChangeAddress changeAddr) valuesWithScriptWits mLowerBound mUpperBound
649650
certsAndMaybeScriptWits withdrawals reqSigners txAuxScripts txMetadata mpparams
650651
mUpdatePropF mOverrideWits outputOptions = do
652+
653+
liftIO $ forM_ mpparams $ \_ ->
654+
printWarning "'--protocol-params-file' for 'transaction build' is deprecated"
655+
651656
let consensusMode = consensusModeOnly cModeParams
652657
dummyFee = Just $ Lovelace 0
653658
inputsThatRequireWitnessing = [input | (input,_) <- inputsAndMaybeScriptWits]
@@ -669,7 +674,6 @@ runTxBuild era (AnyConsensusModeParams cModeParams) networkId mScriptValidity
669674
validatedBounds <- (,) <$> hoistEither (first ShelleyTxCmdTxValidityLowerBoundValidationError $ validateTxValidityLowerBound era mLowerBound)
670675
<*> hoistEither (first ShelleyTxCmdTxValidityUpperBoundValidationError $ validateTxValidityUpperBound era mUpperBound)
671676
validatedReqSigners <- hoistEither (first ShelleyTxCmdRequiredSignersValidationError $ validateRequiredSigners era reqSigners)
672-
validatedPParams <- hoistEither (first ShelleyTxCmdProtocolParametersValidationError $ validateProtocolParameters era mpparams)
673677
validatedTxWtdrwls <- hoistEither (first ShelleyTxCmdTxWithdrawalsValidationError $ validateTxWithdrawals era withdrawals)
674678
validatedTxCerts <- hoistEither (first ShelleyTxCmdTxCertificatesValidationError $ validateTxCertificates era certsAndMaybeScriptWits)
675679
validatedTxUpProp <- hoistEither (first ShelleyTxCmdTxUpdateProposalValidationError $ validateTxUpdateProposal era mUpdatePropF)
@@ -678,25 +682,6 @@ runTxBuild era (AnyConsensusModeParams cModeParams) networkId mScriptValidity
678682

679683
case (consensusMode, cardanoEraStyle era) of
680684
(CardanoMode, ShelleyBasedEra _sbe) -> do
681-
let txBodyContent = TxBodyContent
682-
(validateTxIns inputsAndMaybeScriptWits)
683-
validatedCollateralTxIns
684-
validatedRefInputs
685-
txouts
686-
validatedTotCollateral
687-
validatedRetCol
688-
dFee
689-
validatedBounds
690-
txMetadata
691-
txAuxScripts
692-
validatedReqSigners
693-
validatedPParams
694-
validatedTxWtdrwls
695-
validatedTxCerts
696-
validatedTxUpProp
697-
validatedMintValue
698-
validatedTxScriptValidity
699-
700685
eInMode <- case toEraInMode era CardanoMode of
701686
Just result -> return result
702687
Nothing ->
@@ -720,6 +705,28 @@ runTxBuild era (AnyConsensusModeParams cModeParams) networkId mScriptValidity
720705
firstExceptT ShelleyTxCmdQueryConvenienceError . newExceptT
721706
$ queryStateForBalancedTx nodeEra networkId allTxInputs
722707

708+
validatedPParams <- hoistEither $ first ShelleyTxCmdProtocolParametersValidationError
709+
$ validateProtocolParameters era (Just pparams)
710+
711+
let txBodyContent = TxBodyContent
712+
(validateTxIns inputsAndMaybeScriptWits)
713+
validatedCollateralTxIns
714+
validatedRefInputs
715+
txouts
716+
validatedTotCollateral
717+
validatedRetCol
718+
dFee
719+
validatedBounds
720+
txMetadata
721+
txAuxScripts
722+
validatedReqSigners
723+
validatedPParams
724+
validatedTxWtdrwls
725+
validatedTxCerts
726+
validatedTxUpProp
727+
validatedMintValue
728+
validatedTxScriptValidity
729+
723730
firstExceptT ShelleyTxCmdTxInsDoNotExist
724731
. hoistEither $ txInsExistInUTxO allTxInputs nodeEraUTxO
725732
firstExceptT ShelleyTxCmdQueryNotScriptLocked
@@ -736,6 +743,7 @@ runTxBuild era (AnyConsensusModeParams cModeParams) networkId mScriptValidity
736743
Right txEraUtxo -> return txEraUtxo
737744
Left e -> left e
738745

746+
739747
balancedTxBody@(BalancedTxBody _ _ _ fee) <-
740748
firstExceptT ShelleyTxCmdBalanceTxBody
741749
. hoistEither

0 commit comments

Comments
 (0)