Skip to content

Commit

Permalink
Further tighten bounds to ConwayEraOnwards
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Jul 28, 2023
1 parent d64776e commit af7749e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 66 deletions.
2 changes: 1 addition & 1 deletion cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ genTxBodyContent era = do
txMintValue <- genTxMintValue era
txScriptValidity <- genTxScriptValidity era
txGovernanceActions <- return TxGovernanceActionsNone -- TODO: Conway era
txVotes <- return TxVotesNone -- TODO: Conway era
txVotes <- return Nothing -- TODO: Conway era
pure $ TxBodyContent
{ Api.txIns
, Api.txInsCollateral
Expand Down
1 change: 1 addition & 0 deletions cardano-api/internal/Cardano/Api/Feature.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
{-# LANGUAGE UndecidableInstances #-}

module Cardano.Api.Governance.Actions.VotingProcedure
( TxVotes(..)
, TxVotesSupportedInEra(..)
, votesSupportedInEra
, GovernanceActionId(..)
( GovernanceActionId(..)
, makeGoveranceActionId
, Voter(..)
, Vote(..)
Expand Down Expand Up @@ -55,43 +52,6 @@ import qualified Cardano.Ledger.TxIn as Ledger
import Data.ByteString.Lazy (ByteString)
import Data.Maybe.Strict

-- | A representation of whether the era supports tx voting on governance actions.
--
-- The Conway and subsequent eras support tx voting on governance actions.
--
data TxVotes era where
TxVotesNone :: TxVotes era

TxVotes
:: TxVotesSupportedInEra era
-> [VotingProcedure era]
-> TxVotes era

deriving instance Show (TxVotes era)
deriving instance Eq (TxVotes era)


-- | A representation of whether the era supports transactions with votes.
--
-- The Conway and subsequent eras support governance actions.
--
data TxVotesSupportedInEra era where

VotesSupportedInConwayEra :: TxVotesSupportedInEra ConwayEra

deriving instance Show (TxVotesSupportedInEra era)
deriving instance Eq (TxVotesSupportedInEra era)


votesSupportedInEra :: ShelleyBasedEra era -> Maybe (TxVotesSupportedInEra era)
votesSupportedInEra = \case
ShelleyBasedEraShelley -> Nothing
ShelleyBasedEraAllegra -> Nothing
ShelleyBasedEraMary -> Nothing
ShelleyBasedEraAlonzo -> Nothing
ShelleyBasedEraBabbage -> Nothing
ShelleyBasedEraConway -> Just VotesSupportedInConwayEra

newtype GovernanceActionId ledgerera = GovernanceActionId
{ unGovernanceActionId :: Ledger.GovernanceActionId (EraCrypto ledgerera)
}
Expand Down
38 changes: 19 additions & 19 deletions cardano-api/internal/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ import Cardano.Api.Convenience.Constraints
import Cardano.Api.EraCast
import Cardano.Api.Eras
import Cardano.Api.Error
import Cardano.Api.Feature
import Cardano.Api.Feature.ConwayEraOnwards
import Cardano.Api.Governance.Actions.ProposalProcedure
import Cardano.Api.Governance.Actions.VotingProcedure
import Cardano.Api.Hash
Expand Down Expand Up @@ -1757,7 +1759,7 @@ data TxBodyContent build era =
txMintValue :: TxMintValue build era,
txScriptValidity :: TxScriptValidity era,
txGovernanceActions :: TxGovernanceActions era,
txVotes :: TxVotes era
txVotes :: Maybe (Featured ConwayEraOnwards era [VotingProcedure era])
}
deriving (Eq, Show)

Expand All @@ -1781,7 +1783,7 @@ defaultTxBodyContent = TxBodyContent
, txMintValue = TxMintNone
, txScriptValidity = TxScriptValidityNone
, txGovernanceActions = TxGovernanceActionsNone
, txVotes = TxVotesNone
, txVotes = Nothing
}

setTxIns :: TxIns build era -> TxBodyContent build era -> TxBodyContent build era
Expand Down Expand Up @@ -2730,7 +2732,7 @@ fromLedgerTxBody sbe scriptValidity body scriptdata mAux =
, txAuxScripts
, txScriptValidity = scriptValidity
, txGovernanceActions = fromLedgerProposalProcedure sbe body
, txVotes = fromLedgerTxVotes sbe body
, txVotes = featureInShelleyBasedEra Nothing (\w -> Just (fromLedgerTxVotes w body)) sbe
}
where
(txMetadata, txAuxScripts) = fromLedgerTxAuxiliaryData sbe mAux
Expand All @@ -2751,16 +2753,14 @@ fromLedgerProposalProcedure sbe body =
getProposals GovernanceActionsSupportedInConwayEra body_ = fmap Proposal . toList $ body_ ^. L.proposalProceduresTxBodyL


fromLedgerTxVotes :: ShelleyBasedEra era -> Ledger.TxBody (ShelleyLedgerEra era) -> TxVotes era
fromLedgerTxVotes sbe body =
case votesSupportedInEra sbe of
Nothing -> TxVotesNone
Just vsice -> TxVotes vsice (getVotes vsice body)
where
getVotes :: TxVotesSupportedInEra era
-> Ledger.TxBody (ShelleyLedgerEra era)
-> [VotingProcedure era]
getVotes VotesSupportedInConwayEra body_ = fmap VotingProcedure . toList $ body_ ^. L.votingProceduresTxBodyL
fromLedgerTxVotes :: ()
=> ConwayEraOnwards era
-> Ledger.TxBody (ShelleyLedgerEra era)
-> Featured ConwayEraOnwards era [VotingProcedure era]
fromLedgerTxVotes w body =
conwayEraOnwardsConstraints w
$ Featured w
$ fmap VotingProcedure $ toList $ body ^. L.votingProceduresTxBodyL

fromLedgerTxIns
:: forall era.
Expand Down Expand Up @@ -3430,7 +3430,7 @@ getByronTxBodyContent (Annotated Byron.UnsafeTx{txInputs, txOutputs} _) =
, txMintValue = TxMintNone
, txScriptValidity = TxScriptValidityNone
, txGovernanceActions = TxGovernanceActionsNone
, txVotes = TxVotesNone
, txVotes = Nothing
}

