Skip to content

Commit

Permalink
address formatting issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosLopezDeLara committed Nov 7, 2024
1 parent 0a060c4 commit 7b9d4ca
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
54 changes: 33 additions & 21 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import qualified Ouroboros.Network.Protocol.LocalStateQuery.Type as Consensus
import qualified Ouroboros.Network.Protocol.LocalTxSubmission.Client as Net.Tx

import Control.Monad (forM)
import Control.Monad.Cont (unless)
import Data.Aeson ((.=))
import qualified Data.Aeson as Aeson
import Data.Aeson.Encode.Pretty (encodePretty)
Expand All @@ -80,7 +81,6 @@ import Data.Type.Equality (TestEquality (..))
import GHC.Exts (IsList (..))
import Lens.Micro ((^.))
import qualified System.IO as IO
import Control.Monad.Cont (unless)

runTransactionCmds :: Cmd.TransactionCmds era -> ExceptT TxCmdError IO ()
runTransactionCmds = \case
Expand Down Expand Up @@ -199,31 +199,43 @@ runTransactionBuildCmd
first TxCmdProposalError
<$> readTxGovernanceActions eon proposalFiles

-- Extract return addresses from proposals and check that the return address in each proposal is registered
-- 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
]
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
(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
throwError $
TxCmdUnregisteredStakeAddress unregisteredAddresses

-- the same collateral input can be used for several plutus scripts
let filteredTxinsc = nubOrd txinsc
Expand Down
3 changes: 2 additions & 1 deletion cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import Cardano.CLI.Types.TxFeature
import qualified Cardano.Prelude as List
import Ouroboros.Consensus.Cardano.Block (EraMismatch (..))

import Data.Set (Set)
import Data.Text (Text)
import Data.Set (Set)

{- HLINT ignore "Use let" -}

Expand Down Expand Up @@ -221,6 +221,7 @@ renderTxCmdError = \case
prettyError e
TxCmdUnregisteredStakeAddress credentials ->
"One or more stake addresses in proposals is not registered:" <+> pshow credentials

prettyPolicyIdList :: [PolicyId] -> Doc ann
prettyPolicyIdList =
mconcat . List.intersperse ", " . fmap (pretty . serialiseToRawBytesHexText)

0 comments on commit 7b9d4ca

Please sign in to comment.