From 1359c88c232f8587e9f9b3316fbe9b6bb1f2f8e4 Mon Sep 17 00:00:00 2001 From: Carlos LopezDeLara Date: Wed, 6 Nov 2024 15:43:33 -0600 Subject: [PATCH 1/5] Check if stake address in proposals are registered onchain --- .../Cardano/CLI/EraBased/Run/Transaction.hs | 39 +++++++++++++++++++ .../Cardano/CLI/Types/Errors/TxCmdError.hs | 4 ++ 2 files changed, 43 insertions(+) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs index 08a8678e27..6277154ce3 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs @@ -59,6 +59,7 @@ import Cardano.CLI.Types.Output (renderScriptCosts) import Cardano.CLI.Types.TxFeature import Control.Monad (forM) +import Control.Monad.Cont (unless) import Data.Aeson ((.=)) import qualified Data.Aeson as Aeson import Data.Aeson.Encode.Pretty (encodePretty) @@ -208,6 +209,44 @@ runTransactionBuildCmd forM_ proposals (checkProposalHashes eon . fst) + -- Extract return addresses from proposals and check that the return address in each proposal is registered + + let returnAddrHashes = + Set.fromList + [ StakeCredentialByKey returnAddrHash + | (proposal, _) <- proposals + , let (_, returnAddrHash, _) = fromProposalProcedure eon proposal -- fromProposalProcedure needs to be adjusted so that it works with script hashes. + ] + treasuryWithdrawalAddresses = + Set.fromList + [ stakeCred + | (proposal, _) <- proposals + , let (_, _, govAction) = fromProposalProcedure eon proposal + , TreasuryWithdrawal withdrawalsList _ <- [govAction] -- Match on TreasuryWithdrawal action + , (_, stakeCred, _) <- withdrawalsList -- Extract fund-receiving stake credentials + ] + allAddrHashes = Set.union returnAddrHashes treasuryWithdrawalAddresses + + (balances, _) <- + lift + ( executeLocalStateQueryExpr + localNodeConnInfo + Consensus.VolatileTip + (queryStakeAddresses eon allAddrHashes networkId) + ) + & onLeft (left . TxCmdQueryConvenienceError . AcqFailure) + & onLeft (left . TxCmdQueryConvenienceError . QceUnsupportedNtcVersion) + & onLeft (left . TxCmdTxSubmitErrorEraMismatch) + + let unregisteredAddresses = + Set.filter + (\stakeCred -> Map.notMember (makeStakeAddress networkId stakeCred) balances) + allAddrHashes + + unless (null unregisteredAddresses) $ + throwError $ + TxCmdUnregisteredStakeAddress unregisteredAddresses + -- the same collateral input can be used for several plutus scripts let filteredTxinsc = nubOrd txinsc diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs index 510ebf6193..d8b44f0c64 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs @@ -31,6 +31,7 @@ import Cardano.CLI.Types.Output import Cardano.CLI.Types.TxFeature import qualified Cardano.Prelude as List +import Data.Set (Set) import Data.Text (Text) {- HLINT ignore "Use let" -} @@ -88,6 +89,7 @@ data TxCmdError | forall era. TxCmdFeeEstimationError (TxFeeEstimationError era) | TxCmdPoolMetadataHashError AnchorDataFromCertificateError | TxCmdHashCheckError L.Url HashCheckError + | TxCmdUnregisteredStakeAddress !(Set StakeCredential) renderTxCmdError :: TxCmdError -> Doc ann renderTxCmdError = \case @@ -225,6 +227,8 @@ renderTxCmdError = \case "Hash of the pool metadata hash is not valid:" <+> prettyError e TxCmdHashCheckError url e -> "Hash of the file is not valid. Url:" <+> pretty (L.urlToText url) <+> prettyException e + TxCmdUnregisteredStakeAddress credentials -> + "One or more stake addresses in proposals is not registered:" <+> pshow credentials prettyPolicyIdList :: [PolicyId] -> Doc ann prettyPolicyIdList = From aeeaea910c8bc103b039582b1e5b832db3f05027 Mon Sep 17 00:00:00 2001 From: Carlos LopezDeLara Date: Thu, 7 Nov 2024 11:26:56 -0600 Subject: [PATCH 2/5] fix import --- cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs index 6277154ce3..7b1e1d63b0 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs @@ -58,8 +58,7 @@ import Cardano.CLI.Types.Errors.TxValidationError import Cardano.CLI.Types.Output (renderScriptCosts) import Cardano.CLI.Types.TxFeature -import Control.Monad (forM) -import Control.Monad.Cont (unless) +import Control.Monad (forM, unless) import Data.Aeson ((.=)) import qualified Data.Aeson as Aeson import Data.Aeson.Encode.Pretty (encodePretty) From 3870e25970da191b0b89c8888529a91fed8758aa Mon Sep 17 00:00:00 2001 From: Carlos LopezDeLara <64222734+CarlosLopezDeLara@users.noreply.github.com> Date: Fri, 15 Nov 2024 08:32:53 -0600 Subject: [PATCH 3/5] Update cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs Co-authored-by: Mateusz Galazyn <228866+carbolymer@users.noreply.github.com> --- cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs index 7b1e1d63b0..abebe9612c 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs @@ -217,7 +217,7 @@ runTransactionBuildCmd , let (_, returnAddrHash, _) = fromProposalProcedure eon proposal -- fromProposalProcedure needs to be adjusted so that it works with script hashes. ] treasuryWithdrawalAddresses = - Set.fromList + fromList [ stakeCred | (proposal, _) <- proposals , let (_, _, govAction) = fromProposalProcedure eon proposal From 2870d500b608608fbf891d46fb44667d33ca5559 Mon Sep 17 00:00:00 2001 From: Carlos LopezDeLara Date: Fri, 15 Nov 2024 11:12:22 -0600 Subject: [PATCH 4/5] Use fromList not Set.fromList --- cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs index abebe9612c..877e7ddbdf 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs @@ -211,7 +211,7 @@ runTransactionBuildCmd -- Extract return addresses from proposals and check that the return address in each proposal is registered let returnAddrHashes = - Set.fromList + fromList [ StakeCredentialByKey returnAddrHash | (proposal, _) <- proposals , let (_, returnAddrHash, _) = fromProposalProcedure eon proposal -- fromProposalProcedure needs to be adjusted so that it works with script hashes. From 9f6376ca840b781c8300e4725cdcecc9dc06cce1 Mon Sep 17 00:00:00 2001 From: Carlos LopezDeLara Date: Fri, 15 Nov 2024 11:45:53 -0600 Subject: [PATCH 5/5] improve error message --- cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs index d8b44f0c64..19582fba41 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs @@ -228,7 +228,7 @@ renderTxCmdError = \case TxCmdHashCheckError url e -> "Hash of the file is not valid. Url:" <+> pretty (L.urlToText url) <+> prettyException e TxCmdUnregisteredStakeAddress credentials -> - "One or more stake addresses in proposals is not registered:" <+> pshow credentials + "Stake credential specified in the proposal is not registered on-chain:" <+> pshow credentials prettyPolicyIdList :: [PolicyId] -> Doc ann prettyPolicyIdList =