convTxIns :: TxIns BuildTx era -> Set (L.TxIn StandardCrypto)
Expand Down Expand Up @@ -3611,10 +3611,10 @@ convGovActions :: TxGovernanceActions era -> Seq.StrictSeq (Gov.ProposalProcedur
convGovActions TxGovernanceActionsNone = Seq.empty
convGovActions (TxGovernanceActions _ govActions) = Seq.fromList $ fmap unProposal govActions

convVotes :: ShelleyBasedEra era -> TxVotes era -> Seq.StrictSeq (Gov.VotingProcedure (ShelleyLedgerEra era))
convVotes _ = \case
TxVotesNone -> Seq.empty
TxVotes _ votes -> Seq.fromList $ map unVotingProcedure votes
convVotes :: ()
=> Featured ConwayEraOnwards era [VotingProcedure era]
-> Seq.StrictSeq (Gov.VotingProcedure (ShelleyLedgerEra era))
convVotes (Featured _ v) = Seq.fromList $ map unVotingProcedure v

guardShelleyTxInsOverflow :: [TxIn] -> Either TxBodyError ()
guardShelleyTxInsOverflow txIns = do
Expand Down Expand Up @@ -3984,7 +3984,7 @@ makeShelleyTransactionBody sbe@ShelleyBasedEraConway
& L.reqSignerHashesTxBodyL .~ convExtraKeyWitnesses txExtraKeyWits
& L.mintTxBodyL .~ convMintValue txMintValue
& L.scriptIntegrityHashTxBodyL .~ scriptIntegrityHash
& L.votingProceduresTxBodyL .~ convVotes sbe txVotes
& L.votingProceduresTxBodyL .~ maybe mempty convVotes txVotes
& L.proposalProceduresTxBodyL .~ convGovActions txGovernanceActions
-- TODO Conway: support optional network id in TxBodyContent
-- & L.networkIdTxBodyL .~ SNothing
Expand Down
4 changes: 0 additions & 4 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ module Cardano.Api (
TxCertificates(..),
TxUpdateProposal(..),
TxMintValue(..),
TxVotes(..),
TxGovernanceActions(..),

-- ** Building vs viewing transactions
Expand All @@ -305,7 +304,6 @@ module Cardano.Api (
CertificatesSupportedInEra(..),
UpdateProposalSupportedInEra(..),
TxTotalAndReturnCollateralSupportedInEra(..),
TxVotesSupportedInEra(..),
TxGovernanceActionSupportedInEra(..),

-- ** Feature availability functions
Expand All @@ -323,7 +321,6 @@ module Cardano.Api (
updateProposalSupportedInEra,
scriptDataSupportedInEra,
totalAndReturnCollateralSupportedInEra,
votesSupportedInEra,
governanceActionsSupportedInEra,

-- ** Era-dependent protocol features
Expand Down Expand Up @@ -960,7 +957,6 @@ import Cardano.Api.Fees
import Cardano.Api.Genesis
import Cardano.Api.GenesisParameters
import Cardano.Api.Governance.Actions.ProposalProcedure
import Cardano.Api.Governance.Actions.VotingProcedure
import Cardano.Api.Hash
import Cardano.Api.HasTypeProxy
import Cardano.Api.InMode
Expand Down
1 change: 0 additions & 1 deletion cardano-api/src/Cardano/Api/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ module Cardano.Api.Shelley
GovernanceActionId(..),
Proposal(..),
TxGovernanceActions(..),
TxVotes(..),
VotingProcedure(..),
GovernancePoll(..),
GovernancePollAnswer(..),
Expand Down

0 comments on commit af7749e

Please sign in to comment.