Skip to content

Commit

Permalink
Support --proposal-file in transaction build-raw
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Oct 11, 2023
1 parent 4487ca9 commit c444f26
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ data TransactionCmds era
[MetadataFile]
(Maybe ProtocolParamsFile)
(Maybe UpdateProposalFile)
[ProposalFile 'In]
(TxBodyFile Out)

-- | Like 'TxBuildRaw' but without the fee, and with a change output.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ pTransactionBuildRaw era =
<*> many pMetadataFile
<*> optional pProtocolParamsFile
<*> optional pUpdateProposalFile
<*> many (pFileInDirection "proposal-file" "Filepath of the proposal.")
<*> pTxBodyFileOut

pTransactionSign :: EnvCli -> Parser (TransactionCmds era)
Expand Down
45 changes: 27 additions & 18 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,22 @@ runTransactionCmds cmd =
TxBuild
era mNodeSocketPath consensusModeParams nid mScriptValidity mOverrideWits txins readOnlyRefIns
reqSigners txinsc mReturnColl mTotCollateral txouts changeAddr mValue mLowBound
mUpperBound certs wdrls metadataSchema scriptFiles metadataFiles mUpProp mconwayVote
mNewConstitution outputOptions ->
mUpperBound certs wdrls metadataSchema scriptFiles metadataFiles mUpProp votingProcedureFiles
proposalFiles outputOptions ->
runTxBuildCmd
era mNodeSocketPath consensusModeParams nid mScriptValidity mOverrideWits txins readOnlyRefIns
reqSigners txinsc mReturnColl mTotCollateral txouts changeAddr mValue mLowBound
mUpperBound certs wdrls metadataSchema scriptFiles metadataFiles mUpProp mconwayVote
mNewConstitution outputOptions
mUpperBound certs wdrls metadataSchema scriptFiles metadataFiles mUpProp votingProcedureFiles
proposalFiles outputOptions
TxBuildRaw
era mScriptValidity txins readOnlyRefIns txinsc mReturnColl
mTotColl reqSigners txouts mValue mLowBound mUpperBound fee certs wdrls
metadataSchema scriptFiles metadataFiles mProtocolParamsFile mUpProp out ->
metadataSchema scriptFiles metadataFiles mProtocolParamsFile mUpProp proposalFiles
out ->
runTxBuildRawCmd era mScriptValidity txins readOnlyRefIns txinsc mReturnColl
mTotColl reqSigners txouts mValue mLowBound mUpperBound fee certs wdrls
metadataSchema scriptFiles metadataFiles mProtocolParamsFile mUpProp out
metadataSchema scriptFiles metadataFiles mProtocolParamsFile mUpProp proposalFiles
out
TxSign txinfile skfiles network txoutfile ->
runTxSignCmd txinfile skfiles network txoutfile
TxSubmit mNodeSocketPath anyConsensusModeParams network txFp ->
Expand Down Expand Up @@ -150,7 +152,7 @@ runTxBuildCmd
era socketPath consensusModeParams@(AnyConsensusModeParams cModeParams) nid
mScriptValidity mOverrideWits txins readOnlyRefIns reqSigners txinsc mReturnColl mTotCollateral txouts
changeAddr mValue mLowBound mUpperBound certs wdrls metadataSchema scriptFiles metadataFiles mUpProp
conwayVotes newProposals outputOptions = do
votingProcedureFiles proposalFiles outputOptions = do

-- 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
Expand Down Expand Up @@ -192,14 +194,14 @@ runTxBuildCmd
txOuts <- mapM (toTxOutInAnyEra era) txouts

-- Conway related
votes <-
votingProcedures <-
inEonForEra
(pure emptyVotingProcedures)
(\w -> firstExceptT TxCmdVoteError $ ExceptT (readVotingProceduresFiles w conwayVotes))
(\w -> firstExceptT TxCmdVoteError $ ExceptT (readVotingProceduresFiles w votingProcedureFiles))
era

proposals <- newExceptT $ first TxCmdConstitutionError
<$> readTxGovernanceActions era newProposals
<$> readTxGovernanceActions era proposalFiles

-- the same collateral input can be used for several plutus scripts
let filteredTxinsc = Set.toList $ Set.fromList txinsc
Expand All @@ -210,7 +212,7 @@ runTxBuildCmd
era socketPath consensusModeParams nid mScriptValidity inputsAndMaybeScriptWits readOnlyRefIns filteredTxinsc
mReturnCollateral mTotCollateral txOuts changeAddr valuesWithScriptWits mLowBound
mUpperBound certsAndMaybeScriptWits withdrawalsAndMaybeScriptWits
requiredSigners txAuxScripts txMetadata mProp mOverrideWits votes proposals outputOptions
requiredSigners txAuxScripts txMetadata mProp mOverrideWits votingProcedures proposals outputOptions

let mScriptWits =
forEraInEon era [] $ \sbe -> collectTxBodyScriptWitnesses sbe txBodyContent
Expand Down Expand Up @@ -305,12 +307,14 @@ runTxBuildRawCmd
-> [MetadataFile]
-> Maybe ProtocolParamsFile
-> Maybe UpdateProposalFile
-> [ProposalFile In]
-> TxBodyFile Out
-> ExceptT TxCmdError IO ()
runTxBuildRawCmd
era mScriptValidity txins readOnlyRefIns txinsc mReturnColl
mTotColl reqSigners txouts mValue mLowBound mUpperBound fee certs wdrls
metadataSchema scriptFiles metadataFiles mpParamsFile mUpProp out = do
metadataSchema scriptFiles metadataFiles mpParamsFile mUpProp
proposalFiles out = do
inputsAndMaybeScriptWits <- firstExceptT TxCmdScriptWitnessError
$ readScriptWitnessFiles era txins
certFilesAndMaybeScriptWits <- firstExceptT TxCmdScriptWitnessError
Expand Down Expand Up @@ -357,10 +361,14 @@ runTxBuildRawCmd
-- the same collateral input can be used for several plutus scripts
let filteredTxinsc = Set.toList $ Set.fromList txinsc

proposals <-
lift (readTxGovernanceActions era proposalFiles)
& onLeft (left . TxCmdConstitutionError)

txBody <- hoistEither $ runTxBuildRaw era mScriptValidity inputsAndMaybeScriptWits readOnlyRefIns filteredTxinsc
mReturnCollateral mTotColl txOuts mLowBound mUpperBound fee valuesWithScriptWits
certsAndMaybeScriptWits withdrawalsAndMaybeScriptWits requiredSigners txAuxScripts
txMetadata mLedgerPParams mProp
txMetadata mLedgerPParams mProp proposals

let noWitTx = makeSignedTransaction [] txBody
lift (cardanoEraConstraints era $ writeTxFileTextEnvelopeCddl out noWitTx)
Expand Down Expand Up @@ -399,6 +407,7 @@ runTxBuildRaw :: ()
-> TxMetadataInEra era
-> Maybe (LedgerProtocolParameters era)
-> Maybe UpdateProposal
-> [Proposal era]
-> Either TxCmdError (TxBody era)
runTxBuildRaw era
mScriptValidity inputsAndMaybeScriptWits
Expand All @@ -407,7 +416,7 @@ runTxBuildRaw era
mLowerBound mUpperBound
mFee valuesWithScriptWits
certsAndMaybeSriptWits withdrawals reqSigners
txAuxScripts txMetadata mpparams mUpdateProp = do
txAuxScripts txMetadata mpparams mUpdateProp proposals = do

let allReferenceInputs = getAllReferenceInputs
inputsAndMaybeScriptWits
Expand Down Expand Up @@ -440,7 +449,7 @@ runTxBuildRaw era
<- createTxMintValue era valuesWithScriptWits
validatedTxScriptValidity
<- first TxCmdScriptValidityValidationError $ validateTxScriptValidity era mScriptValidity
let validatedTxProposalProcedures = Nothing -- TODO: Conwary era
let validatedTxProposal = proposals
validatedTxVotes = Nothing -- TODO: Conwary era
let txBodyContent =
TxBodyContent
Expand All @@ -461,7 +470,7 @@ runTxBuildRaw era
, txUpdateProposal = validatedTxUpProp
, txMintValue = validatedMintValue
, txScriptValidity = validatedTxScriptValidity
, txProposalProcedures = validatedTxProposalProcedures
, txProposalProcedures = forEraInEonMaybe era (`Featured` validatedTxProposal)
, txVotingProcedures = validatedTxVotes
}

