Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 539171e

Browse files
authored
[GH-235] Fixing nested configuration problems (#236)
* [GH-235] Fixing nested configuration problems. * [GH-235] Fixing review suggestions, cleaner solution.
1 parent cc194cd commit 539171e

File tree

7 files changed

+198
-241
lines changed

7 files changed

+198
-241
lines changed

app/Cardano/Shell/Features/Networking.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Cardano.Shell.Types (CardanoEnvironment, CardanoFeature (..),
1313
CardanoFeatureInit (..))
1414

1515
import Cardano.Shell.Constants.Types (CardanoConfiguration (..),
16-
Core (..))
16+
Core (..), Wallet (..))
1717
--------------------------------------------------------------------------------
1818
-- Networking feature
1919
--------------------------------------------------------------------------------
@@ -76,7 +76,8 @@ createNetworkingFeature loggingLayer cardanoEnvironment cardanoConfiguration = d
7676
-- the filesystem, so we give him the most flexible/powerful context, @IO@.
7777
networkingConfiguration <- pure "THIS IS AN EXAMPLE OF A CONFIGURATION!"
7878

79-
putTextLn $ "The DB version" <> (show $ coDBSerializeVersion $ ccCore cardanoConfiguration)
79+
putTextLn $ "The DB version - " <> (show $ coDBSerializeVersion $ ccCore cardanoConfiguration)
80+
putTextLn $ "The Wallet Throttle - " <> (show $ thRate $ ccWallet cardanoConfiguration)
8081

8182
-- we construct the layer
8283
networkingLayer <- (featureInit networkingCardanoFeatureInit) cardanoEnvironment loggingLayer cardanoConfiguration networkingConfiguration

