Skip to content

Commit

Permalink
Merge pull request #365 from input-output-hk/newhoggy/build-raw-conwa…
Browse files Browse the repository at this point in the history
…y-support

`transaction build-raw` support for `--vote-file` and `--proposal-file`
  • Loading branch information
newhoggy authored Oct 12, 2023
2 parents 935d5e8 + d86ff89 commit fea0796
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 21 deletions.
2 changes: 2 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ data TransactionCmds era
[MetadataFile]
(Maybe ProtocolParamsFile)
(Maybe UpdateProposalFile)
[VoteFile In]
[ProposalFile In]
(TxBodyFile Out)

-- | Like 'TxBuildRaw' but without the fee, and with a change output.
Expand Down
2 changes: 2 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ pTransactionBuildRaw era =
<*> many pMetadataFile
<*> optional pProtocolParamsFile
<*> optional pUpdateProposalFile
<*> many (pFileInDirection "vote-file" "Filepath of the vote.")
<*> many (pFileInDirection "proposal-file" "Filepath of the proposal.")
<*> pTxBodyFileOut

pTransactionSign :: EnvCli -> Parser (TransactionCmds era)
Expand Down
60 changes: 40 additions & 20 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,24 @@ 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 voteFiles
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 voteFiles
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
voteFiles 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
voteFiles proposalFiles
out
TxSign txinfile skfiles network txoutfile ->
runTxSignCmd txinfile skfiles network txoutfile
TxSubmit mNodeSocketPath anyConsensusModeParams network txFp ->
Expand Down Expand Up @@ -150,7 +154,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
voteFiles 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 +196,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 voteFiles))
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 +214,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 +309,15 @@ runTxBuildRawCmd
-> [MetadataFile]
-> Maybe ProtocolParamsFile
-> Maybe UpdateProposalFile
-> [VoteFile In]
-> [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
voteFiles proposalFiles out = do
inputsAndMaybeScriptWits <- firstExceptT TxCmdScriptWitnessError
$ readScriptWitnessFiles era txins
certFilesAndMaybeScriptWits <- firstExceptT TxCmdScriptWitnessError
Expand Down Expand Up @@ -357,10 +364,21 @@ runTxBuildRawCmd
-- the same collateral input can be used for several plutus scripts
let filteredTxinsc = Set.toList $ Set.fromList txinsc

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

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 votingProcedures proposals

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

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

first TxCmdTxBodyError $
Expand Down Expand Up @@ -513,7 +533,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 +595,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
14 changes: 14 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 @@ -915,6 +915,8 @@ Usage: cardano-cli shelley transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--vote-file FILE]
[--proposal-file FILE]
--out-file FILE

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

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

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

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

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

Build a transaction (low-level, inconvenient)
Expand Down Expand Up @@ -8258,6 +8270,8 @@ Usage: cardano-cli latest transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--vote-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,8 @@ Usage: cardano-cli allegra transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--vote-file FILE]
[--proposal-file FILE]
--out-file FILE

Build a transaction (low-level, inconvenient)
Expand Down Expand Up @@ -381,5 +383,7 @@ Available options:
Filepath of the JSON-encoded protocol parameters file
--update-proposal-file FILE
Filepath of the update proposal.
--vote-file FILE Filepath of the vote.
--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,8 @@ Usage: cardano-cli alonzo transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--vote-file FILE]
[--proposal-file FILE]
--out-file FILE

Build a transaction (low-level, inconvenient)
Expand Down Expand Up @@ -381,5 +383,7 @@ Available options:
Filepath of the JSON-encoded protocol parameters file
--update-proposal-file FILE
Filepath of the update proposal.
--vote-file FILE Filepath of the vote.
--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,8 @@ Usage: cardano-cli babbage transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--vote-file FILE]
[--proposal-file FILE]
--out-file FILE

Build a transaction (low-level, inconvenient)
Expand Down Expand Up @@ -381,5 +383,7 @@ Available options:
Filepath of the JSON-encoded protocol parameters file
--update-proposal-file FILE
Filepath of the update proposal.
--vote-file FILE Filepath of the vote.
--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,8 @@ Usage: cardano-cli conway transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--vote-file FILE]
[--proposal-file FILE]
--out-file FILE

Build a transaction (low-level, inconvenient)
Expand Down Expand Up @@ -381,5 +383,7 @@ Available options:
Filepath of the JSON-encoded protocol parameters file
--update-proposal-file FILE
Filepath of the update proposal.
--vote-file FILE Filepath of the vote.
--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,8 @@ Usage: cardano-cli latest transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--vote-file FILE]
[--proposal-file FILE]
--out-file FILE

Build a transaction (low-level, inconvenient)
Expand Down Expand Up @@ -381,5 +383,7 @@ Available options:
Filepath of the JSON-encoded protocol parameters file
--update-proposal-file FILE
Filepath of the update proposal.
--vote-file FILE Filepath of the vote.
--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,8 @@ Usage: cardano-cli mary transaction build-raw
]
[--protocol-params-file FILE]
[--update-proposal-file FILE]
[--vote-file FILE]
[--proposal-file FILE]
--out-file FILE

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

0 comments on commit fea0796

Please sign in to comment.