Expand Down Expand Up @@ -513,7 +522,7 @@ runTxBuild
inputsAndMaybeScriptWits readOnlyRefIns txinsc mReturnCollateral mTotCollateral txouts
(TxOutChangeAddress changeAddr) valuesWithScriptWits mLowerBound mUpperBound
certsAndMaybeScriptWits withdrawals reqSigners txAuxScripts txMetadata
mUpdatePropF mOverrideWits votes proposals outputOptions = do
mUpdatePropF mOverrideWits votingProcedures proposals outputOptions = do

let consensusMode = consensusModeOnly cModeParams
dummyFee = Just $ Lovelace 0
Expand Down Expand Up @@ -575,7 +584,7 @@ runTxBuild
$ validateProtocolParameters era (Just pparams)

let validatedTxProposalProcedures = proposals
validatedTxVotes = votes
validatedTxVotes = votingProcedures
txBodyContent =
TxBodyContent
{ txIns = validateTxIns inputsAndMaybeScriptWits
Expand Down
8 changes: 7 additions & 1 deletion cardano-cli/src/Cardano/CLI/Legacy/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ runLegacyTxBuildRawCmd :: ()
-> Maybe UpdateProposalFile
-> TxBodyFile Out
-> ExceptT TxCmdError IO ()
runLegacyTxBuildRawCmd (AnyCardanoEra era) = runTxBuildRawCmd era
runLegacyTxBuildRawCmd
(AnyCardanoEra era) mScriptValidity txins readOnlyRefIns txinsc mReturnColl
mTotColl reqSigners txouts mValue mLowBound mUpperBound fee certs wdrls
metadataSchema scriptFiles metadataFiles mProtocolParamsFile mUpProp =
runTxBuildRawCmd era mScriptValidity txins readOnlyRefIns txinsc mReturnColl
mTotColl reqSigners txouts mValue mLowBound mUpperBound fee certs wdrls
metadataSchema scriptFiles metadataFiles mProtocolParamsFile mUpProp []

runLegacyTxSignCmd :: InputTxBodyOrTxFile
-> [WitnessSigningData]
Expand Down
7 changes: 7 additions & 0 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ Usage: cardano-cli shelley transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--proposal-file FILE]
--out-file FILE

