Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plutus cost model: validate sizes in genesis files #724

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions cardano-api/internal/Cardano/Api/Governance/Poll.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}

-- | An API for driving on-chain poll for SPOs.
--
Expand Down Expand Up @@ -37,8 +36,10 @@ module Cardano.Api.Governance.Poll
)
where

import Cardano.Api.Pretty
import Cardano.Api.Error
import Cardano.Api.ProtocolParameters
import Cardano.Api.Eon.ShelleyBasedEra
import Cardano.Api.Eras
import Cardano.Api.Hash
import Cardano.Api.HasTypeProxy
import Cardano.Api.Keys.Shelley
Expand All @@ -58,6 +59,7 @@ import Cardano.Ledger.Crypto (HASH, StandardCrypto)

import Control.Arrow (left)
import Control.Monad (foldM, when)
import Data.Bifunctor (first)
import Data.Either.Combinators (maybeToRight)
import Data.Function ((&))
import qualified Data.Map.Strict as Map
Expand Down Expand Up @@ -279,6 +281,7 @@ data GovernancePollError
| ErrGovernancePollUnauthenticated
| ErrGovernancePollMalformedAnswer DecoderError
| ErrGovernancePollInvalidAnswer GovernancePollInvalidAnswerError
| ErrGovernancePollCostModelNotEnoughParameters CostModelNotEnoughParametersError
deriving Show

data GovernancePollInvalidAnswerError = GovernancePollInvalidAnswerError
Expand Down Expand Up @@ -331,6 +334,9 @@ renderGovernancePollError err =
| (ix, answer) <- invalidAnswerAcceptableAnswers invalidAnswer
]
]
ErrGovernancePollCostModelNotEnoughParameters err' ->
-- TODO can be simplified?
Text.pack $ docToString $ prettyError err'

-- | Verify a poll against a given transaction and returns the signatories
-- (verification key only) when valid.
Expand All @@ -341,12 +347,14 @@ verifyPollAnswer
:: GovernancePoll
-> InAnyShelleyBasedEra Tx
-> Either GovernancePollError [Hash PaymentKey]
verifyPollAnswer poll (InAnyShelleyBasedEra _era (getTxBody -> TxBody body)) = do
answer <- extractPollAnswer (txMetadata body)
verifyPollAnswer poll (InAnyShelleyBasedEra _era tx) = do
content <- first ErrGovernancePollCostModelNotEnoughParameters $ getTxBodyContent body
answer <- extractPollAnswer (txMetadata content)
answer `hasMatchingHash` hashGovernancePoll poll
answer `isAmongAcceptableChoices` govPollAnswers poll
extraKeyWitnesses (txExtraKeyWits body)
extraKeyWitnesses (txExtraKeyWits content)
where
body = getTxBody tx
extractPollAnswer = \case
TxMetadataNone ->
Left ErrGovernancePollNoAnswer
Expand Down
Loading
Loading