Skip to content

Commit

Permalink
[ADP-3212] restructure delegation certificate (#4433)
Browse files Browse the repository at this point in the history
- [x] RemoveCertRegisterKey constructor from  DelegationCertificate 


ADP-3212
  • Loading branch information
paolino authored Feb 7, 2024
2 parents 6ec2496 + f4e7af3 commit 9f3bccf
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ mkRegisterKeyCertificate
-> W.Certificate
mkRegisterKeyCertificate deposit =
W.CertificateOfDelegation deposit
. W.CertRegisterKey
. (\k -> W.CertVoteAndDelegate k Nothing Nothing)
. fromStakeCredential

mkDelegationNone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ import GHC.Generics

data DelegationCertificate
= CertDelegateNone RewardAccount
| CertRegisterKey RewardAccount
| CertVoteAndDelegate RewardAccount (Maybe PoolId) (Maybe DRep)
deriving (Generic, Show, Eq, Ord)

Expand All @@ -87,19 +86,16 @@ instance NFData DelegationCertificate
dlgCertAccount :: DelegationCertificate -> RewardAccount
dlgCertAccount = \case
CertDelegateNone acc -> acc
CertRegisterKey acc -> acc
CertVoteAndDelegate acc _ _ -> acc

dlgCertPoolId :: DelegationCertificate -> Maybe PoolId
dlgCertPoolId = \case
CertDelegateNone{} -> Nothing
CertRegisterKey _ -> Nothing
CertVoteAndDelegate _ poolIdM _ -> poolIdM

dlgCertVote :: DelegationCertificate -> Maybe DRep
dlgCertVote = \case
CertDelegateNone{} -> Nothing
CertRegisterKey _ -> Nothing
CertVoteAndDelegate _ _ voteM -> voteM

data StakeKeyCertificate
Expand Down
4 changes: 1 addition & 3 deletions lib/wallet/api/http/Cardano/Wallet/Api/Types/Certificate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ mkApiAnyCertificate acct' acctPath' = \case
else
DelegationCertificate
$ QuitPoolExternal (ApiRewardAccount rewardKey)
toApiDelCert acctM acctPath (W.CertRegisterKey rewardKey) =
toApiDelCert acctM acctPath (W.CertVoteAndDelegate rewardKey Nothing Nothing) =
if Just rewardKey == acctM then
WalletDelegationCertificate $
RegisterRewardAccount $ NE.map ApiT acctPath
Expand Down Expand Up @@ -339,8 +339,6 @@ mkApiAnyCertificate acct' acctPath' = \case
else
DelegationCertificate $
JoinPoolCastVoteExternal (ApiRewardAccount rewardKey) (ApiT poolId') (ApiT vote')
toApiDelCert _ _ (W.CertVoteAndDelegate _ Nothing Nothing) =
error "toApiDelCert: CertVoteAndDelegate should have at least pool or vote"

instance ToJSON (ApiT DRep) where
toJSON (ApiT Abstain) = "abstain"
Expand Down
7 changes: 1 addition & 6 deletions lib/wallet/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3781,13 +3781,8 @@ instance ToText WalletFollowLog where
[ "Discovered end of delegation within slot "
, pretty slotNo
]
CertRegisterKey {} -> mconcat
[ "Discovered stake key registration "
, " within slot "
, pretty slotNo
]
CertVoteAndDelegate _ mp mr -> mconcat
[ "Discovered the following voting and/or delegation: "
[ "Discovered the following registration + voting and/or delegation: "
, " within slot "
, pretty slotNo
]
Expand Down
8 changes: 1 addition & 7 deletions lib/wallet/src/Cardano/Wallet/DB/Pure/Implementation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,8 @@ mPutDelegationCertificate cert slot = alterModelNoTxs'
CertDelegateNone {} ->
Map.insert slot StakeKeyDeregistration stakeKeys
CertVoteAndDelegate _ (Just _) Nothing -> stakeKeys
CertRegisterKey {} ->
CertVoteAndDelegate {} ->
Map.insert slot StakeKeyRegistration stakeKeys
CertVoteAndDelegate _ Nothing (Just _) ->
error "Vote certificates not supported in DB"
CertVoteAndDelegate _ (Just _) (Just _) ->
error "Vote certificates not supported in DB"
CertVoteAndDelegate _ Nothing Nothing ->
error "Something wrong here"
}

mIsStakeKeyRegistered
Expand Down
3 changes: 1 addition & 2 deletions lib/wallet/src/Cardano/Wallet/DB/Store/Delegations/Layer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ putDelegationCertificate
putDelegationCertificate cert sl = case cert of
CertDelegateNone _ -> [Deregister sl]
CertVoteAndDelegate _ (Just pool) _ -> [Delegate pool sl, Register sl]
CertVoteAndDelegate _ Nothing _ -> []
CertRegisterKey _ -> [Register sl]
CertVoteAndDelegate _ Nothing _ -> [Register sl]

-- | Arguments to 'readDelegation'.
data CurrentEpochSlotting = CurrentEpochSlotting
Expand Down

0 comments on commit 9f3bccf

Please sign in to comment.