Skip to content

Commit

Permalink
extend guardJoin
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Apr 23, 2024
1 parent 21ec4b9 commit 3759b16
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/wallet/src/Cardano/Wallet/Delegation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ joinStakePoolDelegationAction
(Tx.DelegationAction, Maybe Tx.VotingAction)
joinStakePoolDelegationAction
era wallet currentEpochSlotting knownPools poolId poolStatus
= case guardJoin knownPools delegation poolId retirementInfo of
= case guardJoin era knownPools delegation poolId retirementInfo of
Left e -> Left $ ErrStakePoolJoin e
Right () -> Right
( if stakeKeyIsRegistered
Expand All @@ -117,12 +117,14 @@ joinStakePoolDelegationAction
W.getPoolRetirementCertificate poolStatus

guardJoin
:: Set PoolId
:: Write.IsRecentEra era
=> Write.RecentEra era
-> Set PoolId
-> WalletDelegation
-> PoolId
-> Maybe PoolRetirementEpochInfo
-> Either ErrCannotJoin ()
guardJoin knownPools delegation pid mRetirementEpochInfo = do
guardJoin era knownPools delegation pid mRetirementEpochInfo = do
when (pid `Set.notMember` knownPools) $
Left (ErrNoSuchPool pid)

Expand All @@ -131,10 +133,18 @@ guardJoin knownPools delegation pid mRetirementEpochInfo = do
Left (ErrNoSuchPool pid)

when ((null next) && isDelegatingTo (== pid) active) $
Left (ErrAlreadyDelegating pid)
case era of
Write.RecentEraBabbage ->
Left (ErrAlreadyDelegating pid)
Write.RecentEraConway ->
pure ()

when (not (null next) && isDelegatingTo (== pid) (last next)) $
Left (ErrAlreadyDelegating pid)
case era of
Write.RecentEraBabbage ->
Left (ErrAlreadyDelegating pid)
Write.RecentEraConway ->
pure ()
where
WalletDelegation {active, next} = delegation

Expand Down

0 comments on commit 3759b16

Please sign in to comment.