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