apply Emily's suggestions

* Comment on `validateOutputLocks`
* Assertion message rewording
* Some comment rewording
* Fix Typos
* Correct `PShow` instances, derive as much we can
* Remove redundant checks
This commit is contained in:
Hongrui Fang 2022-07-13 01:47:15 +08:00
parent 3c35e610a5
commit 0b55cefd3b
6 changed files with 63 additions and 66 deletions

View file

@ -74,7 +74,8 @@ data GovernorDatum = GovernorDatum
, createProposalTimeRangeMaxWidth :: MaxTimeRangeWidth
-- ^ The maximum valid duration of a transaction that creats a proposal.
, maximumProposalsPerStake :: Integer
-- ^ The maximum number of *alive* proposals which were careated by a stake.
-- ^ The maximum number of unfinished proposals that a stake is allowed to be
-- associated to.
}
deriving stock (Show, GHC.Generic)

View file

@ -378,7 +378,7 @@ governorValidator gov =
stakeInputDatumF <-
pletFieldsC @["stakedAmount", "owner", "lockedBy"] stakeInputDatum
pguardC "Didn't created too many proposals" $
pguardC "Proposals created by the stake must not exceed the number stored in the governor." $
pnumCreatedProposals # stakeInputDatumF.lockedBy
#< oldGovernorDatumF.maximumProposalsPerStake

View file

@ -409,6 +409,8 @@ newtype PResultTag (s :: S) = PResultTag (Term s PInteger)
PEq
, -- | @since 0.1.0
POrd
, -- | @since 0.2.0
PShow
)
via (DerivePNewtype PResultTag PInteger)
@ -427,11 +429,6 @@ deriving via
instance
PTryFrom PData (PAsData PResultTag)
-- | @since 0.2.0
instance PShow PResultTag where
pshow' :: Bool -> Term s PResultTag -> Term s PString
pshow' _ x = pshow @PInteger $ pto x
{- | Plutarch-level version of 'PProposalId'.
@since 0.1.0
@ -446,6 +443,8 @@ newtype PProposalId (s :: S) = PProposalId (Term s PInteger)
PEq
, -- | @since 0.1.0
POrd
, -- | @since 0.2.0
PShow
)
via (DerivePNewtype PProposalId PInteger)
@ -464,11 +463,6 @@ deriving via
instance
(PConstantDecl ProposalId)
-- | @since 0.2.0
instance PShow PProposalId where
pshow' :: Bool -> Term s PProposalId -> Term s PString
pshow' _ x = pshow @PInteger $ pto x
{- | Plutarch-level version of 'ProposalStatus'.
@since 0.1.0

View file

@ -533,10 +533,6 @@ proposalValidator proposal =
----------------------------------------------------------------------
PUnlock _ -> withSingleStake $ \stakeInF stakeOut _ -> do
-- At draft stage, the votes should be empty.
pguardC "Shouldn't retract votes from a draft proposal" $
pnot #$ currentStatus #== pconstant Draft
stakeRole <- pletC $ pgetStakeRole # proposalF.proposalId # stakeInF.lockedBy
pguardC "Stake input should be relevant" $
@ -556,6 +552,12 @@ proposalValidator proposal =
isCreator = pisCreator # stakeRole
-- If the stake has been used for creating the proposal,
-- the creator lock can only be removed when the proposal
-- is finished.
--
-- In other cases, all the locks related to this
-- proposal should be removed.
validateOutputLocks = plam $ \locks ->
plet
( pgetStakeRole # proposalF.proposalId # locks

View file

@ -371,11 +371,11 @@ deriving via
-- | @since 0.2.0
instance PShow PProposalLock where
pshow' :: Bool -> Term s PProposalLock -> Term s PString
pshow' True _ = "(..)"
pshow' True x = "(" <> pshow' False x <> ")"
pshow' False lock = pmatch lock $ \case
PCreated ((pfield @"created" #) -> pid) -> "Created " <> pshow pid
PCreated ((pfield @"created" #) -> pid) -> "PCreated " <> pshow' True pid
PVoted x -> pletFields @'["votedOn", "votedFor"] x $ \xF ->
"Voted on " <> pshow xF.votedOn <> " for " <> pshow xF.votedFor
"PVoted " <> pshow' True xF.votedOn <> " " <> pshow' True xF.votedFor
--------------------------------------------------------------------------------