@@ -21,17 +21,19 @@ import Pos.Chain.Txp (TxpConfiguration)
21
21
import Pos.Chain.Update (BlockVersionModifier (.. ))
22
22
import Pos.Client.KeyStorage (addSecretKey , getSecretKeysPlain )
23
23
import Pos.Client.Txp.Balances (getBalance )
24
- import Pos.Core (AddrStakeDistribution (.. ), Address , StakeholderId ,
25
- addressHash , mkMultiKeyDistr , unsafeGetCoin )
24
+ import Pos.Core as Core (AddrStakeDistribution (.. ), Address ,
25
+ Config (.. ), StakeholderId , addressHash ,
26
+ configGeneratedSecretsThrow , mkMultiKeyDistr ,
27
+ unsafeGetCoin )
26
28
import Pos.Core.Common (AddrAttributes (.. ), AddrSpendingData (.. ),
27
29
makeAddress )
28
- import Pos.Core.Configuration (genesisSecretKeys )
29
30
import Pos.Core.Delegation (HeavyDlgIndex (.. ))
31
+ import Pos.Core.Genesis (gsSecretKeys )
30
32
import Pos.Core.Txp (TxOut (.. ))
31
33
import Pos.Core.Update (SoftwareVersion (.. ))
32
- import Pos.Crypto (ProtocolMagic , PublicKey , emptyPassphrase ,
33
- encToPublic , fullPublicKeyF , hashHexF , noPassEncrypt ,
34
- safeCreatePsk , unsafeCheatingHashCoerce , withSafeSigner )
34
+ import Pos.Crypto (PublicKey , emptyPassphrase , encToPublic ,
35
+ fullPublicKeyF , hashHexF , noPassEncrypt , safeCreatePsk ,
36
+ unsafeCheatingHashCoerce , withSafeSigner )
35
37
import Pos.DB.Class (MonadGState (.. ))
36
38
import Pos.Infra.Diffusion.Types (Diffusion (.. ))
37
39
import Pos.Util.UserSecret (WalletUserSecret (.. ), readUserSecret ,
@@ -64,13 +66,13 @@ import Repl (PrintAction)
64
66
65
67
createCommandProcs ::
66
68
forall m . (MonadIO m , CanLog m , HasLoggerName m )
67
- => Maybe ProtocolMagic
69
+ => Maybe Core. Config
68
70
-> Maybe TxpConfiguration
69
71
-> Maybe (Dict (MonadAuxxMode m ))
70
72
-> PrintAction m
71
73
-> Maybe (Diffusion m )
72
74
-> [CommandProc m ]
73
- createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights . fix $ \ commands -> [
75
+ createCommandProcs mCoreConfig mTxpConfig hasAuxxMode printAction mDiffusion = rights . fix $ \ commands -> [
74
76
75
77
return CommandProc
76
78
{ cpName = " L"
@@ -212,7 +214,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
212
214
},
213
215
214
216
let name = " send-to-all-genesis" in
215
- needsProtocolMagic name >>= \ pm ->
217
+ needsCoreConfig name >>= \ coreConfig ->
216
218
needsDiffusion name >>= \ diffusion ->
217
219
needsAuxxMode name >>= \ Dict ->
218
220
return CommandProc
@@ -226,7 +228,11 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
226
228
stagpTpsSentFile <- getArg tyFilePath " file"
227
229
return Tx. SendToAllGenesisParams {.. }
228
230
, cpExec = \ stagp -> do
229
- Tx. sendToAllGenesis pm diffusion stagp
231
+ secretKeys <- gsSecretKeys <$> configGeneratedSecretsThrow coreConfig
232
+ Tx. sendToAllGenesis (configProtocolMagic coreConfig)
233
+ secretKeys
234
+ diffusion
235
+ stagp
230
236
return ValueUnit
231
237
, cpHelp = " create and send transactions from all genesis addresses \
232
238
\ for <duration> seconds, <delay> in ms. <conc> is the \
@@ -247,7 +253,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
247
253
},
248
254
249
255
let name = " send" in
250
- needsProtocolMagic name >>= \ pm ->
256
+ needsCoreConfig name >>= \ coreConfig ->
251
257
needsDiffusion name >>= \ diffusion ->
252
258
needsAuxxMode name >>= \ Dict ->
253
259
return CommandProc
@@ -257,14 +263,14 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
257
263
(,) <$> getArg tyInt " i"
258
264
<*> getArgSome tyTxOut " out"
259
265
, cpExec = \ (i, outputs) -> do
260
- Tx. send pm diffusion i outputs
266
+ Tx. send (configProtocolMagic coreConfig) diffusion i outputs
261
267
return ValueUnit
262
268
, cpHelp = " send from #i to specified transaction outputs \
263
269
\ (use 'tx-out' to build them)"
264
270
},
265
271
266
272
let name = " vote" in
267
- needsProtocolMagic name >>= \ pm ->
273
+ needsCoreConfig name >>= \ coreConfig ->
268
274
needsDiffusion name >>= \ diffusion ->
269
275
needsAuxxMode name >>= \ Dict ->
270
276
return CommandProc
@@ -275,7 +281,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
275
281
<*> getArg tyBool " agree"
276
282
<*> getArg tyHash " up-id"
277
283
, cpExec = \ (i, decision, upId) -> do
278
- Update. vote pm diffusion i decision upId
284
+ Update. vote (configProtocolMagic coreConfig) diffusion i decision upId
279
285
return ValueUnit
280
286
, cpHelp = " send vote for update proposal <up-id> and \
281
287
\ decision <agree> ('true' or 'false'), \
@@ -331,7 +337,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
331
337
},
332
338
333
339
let name = " propose-update" in
334
- needsProtocolMagic name >>= \ pm ->
340
+ needsCoreConfig name >>= \ coreConfig ->
335
341
needsDiffusion name >>= \ diffusion ->
336
342
needsAuxxMode name >>= \ Dict ->
337
343
return CommandProc
@@ -353,7 +359,8 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
353
359
-- FIXME: confuses existential/universal. A better solution
354
360
-- is to have two ValueHash constructors, one with universal and
355
361
-- one with existential (relevant via singleton-style GADT) quantification.
356
- ValueHash . unsafeCheatingHashCoerce <$> Update. propose pm diffusion params
362
+ ValueHash . unsafeCheatingHashCoerce
363
+ <$> Update. propose (configProtocolMagic coreConfig) diffusion params
357
364
, cpHelp = " propose an update with one positive vote for it \
358
365
\ using secret key #i"
359
366
},
@@ -369,7 +376,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
369
376
},
370
377
371
378
let name = " delegate-heavy" in
372
- needsProtocolMagic name >>= \ pm ->
379
+ needsCoreConfig name >>= \ coreConfig ->
373
380
needsDiffusion name >>= \ diffusion ->
374
381
needsAuxxMode name >>= \ Dict ->
375
382
return CommandProc
@@ -385,7 +392,10 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
385
392
withSafeSigner issuerSk (pure emptyPassphrase) $ \ case
386
393
Nothing -> logError " Invalid passphrase"
387
394
Just ss -> do
388
- let psk = safeCreatePsk pm ss delegatePk (HeavyDlgIndex curEpoch)
395
+ let psk = safeCreatePsk (configProtocolMagic coreConfig)
396
+ ss
397
+ delegatePk
398
+ (HeavyDlgIndex curEpoch)
389
399
if dry
390
400
then do
391
401
printAction $
@@ -403,7 +413,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
403
413
},
404
414
405
415
let name = " generate-blocks" in
406
- needsProtocolMagic name >>= \ pm ->
416
+ needsCoreConfig name >>= \ coreConfig ->
407
417
needsAuxxMode name >>= \ Dict ->
408
418
needsTxpConfig name >>= \ txpConfig ->
409
419
return CommandProc
@@ -414,22 +424,23 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
414
424
bgoSeed <- getArgOpt tyInt " seed"
415
425
return GenBlocksParams {.. }
416
426
, cpExec = \ params -> do
417
- generateBlocks pm txpConfig params
427
+ generateBlocks (configProtocolMagic coreConfig) txpConfig params
418
428
return ValueUnit
419
429
, cpHelp = " generate <n> blocks"
420
430
},
421
431
422
432
let name = " add-key-pool" in
433
+ needsCoreConfig name >>= \ coreConfig ->
423
434
needsAuxxMode name >>= \ Dict ->
424
435
return CommandProc
425
436
{ cpName = name
426
437
, cpArgumentPrepare = identity
427
438
, cpArgumentConsumer = getArgMany tyInt " i"
428
439
, cpExec = \ is -> do
429
440
when (null is) $ logWarning " Not adding keys from pool (list is empty)"
430
- let secrets = fromMaybe ( error " Secret keys are unknown " ) genesisSecretKeys
441
+ secretKeys <- gsSecretKeys <$> configGeneratedSecretsThrow coreConfig
431
442
forM_ is $ \ i -> do
432
- key <- evaluateNF $ secrets !! i
443
+ key <- evaluateNF $ secretKeys !! i
433
444
addSecretKey $ noPassEncrypt key
434
445
return ValueUnit
435
446
, cpHelp = " "
@@ -458,7 +469,7 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
458
469
},
459
470
460
471
let name = " rollback" in
461
- needsProtocolMagic name >>= \ pm ->
472
+ needsCoreConfig name >>= \ coreConfig ->
462
473
needsAuxxMode name >>= \ Dict ->
463
474
return CommandProc
464
475
{ cpName = name
@@ -468,7 +479,9 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
468
479
rpDumpPath <- getArg tyFilePath " dump-file"
469
480
pure RollbackParams {.. }
470
481
, cpExec = \ RollbackParams {.. } -> do
471
- Rollback. rollbackAndDump pm rpNum rpDumpPath
482
+ Rollback. rollbackAndDump (configProtocolMagic coreConfig)
483
+ rpNum
484
+ rpDumpPath
472
485
return ValueUnit
473
486
, cpHelp = " "
474
487
},
@@ -513,18 +526,15 @@ createCommandProcs mpm mTxpConfig hasAuxxMode printAction mDiffusion = rights .
513
526
, cpHelp = " display this message"
514
527
}]
515
528
where
516
- needsAuxxMode :: Name -> Either UnavailableCommand (Dict (MonadAuxxMode m ))
517
- needsAuxxMode name =
518
- maybe (Left $ UnavailableCommand name " AuxxMode is not available" ) Right hasAuxxMode
519
- needsDiffusion :: Name -> Either UnavailableCommand (Diffusion m )
520
- needsDiffusion name =
521
- maybe (Left $ UnavailableCommand name " Diffusion layer is not available" ) Right mDiffusion
522
- needsProtocolMagic :: Name -> Either UnavailableCommand ProtocolMagic
523
- needsProtocolMagic name =
524
- maybe (Left $ UnavailableCommand name " ProtocolMagic is not available" ) Right mpm
525
- needsTxpConfig :: Name -> Either UnavailableCommand TxpConfiguration
526
- needsTxpConfig name =
527
- maybe (Left $ UnavailableCommand name " TxpConfiguration is not available" ) Right mTxpConfig
529
+ needsData :: Maybe a -> Text -> Name -> Either UnavailableCommand a
530
+ needsData mData msg name = maybe
531
+ (Left $ UnavailableCommand name (msg <> " is not available" ))
532
+ Right
533
+ mData
534
+ needsAuxxMode = needsData hasAuxxMode " AuxxMode"
535
+ needsDiffusion = needsData mDiffusion " Diffusion layer"
536
+ needsCoreConfig = needsData mCoreConfig " Core.Config"
537
+ needsTxpConfig = needsData mTxpConfig " TxpConfiguration"
528
538
529
539
procConst :: Applicative m => Name -> Value -> CommandProc m
530
540
procConst name value =
0 commit comments