11{-# LANGUAGE GADTs #-}
22{-# LANGUAGE NumericUnderscores #-}
3+ {-# LANGUAGE RankNTypes #-}
34{-# LANGUAGE TypeApplications #-}
45
56
67module Testnet.Components.SPO
78 ( checkStakeKeyRegistered
8- , convertToEraFlag
99 , createScriptStakeRegistrationCertificate
1010 , createStakeDelegationCertificate
1111 , createStakeKeyRegistrationCertificate
12+ , createStakeKeyDeregistrationCertificate
1213 , decodeEraUTxO
1314 , registerSingleSpo
1415 ) where
@@ -22,7 +23,7 @@ import qualified Data.Map.Strict as Map
2223import Data.Set (Set )
2324import qualified Data.Set as Set
2425import qualified Data.Text as Text
25- import GHC.Stack (HasCallStack )
26+ import GHC.Stack (HasCallStack , withFrozenCallStack )
2627import qualified GHC.Stack as GHC
2728import System.FilePath.Posix ((</>) )
2829
@@ -118,9 +119,9 @@ createStakeDelegationCertificate
118119createStakeDelegationCertificate tempAbsP anyCera delegatorStakeVerKey poolId outputFp =
119120 GHC. withFrozenCallStack $ do
120121 let tempAbsPath' = unTmpAbsPath tempAbsP
121- void $ execCli
122- [ " stake-address " , " delegation-certificate "
123- , convertToEraFlag anyCera
122+ execCli_
123+ [ anyEraToString anyCera
124+ , " stake-address " , " delegation-certificate "
124125 , " --stake-verification-key-file" , delegatorStakeVerKey
125126 , " --stake-pool-id" , poolId
126127 , " --out-file" , tempAbsPath' </> outputFp
@@ -131,18 +132,23 @@ createStakeKeyRegistrationCertificate
131132 => TmpAbsolutePath
132133 -> AnyCardanoEra
133134 -> FilePath -- ^ Stake verification key file
135+ -> Int -- ^ deposit amount used only in Conway
134136 -> FilePath -- ^ Output file path
135137 -> m ()
136- createStakeKeyRegistrationCertificate tempAbsP anyCEra stakeVerKey outputFp =
137- GHC. withFrozenCallStack $ do
138- let tempAbsPath' = unTmpAbsPath tempAbsP
139-
140- void $ execCli
141- [ " stake-address" , " registration-certificate"
142- , convertToEraFlag anyCEra
143- , " --stake-verification-key-file" , stakeVerKey
144- , " --out-file" , tempAbsPath' </> outputFp
145- ]
138+ createStakeKeyRegistrationCertificate tempAbsP (AnyCardanoEra cEra) stakeVerKey deposit outputFp = GHC. withFrozenCallStack $ do
139+ sbe <- requireEon ShelleyEra cEra
140+ let tempAbsPath' = unTmpAbsPath tempAbsP
141+ extraArgs = caseShelleyToBabbageOrConwayEraOnwards
142+ (const [] )
143+ (const [" --key-reg-deposit-amt" , show deposit])
144+ sbe
145+ execCli_ $
146+ [ eraToString cEra
147+ , " stake-address" , " registration-certificate"
148+ , " --stake-verification-key-file" , stakeVerKey
149+ , " --out-file" , tempAbsPath' </> outputFp
150+ ]
151+ <> extraArgs
146152
147153createScriptStakeRegistrationCertificate
148154 :: (MonadTest m , MonadCatch m , MonadIO m , HasCallStack )
@@ -155,20 +161,39 @@ createScriptStakeRegistrationCertificate
155161createScriptStakeRegistrationCertificate tempAbsP anyCEra scriptFile deposit outputFp =
156162 GHC. withFrozenCallStack $ do
157163 let tempAbsPath' = unTmpAbsPath tempAbsP
158-
159- void $ execCli
164+ execCli_
160165 [ anyEraToString anyCEra
161166 , " stake-address" , " registration-certificate"
162167 , " --stake-script-file" , scriptFile
163168 , " --key-reg-deposit-amt" , show deposit
164169 , " --out-file" , tempAbsPath' </> outputFp
165170 ]
166171
167-
168- -- TODO: Remove me and replace with new era based commands
169- -- i.e "conway", "babbage" etc
170- convertToEraFlag :: AnyCardanoEra -> String
171- convertToEraFlag era = " --" <> anyEraToString era <> " -era"
172+ createStakeKeyDeregistrationCertificate
173+ :: (MonadTest m , MonadCatch m , MonadIO m , HasCallStack )
174+ => TmpAbsolutePath
175+ -> AnyCardanoEra
176+ -> FilePath -- ^ Stake verification key file
177+ -> Int -- ^ deposit amount used only in Conway
178+ -> FilePath -- ^ Output file path
179+ -> m ()
180+ createStakeKeyDeregistrationCertificate tempAbsP (AnyCardanoEra cEra) stakeVerKey deposit outputFp =
181+ GHC. withFrozenCallStack $ do
182+ sbe <- requireEon ShelleyEra cEra
183+ let tempAbsPath' = unTmpAbsPath tempAbsP
184+ extraArgs = caseShelleyToBabbageOrConwayEraOnwards
185+ (const [] )
186+ (const [" --key-reg-deposit-amt" , show deposit])
187+ sbe
188+
189+ execCli_ $
190+ [ eraToString cEra
191+ , " stake-address"
192+ , " deregistration-certificate"
193+ , " --stake-verification-key-file" , stakeVerKey
194+ , " --out-file" , tempAbsPath' </> outputFp
195+ ]
196+ <> extraArgs
172197
173198-- | Related documentation: https://github.com/input-output-hk/cardano-node-wiki/blob/main/docs/stake-pool-operations/8_register_stakepool.md
174199registerSingleSpo
@@ -192,7 +217,6 @@ registerSingleSpo
192217registerSingleSpo identifier tap@ (TmpAbsolutePath tempAbsPath') cTestnetOptions execConfig
193218 (fundingInput, fundingSigninKey, changeAddr) = GHC. withFrozenCallStack $ do
194219 let testnetMag = cardanoTestnetMagic cTestnetOptions
195- eraFlag= convertToEraFlag $ cardanoNodeEra cTestnetOptions
196220
197221 workDir <- H. note tempAbsPath'
198222
@@ -251,11 +275,12 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') cTestnetOptions
251275
252276 -- 5. Create registration certificate
253277 let poolRegCertFp = spoReqDir </> " registration.cert"
278+ let era = cardanoNodeEra cTestnetOptions
254279
255280 -- The pledge, pool cost and pool margin can all be 0
256281 execCli_
257- [ " stake-pool " , " registration-certificate "
258- , " --babbage-era "
282+ [ anyEraToString era
283+ , " stake-pool " , " registration-certificate "
259284 , " --testnet-magic" , show @ Int testnetMag
260285 , " --pool-pledge" , " 0"
261286 , " --pool-cost" , " 0"
@@ -272,15 +297,14 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') cTestnetOptions
272297
273298 -- Create pledger registration certificate
274299
275- createStakeKeyRegistrationCertificate
276- tap
277- (cardanoNodeEra cTestnetOptions)
300+ createStakeKeyRegistrationCertificate tap era
278301 poolOwnerstakeVkeyFp
302+ 2_000_000
279303 (workDir </> " pledger.regcert" )
280304
281305 void $ execCli' execConfig
282- [ " transaction " , " build "
283- , eraFlag
306+ [ anyEraToString era
307+ , " transaction " , " build "
284308 , " --change-address" , changeAddr
285309 , " --tx-in" , Text. unpack $ renderTxIn fundingInput
286310 , " --tx-out" , poolowneraddresswstakecred <> " +" <> show @ Int 5_000_000
@@ -332,3 +356,17 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') cTestnetOptions
332356 currentRegistedPoolsJson
333357 return (poolId, poolColdSkeyFp, poolColdVkeyFp, vrfSkeyFp, vrfVkeyFp)
334358
359+
360+ requireEon :: forall eon era minEra m . Eon eon
361+ => MonadTest m
362+ => CardanoEra minEra -- ^ minimal required era i.e. for 'ConwayEraOnwards' eon it's 'Conway'
363+ -> CardanoEra era -- ^ node era
364+ -> m (eon era )
365+ -- TODO: implement 'Bounded' for `Some eon` and remove 'minEra'
366+ requireEon minEra era = withFrozenCallStack $
367+ maybe
368+ (H. note_ errorMessage >> failure)
369+ pure
370+ (forEraMaybeEon era)
371+ where
372+ errorMessage = " Required at least " <> eraToString minEra <> " . Tried to execute in " <> eraToString era <> " ."
0 commit comments