From 4c770abce640903a76c4f5bad6d3140a0e60bb0b Mon Sep 17 00:00:00 2001 From: fanghr Date: Sat, 16 Apr 2022 23:04:22 +0800 Subject: [PATCH] get next proposal id from `pnextProposalId` --- agora/Agora/Governor.hs | 8 +++----- agora/Agora/Proposal.hs | 8 ++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/agora/Agora/Governor.hs b/agora/Agora/Governor.hs index 3b7cc25..17809d0 100644 --- a/agora/Agora/Governor.hs +++ b/agora/Agora/Governor.hs @@ -35,6 +35,7 @@ import Agora.Proposal ( PProposalThresholds, ProposalId, ProposalThresholds, + pnextProposalId ) import Agora.Utils ( allInputs, @@ -208,12 +209,9 @@ governorValidator params = -- check that nothing is minted passert "Nothing should be minted" $ plength # mint' #== 0 - -- check proposal id +1 - -- TODO: deriving a PNum instance for PProposalId - let oldPid = pto $ pfromData $ oldParams.nextProposalId - newPid = pto $ pfromData $ newParams.nextProposalId + -- check that proposal is advanced passert "Proposal id should be advanced by 1" $ - oldPid + 1 #== newPid + pnextProposalId # oldParams.nextProposalId #== newParams.nextProposalId -- TODO: waiting for impl of proposal ptraceError "Not implemented yet" diff --git a/agora/Agora/Proposal.hs b/agora/Agora/Proposal.hs index c5e0068..751b4c0 100644 --- a/agora/Agora/Proposal.hs +++ b/agora/Agora/Proposal.hs @@ -30,6 +30,9 @@ module Agora.Proposal ( -- * Plutarch helpers proposalDatumValid, + + -- * Utils + pnextProposalId ) where import GHC.Generics qualified as GHC @@ -434,3 +437,8 @@ proposalDatumValid proposal = , ptraceIfFalse "Proposal has fewer cosigners than the limit" $ plength # (pfromData datum.cosigners) #<= pconstant proposal.maximumCosigners , ptraceIfFalse "Proposal votes and effects are compatible with each other" $ pkeysEqual # datum.effects # pto (pfromData datum.votes) ] + +-------------------------------------------------------------------------------- + +pnextProposalId :: Term s (PProposalId :--> PProposalId) +pnextProposalId = phoistAcyclic $ plam $ \(pto -> id) -> pcon $ PProposalId $ id + 1