add IsData instances to ProposalTypes

This commit is contained in:
Emily Martins 2022-03-28 13:51:30 +02:00
parent 935b01f0d4
commit b0f948d07a

View file

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
{- | {- |
Module : Agora.Proposal Module : Agora.Proposal
Maintainer : emi@haskell.fyi Maintainer : emi@haskell.fyi
@ -31,6 +33,7 @@ import Plutarch.DataRepr (
PIsDataReprInstances (PIsDataReprInstances), PIsDataReprInstances (PIsDataReprInstances),
) )
import Plutus.V1.Ledger.Api (DatumHash, PubKeyHash, ValidatorHash) import Plutus.V1.Ledger.Api (DatumHash, PubKeyHash, ValidatorHash)
import PlutusTx qualified
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -47,6 +50,7 @@ import Agora.SafeMoney (Discrete, GTTag, PDiscrete)
@ @
-} -}
newtype ResultTag = ResultTag {getResultTag :: Integer} newtype ResultTag = ResultTag {getResultTag :: Integer}
deriving newtype (PlutusTx.ToData, PlutusTx.FromData, PlutusTx.UnsafeFromData)
{- | The "status" of the proposal. This is only useful for state transitions, {- | The "status" of the proposal. This is only useful for state transitions,
as opposed to time-based "phases". as opposed to time-based "phases".
@ -79,6 +83,8 @@ data ProposalStatus
-- TODO: The owner of the proposal may choose to reclaim their proposal. -- TODO: The owner of the proposal may choose to reclaim their proposal.
Finished Finished
PlutusTx.makeIsDataIndexed ''ProposalStatus [('Draft, 0), ('VotingReady, 1), ('Finished, 2)]
{- | The threshold values for various state transitions to happen. {- | The threshold values for various state transitions to happen.
This data is stored centrally (in the Governor) and copied over This data is stored centrally (in the Governor) and copied over
to Proposals when they are created. to Proposals when they are created.
@ -93,6 +99,8 @@ data ProposalThresholds = ProposalThresholds
-- (i.e. to move into 'VotingReady') -- (i.e. to move into 'VotingReady')
} }
PlutusTx.makeIsDataIndexed ''ProposalThresholds [('ProposalThresholds, 0)]
{- | Map which encodes the total tally for each result. {- | Map which encodes the total tally for each result.
It's important that the 'shape' is consistent with the shape of 'effects'. It's important that the 'shape' is consistent with the shape of 'effects'.
@ -107,6 +115,7 @@ data ProposalThresholds = ProposalThresholds
newtype ProposalVotes = ProposalVotes newtype ProposalVotes = ProposalVotes
{ getProposalVotes :: [(ResultTag, Integer)] { getProposalVotes :: [(ResultTag, Integer)]
} }
deriving newtype (PlutusTx.ToData, PlutusTx.FromData, PlutusTx.UnsafeFromData)
-- | Haskell-level datum for Proposal scripts. -- | Haskell-level datum for Proposal scripts.
data ProposalDatum = ProposalDatum data ProposalDatum = ProposalDatum
@ -125,6 +134,8 @@ data ProposalDatum = ProposalDatum
-- ^ Vote tally on the proposal -- ^ Vote tally on the proposal
} }
PlutusTx.makeIsDataIndexed ''ProposalDatum [('ProposalDatum, 0)]
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- Plutarch-land -- Plutarch-land