1
1
{-# LANGUAGE GADTs #-}
2
2
{-# LANGUAGE NumericUnderscores #-}
3
+ {-# LANGUAGE RankNTypes #-}
4
+ {-# LANGUAGE ScopedTypeVariables #-}
3
5
{-# LANGUAGE TypeApplications #-}
4
6
5
7
6
8
module Testnet.Components.SPO
7
9
( checkStakeKeyRegistered
8
- , convertToEraFlag
9
10
, createScriptStakeRegistrationCertificate
10
11
, createStakeDelegationCertificate
11
12
, createStakeKeyRegistrationCertificate
13
+ , createStakeKeyDeregistrationCertificate
12
14
, decodeEraUTxO
13
15
, registerSingleSpo
14
16
) where
@@ -115,12 +117,12 @@ createStakeDelegationCertificate
115
117
-> String -- ^ Pool id
116
118
-> FilePath
117
119
-> m ()
118
- createStakeDelegationCertificate tempAbsP anyCera delegatorStakeVerKey poolId outputFp =
120
+ createStakeDelegationCertificate tempAbsP ( AnyCardanoEra cEra) delegatorStakeVerKey poolId outputFp =
119
121
GHC. withFrozenCallStack $ do
120
122
let tempAbsPath' = unTmpAbsPath tempAbsP
121
- void $ execCli
122
- [ " stake-address " , " delegation-certificate "
123
- , convertToEraFlag anyCera
123
+ execCli_
124
+ [ eraToString cEra
125
+ , " stake-address " , " stake-delegation-certificate "
124
126
, " --stake-verification-key-file" , delegatorStakeVerKey
125
127
, " --stake-pool-id" , poolId
126
128
, " --out-file" , tempAbsPath' </> outputFp
@@ -131,44 +133,62 @@ createStakeKeyRegistrationCertificate
131
133
=> TmpAbsolutePath
132
134
-> AnyCardanoEra
133
135
-> FilePath -- ^ Stake verification key file
136
+ -> Int -- ^ deposit amount used only in Conway
134
137
-> FilePath -- ^ Output file path
135
138
-> 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
- ]
139
+ createStakeKeyRegistrationCertificate tempAbsP (AnyCardanoEra cEra) stakeVerKey deposit outputFp = GHC. withFrozenCallStack $ do
140
+ let tempAbsPath' = unTmpAbsPath tempAbsP
141
+ extraArgs = monoidForEraInEon @ ConwayEraOnwards cEra $
142
+ const [" --key-reg-deposit-amt" , show deposit]
143
+ execCli_ $
144
+ [ eraToString cEra
145
+ , " stake-address" , " registration-certificate"
146
+ , " --stake-verification-key-file" , stakeVerKey
147
+ , " --out-file" , tempAbsPath' </> outputFp
148
+ ]
149
+ <> extraArgs
146
150
147
151
createScriptStakeRegistrationCertificate
148
152
:: (MonadTest m , MonadCatch m , MonadIO m , HasCallStack )
149
153
=> TmpAbsolutePath
150
154
-> AnyCardanoEra
151
155
-> FilePath -- ^ Script file
152
- -> Int -- ^ Registration deposit amount
156
+ -> Int -- ^ Registration deposit amount used only in Conway
153
157
-> FilePath -- ^ Output file path
154
158
-> m ()
155
- createScriptStakeRegistrationCertificate tempAbsP anyCEra scriptFile deposit outputFp =
159
+ createScriptStakeRegistrationCertificate tempAbsP ( AnyCardanoEra cEra) scriptFile deposit outputFp =
156
160
GHC. withFrozenCallStack $ do
157
161
let tempAbsPath' = unTmpAbsPath tempAbsP
158
-
159
- void $ execCli
160
- [ anyEraToString anyCEra
162
+ extraArgs = monoidForEraInEon @ ConwayEraOnwards cEra $
163
+ const [" --key-reg-deposit-amt" , show deposit]
164
+ execCli_ $
165
+ [ eraToString cEra
161
166
, " stake-address" , " registration-certificate"
162
167
, " --stake-script-file" , scriptFile
163
- , " --key-reg-deposit-amt" , show deposit
164
168
, " --out-file" , tempAbsPath' </> outputFp
165
169
]
170
+ <> extraArgs
166
171
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
+ let tempAbsPath' = unTmpAbsPath tempAbsP
183
+ extraArgs = monoidForEraInEon @ ConwayEraOnwards cEra $
184
+ const [" --key-reg-deposit-amt" , show deposit]
185
+ execCli_ $
186
+ [ eraToString cEra
187
+ , " stake-address" , " deregistration-certificate"
188
+ , " --stake-verification-key-file" , stakeVerKey
189
+ , " --out-file" , tempAbsPath' </> outputFp
190
+ ]
191
+ <> extraArgs
172
192
173
193
-- | Related documentation: https://github.com/input-output-hk/cardano-node-wiki/blob/main/docs/stake-pool-operations/8_register_stakepool.md
174
194
registerSingleSpo
@@ -192,7 +212,6 @@ registerSingleSpo
192
212
registerSingleSpo identifier tap@ (TmpAbsolutePath tempAbsPath') cTestnetOptions execConfig
193
213
(fundingInput, fundingSigninKey, changeAddr) = GHC. withFrozenCallStack $ do
194
214
let testnetMag = cardanoTestnetMagic cTestnetOptions
195
- eraFlag= convertToEraFlag $ cardanoNodeEra cTestnetOptions
196
215
197
216
workDir <- H. note tempAbsPath'
198
217
@@ -251,11 +270,12 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') cTestnetOptions
251
270
252
271
-- 5. Create registration certificate
253
272
let poolRegCertFp = spoReqDir </> " registration.cert"
273
+ let era = cardanoNodeEra cTestnetOptions
254
274
255
275
-- The pledge, pool cost and pool margin can all be 0
256
276
execCli_
257
- [ " stake-pool " , " registration-certificate "
258
- , " --babbage-era "
277
+ [ anyEraToString era
278
+ , " stake-pool " , " registration-certificate "
259
279
, " --testnet-magic" , show @ Int testnetMag
260
280
, " --pool-pledge" , " 0"
261
281
, " --pool-cost" , " 0"
@@ -272,15 +292,14 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') cTestnetOptions
272
292
273
293
-- Create pledger registration certificate
274
294
275
- createStakeKeyRegistrationCertificate
276
- tap
277
- (cardanoNodeEra cTestnetOptions)
295
+ createStakeKeyRegistrationCertificate tap era
278
296
poolOwnerstakeVkeyFp
297
+ 2_000_000
279
298
(workDir </> " pledger.regcert" )
280
299
281
300
void $ execCli' execConfig
282
- [ " transaction " , " build "
283
- , eraFlag
301
+ [ anyEraToString era
302
+ , " transaction " , " build "
284
303
, " --change-address" , changeAddr
285
304
, " --tx-in" , Text. unpack $ renderTxIn fundingInput
286
305
, " --tx-out" , poolowneraddresswstakecred <> " +" <> show @ Int 5_000_000
@@ -310,7 +329,7 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') cTestnetOptions
310
329
]
311
330
-- TODO: Currently we can't propagate the error message thrown by checkStakeKeyRegistered when using byDurationM
312
331
-- Instead we wait 15 seconds
313
- threadDelay 15_000000
332
+ threadDelay 15_000_000
314
333
-- Check the pledger/owner stake key was registered
315
334
delegsAndRewards <-
316
335
checkStakeKeyRegistered
@@ -331,4 +350,3 @@ registerSingleSpo identifier tap@(TmpAbsolutePath tempAbsPath') cTestnetOptions
331
350
poolColdVkeyFp
332
351
currentRegistedPoolsJson
333
352
return (poolId, poolColdSkeyFp, poolColdVkeyFp, vrfSkeyFp, vrfVkeyFp)
334
-
0 commit comments