Skip to content

Commit

Permalink
Add ConwayUpdateDRep constructor to ConwayTxCertGov type
Browse files Browse the repository at this point in the history
and corresponding pattern `UpdateDRepTxCert`
  • Loading branch information
teodanciu committed Aug 1, 2023
1 parent 17587cf commit a3ed8fc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions eras/conway/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* `ConwayTxCertCommittee` -> `ConwayTxCertGov`
* Remove `DelegStakeTxCert` from the `COMPLETE` pragma for `TxCert`
* Add `Committee` and adjust `NewCommittee` governance action
* Add `ConwayUpdateDRep` constructor to `ConwayGovCert` type and corresponding pattern `UnRegDRepTxCert`

## 1.6.3.0

Expand Down
3 changes: 3 additions & 0 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Rules/GovCert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ conwayGovCertTransition = do
ConwayResignCommitteeColdKey coldK -> do
checkColdKeyHasNotResigned coldK vsCommitteeHotKeys
pure $ vState {vsCommitteeHotKeys = Map.insert coldK Nothing vsCommitteeHotKeys}
ConwayUpdateDRep cred _mAnchor -> do
Set.notMember cred vsDReps ?! ConwayDRepNotRegistered cred
pure vState -- TODO: update anchor
where
checkColdKeyHasNotResigned coldK vsCommitteeHotKeys =
((isNothing <$> Map.lookup coldK vsCommitteeHotKeys) /= Just True)
Expand Down
37 changes: 34 additions & 3 deletions eras/conway/impl/src/Cardano/Ledger/Conway/TxCert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module Cardano.Ledger.Conway.TxCert (
pattern ResignCommitteeColdTxCert,
pattern RegDRepTxCert,
pattern UnRegDRepTxCert,
pattern UpdateDRepTxCert,
)
where