Build a transaction (low-level, inconvenient)
Expand Down Expand Up @@ -2129,6 +2130,7 @@ Usage: cardano-cli allegra transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--proposal-file FILE]
--out-file FILE

Build a transaction (low-level, inconvenient)
Expand Down Expand Up @@ -3300,6 +3302,7 @@ Usage: cardano-cli mary transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--proposal-file FILE]
--out-file FILE

Build a transaction (low-level, inconvenient)
Expand Down Expand Up @@ -4476,6 +4479,7 @@ Usage: cardano-cli alonzo transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--proposal-file FILE]
--out-file FILE

Build a transaction (low-level, inconvenient)
Expand Down Expand Up @@ -5688,6 +5692,7 @@ Usage: cardano-cli babbage transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--proposal-file FILE]
--out-file FILE

Build a transaction (low-level, inconvenient)
Expand Down Expand Up @@ -7244,6 +7249,7 @@ Usage: cardano-cli conway transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--proposal-file FILE]
--out-file FILE

Build a transaction (low-level, inconvenient)
Expand Down Expand Up @@ -8453,6 +8459,7 @@ Usage: cardano-cli latest transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--proposal-file FILE]
--out-file FILE

Build a transaction (low-level, inconvenient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Usage: cardano-cli allegra transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--proposal-file FILE]
--out-file FILE

Build a transaction (low-level, inconvenient)
Expand Down Expand Up @@ -381,5 +382,6 @@ Available options:
Filepath of the JSON-encoded protocol parameters file
--update-proposal-file FILE
Filepath of the update proposal.
--proposal-file FILE Filepath of the proposal.
--out-file FILE Output filepath of the JSON TxBody.
-h,--help Show this help text
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Usage: cardano-cli alonzo transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--proposal-file FILE]
--out-file FILE

Build a transaction (low-level, inconvenient)
Expand Down Expand Up @@ -381,5 +382,6 @@ Available options:
Filepath of the JSON-encoded protocol parameters file
--update-proposal-file FILE
Filepath of the update proposal.
--proposal-file FILE Filepath of the proposal.
--out-file FILE Output filepath of the JSON TxBody.
-h,--help Show this help text
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Usage: cardano-cli babbage transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--proposal-file FILE]
--out-file FILE

Build a transaction (low-level, inconvenient)
Expand Down Expand Up @@ -381,5 +382,6 @@ Available options:
Filepath of the JSON-encoded protocol parameters file
--update-proposal-file FILE
Filepath of the update proposal.
--proposal-file FILE Filepath of the proposal.
--out-file FILE Output filepath of the JSON TxBody.
-h,--help Show this help text
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Usage: cardano-cli conway transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--proposal-file FILE]
--out-file FILE

Build a transaction (low-level, inconvenient)
Expand Down Expand Up @@ -381,5 +382,6 @@ Available options:
Filepath of the JSON-encoded protocol parameters file
--update-proposal-file FILE
Filepath of the update proposal.
--proposal-file FILE Filepath of the proposal.
--out-file FILE Output filepath of the JSON TxBody.
-h,--help Show this help text
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Usage: cardano-cli latest transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--proposal-file FILE]
--out-file FILE

Build a transaction (low-level, inconvenient)
Expand Down Expand Up @@ -381,5 +382,6 @@ Available options:
Filepath of the JSON-encoded protocol parameters file
--update-proposal-file FILE
Filepath of the update proposal.
--proposal-file FILE Filepath of the proposal.
--out-file FILE Output filepath of the JSON TxBody.
-h,--help Show this help text
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Usage: cardano-cli mary transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--proposal-file FILE]
--out-file FILE

Build a transaction (low-level, inconvenient)
Expand Down Expand Up @@ -381,5 +382,6 @@ Available options:
Filepath of the JSON-encoded protocol parameters file
--update-proposal-file FILE
Filepath of the update proposal.
--proposal-file FILE Filepath of the proposal.
--out-file FILE Output filepath of the JSON TxBody.
-h,--help Show this help text
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Usage: cardano-cli shelley transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--proposal-file FILE]
--out-file FILE

Build a transaction (low-level, inconvenient)
Expand Down Expand Up @@ -381,5 +382,6 @@ Available options:
Filepath of the JSON-encoded protocol parameters file
--update-proposal-file FILE
Filepath of the update proposal.
--proposal-file FILE Filepath of the proposal.
--out-file FILE Output filepath of the JSON TxBody.
-h,--help Show this help text

0 comments on commit c444f26

Please sign in to comment.