Skip to content

Commit

Permalink
Add new flags to disable metadata checks on proposals and votes to bu…
Browse files Browse the repository at this point in the history
…ild cmd.

Add new flags to disable metadata checks on proposals and votes to build cmd.

Add new flags to disable metadata checks on proposals and votes to build cmd.

The build cmd automatically runs checks on the metadata hashes on proposals and votes included in the transaction. The new flags allow the user to disable such checks. Useful for testing purposes and for users that may want to avoid CLI reaching out to the internet.

--disable-metadata-checks-on-proposals
--disable-metadata-checks-on-votes
  • Loading branch information
CarlosLopezDeLara committed Feb 13, 2025
1 parent bb8b3b9 commit 53773b5
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 2 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 @@ -133,6 +133,8 @@ data TransactionBuildCmdArgs era = TransactionBuildCmdArgs
, mUpdateProposalFile :: !(Maybe (Featured ShelleyToBabbageEra era (Maybe UpdateProposalFile)))
, voteFiles :: ![(VoteFile In, Maybe CliVoteScriptRequirements)]
, proposalFiles :: ![(ProposalFile In, Maybe CliProposalScriptRequirements)]
, metadataChecksOnProposals :: !MetadataCheck
, metadataChecksOnVotes :: !MetadataCheck
, treasuryDonation :: !(Maybe TxTreasuryDonation)
, buildOutputOptions :: !TxBuildOutputOptions
}
Expand Down
19 changes: 19 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Cardano.CLI.EraBased.Commands.Transaction
import Cardano.CLI.EraBased.Options.Common
import Cardano.CLI.Parser
import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Governance

import Data.Foldable
import Options.Applicative hiding (help, str)
Expand Down Expand Up @@ -200,6 +201,8 @@ pTransactionBuildCmd sbe envCli = do
<*> pFeatured (toCardanoEra sbe) (optional pUpdateProposalFile)
<*> pVoteFiles sbe AutoBalance
<*> pProposalFiles sbe AutoBalance
<*> pMetadataChecksOnProposals
<*> pMetadataChecksOnVotes
<*> pTreasuryDonation sbe
<*> pTxBuildOutputOptions

Expand Down Expand Up @@ -384,3 +387,19 @@ pTransactionId =
TransactionTxIdCmdArgs
<$> pInputTxOrTxBodyFile
<*> pTxIdOutputFormatJsonOrText

pMetadataChecksOnProposals :: Parser MetadataCheck
pMetadataChecksOnProposals =
Opt.flag EnableMetadataCheck DisableMetadataCheck $
mconcat
[ Opt.long "disable-metadata-checks-on-proposals"
, Opt.help "Disable automatic metadata-hash checks on proposals included in the transaction."
]

pMetadataChecksOnVotes :: Parser MetadataCheck
pMetadataChecksOnVotes =
Opt.flag EnableMetadataCheck DisableMetadataCheck $
mconcat
[ Opt.long "disable-metadata-checks-on-votes"
, Opt.help "Disable automatic metadata-hash checks on votes included in the transaction."
]
12 changes: 10 additions & 2 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import Cardano.CLI.Types.Errors.BootstrapWitnessError
import Cardano.CLI.Types.Errors.NodeEraMismatchError
import Cardano.CLI.Types.Errors.TxCmdError
import Cardano.CLI.Types.Errors.TxValidationError
import Cardano.CLI.Types.Governance
import Cardano.CLI.Types.Output (renderScriptCosts)
import Cardano.CLI.Types.TxFeature

Expand Down Expand Up @@ -147,6 +148,8 @@ runTransactionBuildCmd
, mUpdateProposalFile
, voteFiles
, proposalFiles
, metadataChecksOnProposals
, metadataChecksOnVotes
, treasuryDonation -- Maybe TxTreasuryDonation
, buildOutputOptions
} = do
Expand Down Expand Up @@ -209,14 +212,19 @@ runTransactionBuildCmd
(\w -> firstExceptT TxCmdVoteError $ ExceptT (readVotingProceduresFiles w voteFiles))
era'

forM_ votingProceduresAndMaybeScriptWits (checkVotingProcedureHashes eon . fst)
unless (metadataChecksOnVotes == DisableMetadataCheck) $
forM_ votingProceduresAndMaybeScriptWits (checkVotingProcedureHashes eon . fst)

-- unless disableMetadataChecksOnVotes $
-- forM_ votingProceduresAndMaybeScriptWits (checkVotingProcedureHashes eon . fst)

proposals <-
newExceptT $
first TxCmdProposalError
<$> readTxGovernanceActions eon proposalFiles

