Skip to content

Commit

Permalink
create-testnet-data: correctly compute set of credentials delegating …
Browse files Browse the repository at this point in the history
…votes to a drep in conway genesis
  • Loading branch information
smelc committed Oct 17, 2024
1 parent 235cb3e commit 1a46427
Showing 1 changed file with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}

{- HLINT ignore "Use zipWith" -}

module Cardano.CLI.EraBased.Run.Genesis.CreateTestnetData
( runGenesisKeyGenUTxOCmd
, runGenesisKeyGenGenesisCmd
Expand Down Expand Up @@ -338,40 +340,41 @@ runGenesisCreateTestNetDataCmd

addDRepsToConwayGenesis
:: [VerificationKey DRepKey]
-- \^ The credential of the DReps
-> [VerificationKey StakeKey]
-- \^ The credentials of those that delegate their votes to the dreps. It happens
-- to only be stake keys now, but it could be more general in the future.
-> L.ConwayGenesis L.StandardCrypto
-- \^ The genesis data to amend
-> L.ConwayGenesis L.StandardCrypto
addDRepsToConwayGenesis dRepKeys stakingKeys conwayGenesis =
conwayGenesis
{ L.cgDelegs = delegs (zip stakingKeys (case dRepKeys of [] -> []; _ -> cycle dRepKeys))
, L.cgInitialDReps = initialDReps (L.ucppDRepDeposit $ L.cgUpgradePParams conwayGenesis) dRepKeys
}
conwayGenesis{L.cgDelegs, L.cgInitialDReps}
where
delegs
:: [(VerificationKey StakeKey, VerificationKey DRepKey)]
-> ListMap (L.Credential L.Staking L.StandardCrypto) (L.Delegatee L.StandardCrypto)
-- The credential, to the drep it delegates to
delegs :: [(L.Credential L.Staking L.StandardCrypto, VerificationKey DRepKey)]
delegs =
fromList
. map
( bimap
verificationKeytoStakeCredential
(L.DelegVote . L.DRepCredential . verificationKeyToDRepCredential)
)
map
(first verificationKeytoStakeCredential)
(zip stakingKeys (case dRepKeys of [] -> []; _ -> cycle dRepKeys))

minDeposit = L.ucppDRepDeposit $ L.cgUpgradePParams conwayGenesis
cgDelegs = fromList $ map (second (L.DelegVote . L.DRepCredential . verificationKeyToDRepCredential)) delegs
cgInitialDReps = initialDReps $ map (\(stakingCred, drep) -> (drep, Set.singleton stakingCred)) delegs

initialDReps
:: Lovelace
-> [VerificationKey DRepKey]
:: [(VerificationKey DRepKey, Set.Set (L.Credential L.Staking L.StandardCrypto))]
-- \^ The initial DReps and the credentials of those that delegate their votes to them
-> ListMap (L.Credential L.DRepRole L.StandardCrypto) (L.DRepState L.StandardCrypto)
initialDReps minDeposit =
initialDReps =
fromList
. map
( \c ->
( verificationKeyToDRepCredential c
( \(drep, drepDelegs) ->
( verificationKeyToDRepCredential drep
, L.DRepState
{ L.drepExpiry = EpochNo 1_000
, L.drepAnchor = SNothing
, L.drepDeposit = max (L.Coin 1_000_000) minDeposit
, L.drepDelegs = Set.empty
, L.drepDelegs
}
)
)
Expand Down

0 comments on commit 1a46427

Please sign in to comment.