Expand Down Expand Up @@ -153,6 +154,9 @@ class ShelleyEraTxCert era => ConwayEraTxCert era where
mkUnRegDRepTxCert :: Credential 'DRepRole (EraCrypto era) -> Coin -> TxCert era
getUnRegDRepTxCert :: TxCert era -> Maybe (Credential 'DRepRole (EraCrypto era), Coin)

mkUpdateDRepTxCert :: Credential 'DRepRole (EraCrypto era) -> StrictMaybe (Anchor (EraCrypto era)) -> TxCert era
getUpdateDRepTxCert :: TxCert era -> Maybe (Credential 'DRepRole (EraCrypto era), StrictMaybe (Anchor (EraCrypto era)))

instance Crypto c => ConwayEraTxCert (ConwayEra c) where
mkRegDepositTxCert cred c = ConwayTxCertDeleg $ ConwayRegCert cred $ SJust c

Expand Down Expand Up @@ -189,6 +193,11 @@ instance Crypto c => ConwayEraTxCert (ConwayEra c) where
ConwayTxCertGov (ConwayUnRegDRep cred deposit) -> Just (cred, deposit)
_ -> Nothing

mkUpdateDRepTxCert cred mAnchor = ConwayTxCertGov $ ConwayUpdateDRep cred mAnchor
getUpdateDRepTxCert = \case
ConwayTxCertGov (ConwayUpdateDRep cred mAnchor) -> Just (cred, mAnchor)
_ -> Nothing

pattern RegDepositTxCert ::
ConwayEraTxCert era =>
StakeCredential (EraCrypto era) ->
Expand Down Expand Up @@ -262,6 +271,15 @@ pattern UnRegDRepTxCert cred deposit <- (getUnRegDRepTxCert -> Just (cred, depos
where
UnRegDRepTxCert cred deposit = mkUnRegDRepTxCert cred deposit

pattern UpdateDRepTxCert ::
ConwayEraTxCert era =>
Credential 'DRepRole (EraCrypto era) ->
StrictMaybe (Anchor (EraCrypto era)) ->
TxCert era
pattern UpdateDRepTxCert cred mAnchor <- (getUpdateDRepTxCert -> Just (cred, mAnchor))
where
UpdateDRepTxCert cred mAnchor = mkUpdateDRepTxCert cred mAnchor

{-# COMPLETE
RegPoolTxCert
, RetirePoolTxCert
Expand All @@ -275,6 +293,7 @@ pattern UnRegDRepTxCert cred deposit <- (getUnRegDRepTxCert -> Just (cred, depos
, ResignCommitteeColdTxCert
, RegDRepTxCert
, UnRegDRepTxCert
, UpdateDRepTxCert
#-}

-- | First type argument is the deposit
Expand Down Expand Up @@ -321,6 +340,7 @@ instance NoThunks (ConwayDelegCert c)
data ConwayGovCert c
= ConwayRegDRep !(Credential 'DRepRole c) !Coin !(StrictMaybe (Anchor c))
| ConwayUnRegDRep !(Credential 'DRepRole c) !Coin
| ConwayUpdateDRep !(Credential 'DRepRole c) !(StrictMaybe (Anchor c))
| ConwayAuthCommitteeHotKey !(Credential 'ColdCommitteeRole c) !(Credential 'HotCommitteeRole c)
| ConwayResignCommitteeColdKey !(Credential 'ColdCommitteeRole c)
deriving (Show, Generic, Eq)
Expand Down Expand Up @@ -393,6 +413,10 @@ conwayTxCertDelegDecoder = \case
cred <- decCBOR
deposit <- decCBOR
pure (3, UnRegDRepTxCert cred deposit)
18 -> do
cred <- decCBOR
mAnchor <- decodeNullStrictMaybe decCBOR
pure (3, UpdateDRepTxCert cred mAnchor)
k -> invalidKey k
where
delegCertDecoder n decodeDelegatee = do
Expand All @@ -415,7 +439,7 @@ instance (Era era, Val (Value era)) => EncCBOR (ConwayTxCert era) where
encCBOR = \case
ConwayTxCertDeleg delegCert -> encodeConwayDelegCert delegCert
ConwayTxCertPool poolCert -> encodePoolCert poolCert
ConwayTxCertGov committeeCert -> encodeCommitteeHotKey committeeCert
ConwayTxCertGov govCert -> encodeGovCert govCert

encodeConwayDelegCert :: Crypto c => ConwayDelegCert c -> Encoding
encodeConwayDelegCert = \case
Expand Down Expand Up @@ -465,8 +489,8 @@ encodeConwayDelegCert = \case
<> encCBOR dRep
<> encCBOR deposit

encodeCommitteeHotKey :: Crypto c => ConwayGovCert c -> Encoding
encodeCommitteeHotKey = \case
encodeGovCert :: Crypto c => ConwayGovCert c -> Encoding
encodeGovCert = \case
ConwayAuthCommitteeHotKey cred key ->
encodeListLen 3
<> encodeWord8 14
Expand All @@ -487,6 +511,11 @@ encodeCommitteeHotKey = \case
<> encodeWord8 17
<> encCBOR cred
<> encCBOR deposit
ConwayUpdateDRep cred mAnchor ->
encodeListLen 3
<> encodeWord8 18
<> encCBOR cred
<> encodeNullStrictMaybe encCBOR mAnchor

fromShelleyDelegCert :: ShelleyDelegCert c -> ConwayDelegCert c
fromShelleyDelegCert = \case
Expand Down Expand Up @@ -529,6 +558,7 @@ getScriptWitnessConwayTxCert = \case
-- Registration of a DRep does not require a witness
ConwayRegDRep {} -> Nothing
ConwayUnRegDRep cred _ -> credScriptHash cred
ConwayUpdateDRep cred _ -> credScriptHash cred

getVKeyWitnessConwayTxCert :: ConwayTxCert era -> Maybe (KeyHash 'Witness (EraCrypto era))
getVKeyWitnessConwayTxCert = \case
Expand All @@ -549,3 +579,4 @@ getVKeyWitnessConwayTxCert = \case
-- Registration of a DRep does not require a witness
ConwayRegDRep {} -> Nothing
ConwayUnRegDRep cred _ -> credKeyHashWitness cred
ConwayUpdateDRep cred _ -> credKeyHashWitness cred
2 changes: 2 additions & 0 deletions eras/conway/test-suite/cddl-files/conway.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ certificate =
// unreg_committee_hot_key_cert
// reg_drep_cert
// unreg_drep_cert
// update_drep_cert
]

stake_registration = (0, stake_credential)
Expand Down Expand Up @@ -309,6 +310,7 @@ reg_committee_hot_key_cert = (14, committee_cold_keyhash, committee_hot_keyhash)
unreg_committee_hot_key_cert = (15, committee_cold_keyhash)
reg_drep_cert = (16, voting_credential, coin, anchor / null)
unreg_drep_cert = (17, voting_credential, coin)
update_drep_cert = (18, voting_credential, anchor / null)


delta_coin = int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ ppConwayGovCert = \case
ppSexp "ConwayRegDRep" [prettyA cred, prettyA deposit, prettyA mAnchor]
ConwayUnRegDRep cred deposit ->
ppSexp "ConwayUnRegDRep" [prettyA cred, prettyA deposit]
ConwayUpdateDRep cred mAnchor ->
ppSexp "ConwayUpdateDRep" [prettyA cred, prettyA mAnchor]
ConwayAuthCommitteeHotKey coldKey hotKey ->
ppSexp "ConwayAuthCommitteeHotKey" [prettyA coldKey, prettyA hotKey]
ConwayResignCommitteeColdKey coldKey ->
Expand Down

0 comments on commit a3ed8fc

Please sign in to comment.