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

[GH-235] Fixing nested configuration problems #236

Merged
merged 2 commits into from
Jul 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/Cardano/Shell/Features/Networking.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Cardano.Shell.Types (CardanoEnvironment, CardanoFeature (..),
CardanoFeatureInit (..))

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

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

-- we construct the layer
networkingLayer <- (featureInit networkingCardanoFeatureInit) cardanoEnvironment loggingLayer cardanoConfiguration networkingConfiguration
Expand Down
61 changes: 55 additions & 6 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import Cardano.Shell.Features.Logging (LoggingCLIArguments,
import Cardano.Shell.Features.Networking (createNetworkingFeature)

import Cardano.Shell.Configuration.Lib (finaliseCardanoConfiguration)
import Cardano.Shell.Constants.CLI (configCoreCLIParser)
import Cardano.Shell.Constants.PartialTypes (PartialCardanoConfiguration (..),
PartialCore (..))
import Cardano.Shell.Constants.CLI (configBlockCLIParser,
configCoreCLIParser,
configWalletCLIParser)
import Cardano.Shell.Constants.PartialTypes (PartialBlock (..), PartialCardanoConfiguration (..),
PartialCore (..),
PartialWallet (..))
import Cardano.Shell.Lib
import Cardano.Shell.Presets (mainnetConfiguration)
import Cardano.Shell.Types
Expand All @@ -23,7 +26,11 @@ import Options.Applicative

-- | The product type of all command line arguments.
-- All here being - from all the features.
data CLIArguments = CLIArguments !LoggingCLIArguments !PartialCore
data CLIArguments = CLIArguments
!LoggingCLIArguments
!PartialWallet
!PartialBlock
!PartialCore

main :: IO ()
main = do
Expand Down Expand Up @@ -87,10 +94,49 @@ initializeAllFeatures :: PartialCardanoConfiguration -> CardanoEnvironment -> IO
initializeAllFeatures partialConfig cardanoEnvironment = do

-- Here we parse the __CLI__ arguments for the actual application.
CLIArguments loggingCLIArguments coreCLI <- execParser parserWithInfo
CLIArguments loggingCLIArguments walletCLI blockCLI coreCLI <- execParser parserWithInfo

let configCore = pccCore partialConfig
let configBlock = pccBlock partialConfig
let configWallet = pccWallet partialConfig

let pccCore' = configCore <> coreCLI
let pccBlock' = configBlock <> blockCLI
let pccWallet' = configWallet <> walletCLI

putTextLn "************************************************"
putTextLn "CORE"
putTextLn "************************************************"
putTextLn $ show configCore
putTextLn "------------------------------------------------"
putTextLn $ show coreCLI
putTextLn "------------------------------------------------"
putTextLn $ show pccCore'

putTextLn "************************************************"
putTextLn "BLOCK"
putTextLn "************************************************"
putTextLn $ show configBlock
putTextLn "------------------------------------------------"
putTextLn $ show blockCLI
putTextLn "------------------------------------------------"
putTextLn $ show pccBlock'

putTextLn "************************************************"
putTextLn "WALLET"
putTextLn "************************************************"
putTextLn $ show configWallet
putTextLn "------------------------------------------------"
putTextLn $ show walletCLI
putTextLn "------------------------------------------------"
putTextLn $ show pccWallet'

finalConfig <- either (throwIO . ConfigurationError) pure $
finaliseCardanoConfiguration $ partialConfig { pccCore = pccCore partialConfig <> pure coreCLI }
finaliseCardanoConfiguration $ partialConfig
{ pccCore = pccCore'
, pccBlock = pccBlock'
, pccWallet = pccWallet'
}

-- Here we initialize all the features
(loggingLayer, loggingFeature) <- createLoggingFeature cardanoEnvironment finalConfig loggingCLIArguments
Expand Down Expand Up @@ -118,4 +164,7 @@ initializeAllFeatures partialConfig cardanoEnvironment = do
commandLineParser :: Parser CLIArguments
commandLineParser = CLIArguments
<$> loggingParser
<*> configWalletCLIParser
<*> configBlockCLIParser
<*> configCoreCLIParser

61 changes: 15 additions & 46 deletions src/Cardano/Shell/Configuration/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
module Cardano.Shell.Configuration.Lib
( finaliseCardanoConfiguration
, finaliseCore
, finaliseGenesis
, mkLauncher
, mkTopology
, mkOSConfig
Expand Down Expand Up @@ -32,18 +31,13 @@ import Cardano.Shell.Configuration.Types (BlockchainConfig,
import Cardano.Shell.Constants.PartialTypes (PartialBlock (..), PartialCardanoConfiguration (..),
PartialCertificate (..),
PartialCore (..),
PartialGenesis (..),
PartialNode (..),
PartialStaticKeyMaterial (..),
PartialTLS (..),
PartialThrottle (..),
PartialWallet (..))
import Cardano.Shell.Constants.Types (Block (..),
CardanoConfiguration (..),
Certificate (..), Core (..),
Genesis (..), Node (..),
StaticKeyMaterial (..),
TLS (..), Throttle (..),
Node (..), TLS (..),
Wallet (..))

-- | Converting a @Last@ to an @Either@
Expand All @@ -64,52 +58,35 @@ finaliseCardanoConfiguration PartialCardanoConfiguration{..} = do
ccDBPath <- lastToEither "Unspecified ccDBPath" pccDBPath
ccApplicationLockFile <- lastToEither "Unspecified ccApplicationLockFile"
pccApplicationLockFile
ccCore <- join $ finaliseCore <$>
lastToEither "Unspecified ccCore" pccCore
ccCore <- finaliseCore pccCore
ccNTP <- lastToEither "Unspecified ccNTP" pccNTP
ccUpdate <- lastToEither "Unspecified ccUpdate" pccUpdate
ccTXP <- lastToEither "Unspecified ccTXP" pccTXP
ccSSC <- lastToEither "Unspecified ccSSC" pccSSC
ccDLG <- lastToEither "Unspecified ccDLG" pccDLG
ccBlock <- join $ finaliseBlock <$>
lastToEither "Unspecified ccBlock" pccBlock
ccBlock <- finaliseBlock pccBlock
ccNode <- join $ finaliseNode <$>
lastToEither "Unspecified ccNode" pccNode
ccTLS <- join $ finaliseTLS <$>
lastToEither "Unspecified ccTLS" pccTLS
ccWallet <- join $ finaliseWallet <$>
lastToEither "Unspecified ccWallet" pccWallet
ccWallet <- finaliseWallet pccWallet

pure CardanoConfiguration{..}

-- | Finalize the @PartialCore@, convert to @Core@.
finaliseCore :: PartialCore -> Either Text Core
finaliseCore PartialCore{..} = do
coGenesis <- join $ finaliseGenesis <$>
lastToEither "Unspecified coGenesis" pcoGenesis
coStaticKeyMaterial <- join $ finaliseStaticKeyMaterial <$>
lastToEither "Unspecified coStaticKeyMaterial" pcoStaticKeyMaterial
coRequiresNetworkMagic <- lastToEither "Unspecified coRequiresNetworkMagic" pcoRequiresNetworkMagic
coDBSerializeVersion <- lastToEither "Unspecified coDBSerializeVersion" pcoDBSerializeVersion

pure Core{..}

-- | Finalize the @PartialGenesis@, convert to @Genesis@.
finaliseGenesis :: PartialGenesis -> Either Text Genesis
finaliseGenesis PartialGenesis{..} = do

geSrc <- lastToEither "Unspecified geSrc" pgeSrc
geGenesisHash <- lastToEither "Unspecified geGenesisHash" pgeGenesisHash

pure Genesis{..}
coGenesisFile <- lastToEither "Unspecified coGenesisFile" pcoGenesisFile
coGenesisHash <- lastToEither "Unspecified coGenesisHash" pcoGenesisHash

finaliseStaticKeyMaterial :: PartialStaticKeyMaterial -> Either Text StaticKeyMaterial
finaliseStaticKeyMaterial PartialStaticKeyMaterial{..} = do
coStaticKeySigningKeyFile <- lastToEither "Unspecified coStaticKeySigningKeyFile" pcoStaticKeySigningKeyFile
coStaticKeyDlgCertFile <- lastToEither "Unspecified coStaticKeyDlgCertFile" pcoStaticKeyDlgCertFile

skmSigningKeyFile <- lastToEither "Unspecified skmSigningKeyFile" pskmSigningKeyFile
skmDlgCertFile <- lastToEither "Unspecified skmDlgCertFile" pskmDlgCertFile
coRequiresNetworkMagic <- lastToEither "Unspecified coRequiresNetworkMagic" pcoRequiresNetworkMagic
coDBSerializeVersion <- lastToEither "Unspecified coDBSerializeVersion" pcoDBSerializeVersion

pure StaticKeyMaterial{..}
pure Core{..}

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

pure TLS{..}

-- | Finalise the @PartialThrottle@, convert to @Throttle@.
finaliseThrottle :: PartialThrottle -> Either Text Throttle
finaliseThrottle PartialThrottle{..} = do
-- | Finalize the @PartialWallet@, convert to @Wallet@.
finaliseWallet :: PartialWallet -> Either Text Wallet
finaliseWallet PartialWallet{..} = do

thEnabled <- lastToEither "Unspecified thEnabled" pthEnabled
thRate <- lastToEither "Unspecified thRate" pthRate
thPeriod <- lastToEither "Unspecified thPeriod" pthPeriod
thBurst <- lastToEither "Unspecified thBurst" pthBurst

pure Throttle {..}

-- | Finalize the @PartialWallet@, convert to @Wallet@.
finaliseWallet :: PartialWallet -> Either Text Wallet
finaliseWallet PartialWallet{..} = do

waThrottle <- join $ finaliseThrottle <$> lastToEither "Unspecified waThrottle" pwaThrottle

pure Wallet{..}
pure Wallet {..}


-- | Generate 'TopologyConfig' with given 'Cluster'
Expand Down
Loading