export PGovernorRedeemer

This commit is contained in:
fanghr 2022-04-15 13:11:48 +08:00
parent c432a06d5e
commit b546fc9701

View file

@ -15,6 +15,7 @@ module Agora.Governor (
-- * Plutarch-land -- * Plutarch-land
PGovernorDatum (..), PGovernorDatum (..),
PGovernorRedeemer (..),
-- * Scripts -- * Scripts
governorPolicy, governorPolicy,
@ -28,7 +29,7 @@ import Generics.SOP (Generic, I (I))
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
import Agora.Proposal (ProposalId, ProposalThresholds, PProposalThresholds, PProposalId) import Agora.Proposal (PProposalId, PProposalThresholds, ProposalId, ProposalThresholds)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -54,7 +55,7 @@ data GovernorDatum = GovernorDatum
-- ^ Gets copied over upon creation of a 'Agora.Proposal.ProposalDatum'. -- ^ Gets copied over upon creation of a 'Agora.Proposal.ProposalDatum'.
, nextProposalId :: ProposalId , nextProposalId :: ProposalId
-- ^ What tag the next proposal will get upon creating. -- ^ What tag the next proposal will get upon creating.
} }
deriving stock (Show, GHC.Generic) deriving stock (Show, GHC.Generic)
PlutusTx.makeIsDataIndexed ''GovernorDatum [('GovernorDatum, 0)] PlutusTx.makeIsDataIndexed ''GovernorDatum [('GovernorDatum, 0)]
@ -71,38 +72,40 @@ data GovernorRedeemer
| -- | Checks that a SINGLE proposal finished correctly, | -- | Checks that a SINGLE proposal finished correctly,
-- and allows minting GATs for each effect script. -- and allows minting GATs for each effect script.
MintGATs MintGATs
-- | Allow effects to mutate the datum | -- | Allow effects to mutate the datum
| MutateDatum MutateDatum
deriving stock (Show, GHC.Generic) deriving stock (Show, GHC.Generic)
PlutusTx.makeIsDataIndexed PlutusTx.makeIsDataIndexed
''GovernorRedeemer ''GovernorRedeemer
[('CreateProposal,0) [ ('CreateProposal, 0)
,('MintGATs, 1) , ('MintGATs, 1)
,('MutateDatum, 2) , ('MutateDatum, 2)
] ]
-- | Parameters for creating Governor scripts. -- | Parameters for creating Governor scripts.
data Governor data Governor = Governor
= Governor { { datumNFT :: AssetClass
-- | NFT that identifies the governor datum -- ^ NFT that identifies the governor datum
datumNFT :: AssetClass
} }
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- | Plutarch-level datum for the Governor script. -- | Plutarch-level datum for the Governor script.
newtype PGovernorDatum (s :: S) = PGovernorDatum
newtype PGovernorDatum (s::S)= PGovernorDatum { getGovernorDatum :: { getGovernorDatum ::
Term s (PDataRecord '[ Term
"proposalThresholds" ':= PProposalThresholds, s
"nextProposalId" ':= PProposalId ( PDataRecord
]) '[ "proposalThresholds" ':= PProposalThresholds
} , "nextProposalId" ':= PProposalId
]
)
}
deriving stock (GHC.Generic) deriving stock (GHC.Generic)
deriving anyclass (Generic) deriving anyclass (Generic)
deriving anyclass (PIsDataRepr) deriving anyclass (PIsDataRepr)
deriving deriving
(PlutusType, PIsData, PDataFields) (PlutusType, PIsData, PDataFields)
via PIsDataReprInstances PGovernorDatum via PIsDataReprInstances PGovernorDatum
@ -110,16 +113,15 @@ instance PUnsafeLiftDecl PGovernorDatum where type PLifted PGovernorDatum = Gove
deriving via (DerivePConstantViaData GovernorDatum PGovernorDatum) instance (PConstant GovernorDatum) deriving via (DerivePConstantViaData GovernorDatum PGovernorDatum) instance (PConstant GovernorDatum)
-- | Plutarch-level version of 'GovernorRedeemer' -- | Plutarch-level version of 'GovernorRedeemer'
data PGovernorRedeemer (s :: S)
data PGovernorRedeemer (s :: S) = = PCreateProposal (Term s (PDataRecord '[]))
PCreateProposal (Term s (PDataRecord '[]))
| PMintGATs (Term s (PDataRecord '[])) | PMintGATs (Term s (PDataRecord '[]))
| PMutateDatum (Term s (PDataRecord '[])) | PMutateDatum (Term s (PDataRecord '[]))
deriving stock (GHC.Generic) deriving stock (GHC.Generic)
deriving anyclass (Generic) deriving anyclass (Generic)
deriving anyclass (PIsDataRepr) deriving anyclass (PIsDataRepr)
deriving deriving
(PlutusType, PIsData) (PlutusType, PIsData)
via PIsDataReprInstances PGovernorRedeemer via PIsDataReprInstances PGovernorRedeemer
instance PUnsafeLiftDecl PGovernorRedeemer where type PLifted PGovernorRedeemer = GovernorRedeemer instance PUnsafeLiftDecl PGovernorRedeemer where type PLifted PGovernorRedeemer = GovernorRedeemer