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

Commit 5523bc5

Browse files
committed
[GH-235] Fixing nested configuration problems.
1 parent 7f1e7c9 commit 5523bc5

File tree

7 files changed

+197
-234
lines changed

7 files changed

+197
-234
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+
!(Last PartialWallet)
32+
!(Last PartialBlock)
33+
!(Last 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' = liftA2 (<>) configCore coreCLI
104+
let pccBlock' = liftA2 (<>) configBlock blockCLI
105+
let pccWallet' = liftA2 (<>) 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: 12 additions & 40 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@
@@ -85,31 +79,17 @@ finaliseCardanoConfiguration PartialCardanoConfiguration{..} = do
8579
-- | Finalize the @PartialCore@, convert to @Core@.
8680
finaliseCore :: PartialCore -> Either Text Core
8781
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
9482

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{..}
83+
coGenesisFile <- lastToEither "Unspecified coGenesisFile" pcoGenesisFile
84+
coGenesisHash <- lastToEither "Unspecified coGenesisHash" pcoGenesisHash
10585

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

109-
skmSigningKeyFile <- lastToEither "Unspecified skmSigningKeyFile" pskmSigningKeyFile
110-
skmDlgCertFile <- lastToEither "Unspecified skmDlgCertFile" pskmDlgCertFile
89+
coRequiresNetworkMagic <- lastToEither "Unspecified coRequiresNetworkMagic" pcoRequiresNetworkMagic
90+
coDBSerializeVersion <- lastToEither "Unspecified coDBSerializeVersion" pcoDBSerializeVersion
11191

112-
pure StaticKeyMaterial{..}
92+
pure Core{..}
11393

11494
-- | Finalize the @PartialNode@, convert to @Node@.
11595
finaliseNode :: PartialNode -> Either Text Node
@@ -169,24 +149,16 @@ finaliseTLS PartialTLS{..} = do
169149

170150
pure TLS{..}
171151

172-
-- | Finalise the @PartialThrottle@, convert to @Throttle@.
173-
finaliseThrottle :: PartialThrottle -> Either Text Throttle
174-
finaliseThrottle PartialThrottle{..} = do
152+
-- | Finalize the @PartialWallet@, convert to @Wallet@.
153+
finaliseWallet :: PartialWallet -> Either Text Wallet
154+
finaliseWallet PartialWallet{..} = do
175155

176156
thEnabled <- lastToEither "Unspecified thEnabled" pthEnabled
177157
thRate <- lastToEither "Unspecified thRate" pthRate
178158
thPeriod <- lastToEither "Unspecified thPeriod" pthPeriod
179159
thBurst <- lastToEither "Unspecified thBurst" pthBurst
180160

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{..}
161+
pure Wallet {..}
190162

191163

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

0 commit comments

Comments
 (0)