forM_ proposals (checkProposalHashes eon . fst)
unless (metadataChecksOnProposals == DisableMetadataCheck) $
forM_ proposals (checkProposalHashes eon . fst)

-- Extract return addresses from proposals and check that the return address in each proposal is registered

Expand Down
3 changes: 3 additions & 0 deletions cardano-cli/src/Cardano/CLI/Types/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ data VoteDelegationTarget
| VoteDelegationTargetOfAbstain
| VoteDelegationTargetOfNoConfidence
deriving (Eq, Show)

data MetadataCheck = EnableMetadataCheck | DisableMetadataCheck
deriving (Eq, Show)
6 changes: 6 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 @@ -6435,6 +6435,8 @@ Usage: cardano-cli babbage transaction build
| --metadata-cbor-file FILEPATH
]
[--update-proposal-file FILEPATH]
[--disable-metadata-checks-on-proposals]
[--disable-metadata-checks-on-votes]
( --out-file FILEPATH
| --calculate-plutus-script-cost FILEPATH
)
Expand Down Expand Up @@ -8489,6 +8491,8 @@ Usage: cardano-cli conway transaction build
| --proposal-reference-tx-in-redeemer-value JSON_VALUE
)
]]
[--disable-metadata-checks-on-proposals]
[--disable-metadata-checks-on-votes]
[--treasury-donation LOVELACE]
( --out-file FILEPATH
| --calculate-plutus-script-cost FILEPATH
Expand Down Expand Up @@ -10577,6 +10581,8 @@ Usage: cardano-cli latest transaction build
| --proposal-reference-tx-in-redeemer-value JSON_VALUE
)
]]
[--disable-metadata-checks-on-proposals]
[--disable-metadata-checks-on-votes]
[--treasury-donation LOVELACE]
( --out-file FILEPATH
| --calculate-plutus-script-cost FILEPATH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ Usage: cardano-cli babbage transaction build
| --metadata-cbor-file FILEPATH
]
[--update-proposal-file FILEPATH]
[--disable-metadata-checks-on-proposals]
[--disable-metadata-checks-on-votes]
( --out-file FILEPATH
| --calculate-plutus-script-cost FILEPATH
)
Expand Down Expand Up @@ -391,6 +393,12 @@ Available options:
Filepath of the metadata, in raw CBOR format.
--update-proposal-file FILEPATH
Filepath of the update proposal.
--disable-metadata-checks-on-proposals
Disable automatic metadata-hash checks on proposals
included in the transaction.
--disable-metadata-checks-on-votes
Disable automatic metadata-hash checks on votes
included in the transaction.
--out-file FILEPATH Output filepath of the JSON TxBody.
--calculate-plutus-script-cost FILEPATH
Where to write the script cost information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ Usage: cardano-cli conway transaction build
| --proposal-reference-tx-in-redeemer-value JSON_VALUE
)
]]
[--disable-metadata-checks-on-proposals]
[--disable-metadata-checks-on-votes]
[--treasury-donation LOVELACE]
( --out-file FILEPATH
| --calculate-plutus-script-cost FILEPATH
Expand Down Expand Up @@ -470,6 +472,12 @@ Available options:
The script redeemer value. There is no schema:
(almost) any JSON value is supported, including
top-level strings and numbers.
--disable-metadata-checks-on-proposals
Disable automatic metadata-hash checks on proposals
included in the transaction.
--disable-metadata-checks-on-votes
Disable automatic metadata-hash checks on votes
included in the transaction.
--treasury-donation LOVELACE
The donation to the treasury to perform.
--out-file FILEPATH Output filepath of the JSON TxBody.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ Usage: cardano-cli latest transaction build
| --proposal-reference-tx-in-redeemer-value JSON_VALUE
)
]]
[--disable-metadata-checks-on-proposals]
[--disable-metadata-checks-on-votes]
[--treasury-donation LOVELACE]
( --out-file FILEPATH
| --calculate-plutus-script-cost FILEPATH
Expand Down Expand Up @@ -470,6 +472,12 @@ Available options:
The script redeemer value. There is no schema:
(almost) any JSON value is supported, including
top-level strings and numbers.
--disable-metadata-checks-on-proposals
Disable automatic metadata-hash checks on proposals
included in the transaction.
--disable-metadata-checks-on-votes
Disable automatic metadata-hash checks on votes
included in the transaction.
--treasury-donation LOVELACE
The donation to the treasury to perform.
--out-file FILEPATH Output filepath of the JSON TxBody.
Expand Down

0 comments on commit 53773b5

Please sign in to comment.