app/Main.hs

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ import Cardano.Shell.Features.Logging (LoggingCLIArguments,
1111
import Cardano.Shell.Features.Networking (createNetworkingFeature)
1212

1313
import Cardano.Shell.Configuration.Lib (finaliseCardanoConfiguration)
14-
import Cardano.Shell.Constants.CLI (configCoreCLIParser)
15-
import Cardano.Shell.Constants.PartialTypes (PartialCardanoConfiguration (..),
16-
PartialCore (..))
14+
import Cardano.Shell.Constants.CLI (configBlockCLIParser,
15+
configCoreCLIParser,
16+
configWalletCLIParser)
17+
import Cardano.Shell.Constants.PartialTypes (PartialBlock (..), PartialCardanoConfiguration (..),
18+
PartialCore (..),
19+
PartialWallet (..))
1720
import Cardano.Shell.Lib
1821
import Cardano.Shell.Presets (mainnetConfiguration)
1922
import Cardano.Shell.Types
@@ -23,7 +26,11 @@ import Options.Applicative
2326

2427
-- | The product type of all command line arguments.
2528
-- All here being - from all the features.
26-
data CLIArguments = CLIArguments !LoggingCLIArguments !PartialCore
29+
data CLIArguments = CLIArguments
30+
!LoggingCLIArguments
31+
!PartialWallet
32+
!PartialBlock
33+
!PartialCore
2734

2835
main :: IO ()
2936
main = do
@@ -87,10 +94,49 @@ initializeAllFeatures :: PartialCardanoConfiguration -> CardanoEnvironment -> IO
8794
initializeAllFeatures partialConfig cardanoEnvironment = do
8895

8996
-- Here we parse the __CLI__ arguments for the actual application.
90-
CLIArguments loggingCLIArguments coreCLI <- execParser parserWithInfo
97+
CLIArguments loggingCLIArguments walletCLI blockCLI coreCLI <- execParser parserWithInfo
98+
99+
let configCore = pccCore partialConfig
100+
let configBlock = pccBlock partialConfig
101+
let configWallet = pccWallet partialConfig
102+
103+
let pccCore' = configCore <> coreCLI
104+
let pccBlock' = configBlock <> blockCLI
105+
let pccWallet' = configWallet <> walletCLI
106+
107+
putTextLn "************************************************"
108+
putTextLn "CORE"
109+
putTextLn "************************************************"
110+
putTextLn $ show configCore
111+
putTextLn "------------------------------------------------"
112+
putTextLn $ show coreCLI
113+
putTextLn "------------------------------------------------"
114+
putTextLn $ show pccCore'
115+
116+
putTextLn "************************************************"
117+
putTextLn "BLOCK"
118+
putTextLn "************************************************"
119+
putTextLn $ show configBlock
120+
putTextLn "------------------------------------------------"
121+
putTextLn $ show blockCLI
122+
putTextLn "------------------------------------------------"
123+
putTextLn $ show pccBlock'
124+
125+
putTextLn "************************************************"
126+
putTextLn "WALLET"
127+
putTextLn "************************************************"
128+
putTextLn $ show configWallet
129+
putTextLn "------------------------------------------------"
130+
putTextLn $ show walletCLI
131+
putTextLn "------------------------------------------------"
132+
putTextLn $ show pccWallet'
91133

92134
finalConfig <- either (throwIO . ConfigurationError) pure $
93-
finaliseCardanoConfiguration $ partialConfig { pccCore = pccCore partialConfig <> pure coreCLI }
135+
finaliseCardanoConfiguration $ partialConfig
136+
{ pccCore = pccCore'
137+
, pccBlock = pccBlock'
138+
, pccWallet = pccWallet'
139+
}
94140

95141
-- Here we initialize all the features
96142
(loggingLayer, loggingFeature) <- createLoggingFeature cardanoEnvironment finalConfig loggingCLIArguments
@@ -118,4 +164,7 @@ initializeAllFeatures partialConfig cardanoEnvironment = do
118164
commandLineParser :: Parser CLIArguments
119165
commandLineParser = CLIArguments
120166
<$> loggingParser
167+
<*> configWalletCLIParser
168+
<*> configBlockCLIParser
121169
<*> configCoreCLIParser
170+

src/Cardano/Shell/Configuration/Lib.hs

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
module Cardano.Shell.Configuration.Lib
44
( finaliseCardanoConfiguration
55
, finaliseCore
6-
, finaliseGenesis
76
, mkLauncher
87
, mkTopology
98
, mkOSConfig
@@ -32,18 +31,13 @@ import Cardano.Shell.Configuration.Types (BlockchainConfig,
3231
import Cardano.Shell.Constants.PartialTypes (PartialBlock (..), PartialCardanoConfiguration (..),
3332
PartialCertificate (..),
3433
PartialCore (..),
35-
PartialGenesis (..),
3634
PartialNode (..),
37-
PartialStaticKeyMaterial (..),
3835
PartialTLS (..),
39-
PartialThrottle (..),
4036
PartialWallet (..))
4137
import Cardano.Shell.Constants.Types (Block (..),
4238
CardanoConfiguration (..),
4339
Certificate (..), Core (..),
44-
Genesis (..), Node (..),
45-
StaticKeyMaterial (..),
46-
TLS (..), Throttle (..),
40+
Node (..), TLS (..),
4741
Wallet (..))
4842

4943
-- | Converting a @Last@ to an @Either@
@@ -64,52 +58,35 @@ finaliseCardanoConfiguration PartialCardanoConfiguration{..} = do
6458
ccDBPath <- lastToEither "Unspecified ccDBPath" pccDBPath
6559
ccApplicationLockFile <- lastToEither "Unspecified ccApplicationLockFile"
6660
pccApplicationLockFile
67-
ccCore <- join $ finaliseCore <$>
68-
lastToEither "Unspecified ccCore" pccCore
61+
ccCore <- finaliseCore pccCore
6962
ccNTP <- lastToEither "Unspecified ccNTP" pccNTP
7063
ccUpdate <- lastToEither "Unspecified ccUpdate" pccUpdate
7164
ccTXP <- lastToEither "Unspecified ccTXP" pccTXP
7265
ccSSC <- lastToEither "Unspecified ccSSC" pccSSC
7366
ccDLG <- lastToEither "Unspecified ccDLG" pccDLG
74-
ccBlock <- join $ finaliseBlock <$>
75-
lastToEither "Unspecified ccBlock" pccBlock
67+
ccBlock <- finaliseBlock pccBlock
7668
ccNode <- join $ finaliseNode <$>
7769
lastToEither "Unspecified ccNode" pccNode
7870
ccTLS <- join $ finaliseTLS <$>
7971
lastToEither "Unspecified ccTLS" pccTLS
80-
ccWallet <- join $ finaliseWallet <$>
81-
lastToEither "Unspecified ccWallet" pccWallet
72+
ccWallet <- finaliseWallet pccWallet
8273

8374
pure CardanoConfiguration{..}
8475

8576
-- | Finalize the @PartialCore@, convert to @Core@.
8677
finaliseCore :: PartialCore -> Either Text Core
8778
finaliseCore PartialCore{..} = do
88-
coGenesis <- join $ finaliseGenesis <$>
89-
lastToEither "Unspecified coGenesis" pcoGenesis
90-
coStaticKeyMaterial <- join $ finaliseStaticKeyMaterial <$>
91-
lastToEither "Unspecified coStaticKeyMaterial" pcoStaticKeyMaterial
92-
coRequiresNetworkMagic <- lastToEither "Unspecified coRequiresNetworkMagic" pcoRequiresNetworkMagic
93-
coDBSerializeVersion <- lastToEither "Unspecified coDBSerializeVersion" pcoDBSerializeVersion
9479

95-
pure Core{..}
96-
97-
-- | Finalize the @PartialGenesis@, convert to @Genesis@.
98-
finaliseGenesis :: PartialGenesis -> Either Text Genesis
99-
finaliseGenesis PartialGenesis{..} = do
100-
101-
geSrc <- lastToEither "Unspecified geSrc" pgeSrc
102-
geGenesisHash <- lastToEither "Unspecified geGenesisHash" pgeGenesisHash
103-
104-
pure Genesis{..}
80+
coGenesisFile <- lastToEither "Unspecified coGenesisFile" pcoGenesisFile
81+
coGenesisHash <- lastToEither "Unspecified coGenesisHash" pcoGenesisHash
10582

106-
finaliseStaticKeyMaterial :: PartialStaticKeyMaterial -> Either Text StaticKeyMaterial
107-
finaliseStaticKeyMaterial PartialStaticKeyMaterial{..} = do
83+
coStaticKeySigningKeyFile <- lastToEither "Unspecified coStaticKeySigningKeyFile" pcoStaticKeySigningKeyFile
84+
coStaticKeyDlgCertFile <- lastToEither "Unspecified coStaticKeyDlgCertFile" pcoStaticKeyDlgCertFile
10885

109-
skmSigningKeyFile <- lastToEither "Unspecified skmSigningKeyFile" pskmSigningKeyFile
110-
skmDlgCertFile <- lastToEither "Unspecified skmDlgCertFile" pskmDlgCertFile
86+
coRequiresNetworkMagic <- lastToEither "Unspecified coRequiresNetworkMagic" pcoRequiresNetworkMagic
87+
coDBSerializeVersion <- lastToEither "Unspecified coDBSerializeVersion" pcoDBSerializeVersion
11188

112-
pure StaticKeyMaterial{..}
89+
pure Core{..}
11390

11491
-- | Finalize the @PartialNode@, convert to @Node@.
11592
finaliseNode :: PartialNode -> Either Text Node
@@ -169,24 +146,16 @@ finaliseTLS PartialTLS{..} = do
169146

170147
pure TLS{..}
171148

172-
-- | Finalise the @PartialThrottle@, convert to @Throttle@.
173-
finaliseThrottle :: PartialThrottle -> Either Text Throttle
174-
finaliseThrottle PartialThrottle{..} = do
149+
-- | Finalize the @PartialWallet@, convert to @Wallet@.
150+
finaliseWallet :: PartialWallet -> Either Text Wallet
151+
finaliseWallet PartialWallet{..} = do
175152

176153
thEnabled <- lastToEither "Unspecified thEnabled" pthEnabled
177154
thRate <- lastToEither "Unspecified thRate" pthRate
178155
thPeriod <- lastToEither "Unspecified thPeriod" pthPeriod
179156
thBurst <- lastToEither "Unspecified thBurst" pthBurst
180157

181-
pure Throttle {..}
182-
183-
-- | Finalize the @PartialWallet@, convert to @Wallet@.
184-
finaliseWallet :: PartialWallet -> Either Text Wallet
185-
finaliseWallet PartialWallet{..} = do
186-
187-
waThrottle <- join $ finaliseThrottle <$> lastToEither "Unspecified waThrottle" pwaThrottle
188-
189-
pure Wallet{..}
158+
pure Wallet {..}
190159

191160

192161
-- | Generate 'TopologyConfig' with given 'Cluster'

0 commit comments

Comments
 (0)