Skip to content

Commit

Permalink
Merge #1380
Browse files Browse the repository at this point in the history
1380: More module movement from cardano-config to cardano-node and cardano-api r=Jimbo4350 a=Jimbo4350



Co-authored-by: Jordan Millar <jordan.millar@iohk.io>
  • Loading branch information
iohk-bors[bot] and Jimbo4350 committed Jul 3, 2020
2 parents d0a6376 + 5c36fbf commit 6917aae
Show file tree
Hide file tree
Showing 37 changed files with 820 additions and 661 deletions.
9 changes: 9 additions & 0 deletions cardano-api/cardano-api.cabal
Expand Up @@ -22,6 +22,7 @@ library
Cardano.Api.Protocol.Shelley
Cardano.Api.Shelley.Address
Cardano.Api.Shelley.ColdKeys
Cardano.Api.Shelley.Genesis
Cardano.Api.Shelley.OCert
Cardano.Api.Shelley.KES
Cardano.Api.Shelley.VRF
Expand Down Expand Up @@ -81,6 +82,7 @@ library
, shelley-spec-ledger
, stm
, text
, time
, transformers
, transformers-except
, typed-protocols
Expand Down Expand Up @@ -115,17 +117,24 @@ test-suite cardano-api-test
, cardano-crypto-wrapper
, cardano-ledger-test
, cardano-prelude
, cardano-prelude-test
, cardano-slotting
, containers
, cryptonite
, hedgehog
, ouroboros-consensus
, ouroboros-consensus-shelley
, ouroboros-network
, shelley-spec-ledger
, shelley-spec-ledger-test
, time

other-modules: Test.Cardano.Api
Test.Cardano.Api.CBOR
Test.Cardano.Api.Convert
Test.Cardano.Api.Examples
Test.Cardano.Api.Gen
Test.Cardano.Api.Ledger
Test.Cardano.Api.Orphans
Test.Cardano.Api.View
Test.Cardano.Api.Typed.CBOR
Expand Down
61 changes: 53 additions & 8 deletions cardano-api/src/Cardano/Api/Protocol.hs
@@ -1,15 +1,20 @@
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}


module Cardano.Api.Protocol
(
-- * The enumeration of supported protocols
Protocol(..)
, MockProtocol(..)

-- * Node client support
-- | Support for the context needed to run a client of a node that is using
Expand All @@ -20,7 +25,9 @@ module Cardano.Api.Protocol

import Cardano.Prelude

import Cardano.Config.Types (Protocol(..))
import Control.Monad.Fail (fail)
import Data.Aeson

import Cardano.Chain.Slotting (EpochSlots(..))

import Cardano.Api.Protocol.Types
Expand All @@ -30,6 +37,45 @@ import Cardano.Api.Protocol.Shelley

import qualified Ouroboros.Consensus.Cardano as Consensus

data Protocol = MockProtocol !MockProtocol
| ByronProtocol
| ShelleyProtocol
| CardanoProtocol
deriving (Eq, Show, Generic)

instance FromJSON Protocol where
parseJSON =
withText "Protocol" $ \str -> case str of

-- The new names
"MockBFT" -> pure (MockProtocol MockBFT)
"MockPBFT" -> pure (MockProtocol MockPBFT)
"MockPraos" -> pure (MockProtocol MockPraos)
"Byron" -> pure ByronProtocol
"Shelley" -> pure ShelleyProtocol
"Cardano" -> pure CardanoProtocol

-- The old names
"BFT" -> pure (MockProtocol MockBFT)
--"MockPBFT" -- same as new name
"Praos" -> pure (MockProtocol MockPraos)
"RealPBFT" -> pure ByronProtocol
"TPraos" -> pure ShelleyProtocol

_ -> fail $ "Parsing of Protocol failed. "
<> show str <> " is not a valid protocol"


deriving instance NFData Protocol
deriving instance NoUnexpectedThunks Protocol

data MockProtocol = MockBFT
| MockPBFT
| MockPraos
deriving (Eq, Show, Generic)

deriving instance NFData MockProtocol
deriving instance NoUnexpectedThunks MockProtocol

mkNodeClientProtocol :: Protocol -> SomeNodeClientProtocol
mkNodeClientProtocol protocol =
Expand Down Expand Up @@ -71,4 +117,3 @@ mkNodeClientProtocol protocol =
-- client case.
(EpochSlots 21600)
(Consensus.SecurityParam 2160)

Expand Up @@ -3,7 +3,7 @@

{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Config.Shelley.Genesis
module Cardano.Api.Shelley.Genesis
( ShelleyGenesis(..)
, ShelleyGenesisError(..)
, renderShelleyGenesisError
Expand All @@ -19,7 +19,7 @@ import qualified Data.Map.Strict as Map
import qualified Data.Time as Time

import Data.Aeson (Value, ToJSON(..), toJSON, FromJSON(..))
import Data.Aeson.Types (Parser)
import Data.Aeson.Types (Parser)

import Cardano.Config.Shelley.Orphans ()
import Cardano.Crypto.ProtocolMagic (ProtocolMagicId(..))
Expand Down
File renamed without changes.
Expand Up @@ -3,7 +3,7 @@

{-# OPTIONS_GHC -Wno-unticked-promoted-constructors #-}

module Test.Cardano.Config.Examples
module Test.Cardano.Api.Examples
( exampleShelleyGenesis
) where

Expand All @@ -28,7 +28,7 @@ import Shelley.Spec.Ledger.Keys (KeyHash(..), KeyRole(..), Hash,
VerKeyVRF, GenDelegPair(..))
import Shelley.Spec.Ledger.PParams (PParams' (..), emptyPParams)

import Cardano.Config.Shelley.Genesis
import Cardano.Api.Shelley.Genesis


exampleShelleyGenesis :: ShelleyGenesis TPraosStandardCrypto
Expand Down
Expand Up @@ -2,7 +2,7 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}

module Test.Cardano.Config.Types
module Test.Cardano.Api.Ledger
( tests
) where

Expand All @@ -22,7 +22,7 @@ import Ouroboros.Consensus.Shelley.Protocol (TPraosStandardCrypto)
import qualified Test.Shelley.Spec.Ledger.Genesis.Properties as Ledger
import Test.Shelley.Spec.Ledger.Generator.Genesis

import Test.Cardano.Config.Examples
import Test.Cardano.Api.Examples
import Test.Cardano.Prelude


Expand Down
2 changes: 2 additions & 0 deletions cardano-api/test/cardano-api-test.hs
Expand Up @@ -6,6 +6,7 @@ import Hedgehog.Main (defaultMain)
import qualified Test.Cardano.Api
import qualified Test.Cardano.Api.CBOR
import qualified Test.Cardano.Api.Convert
import qualified Test.Cardano.Api.Ledger
import qualified Test.Cardano.Api.View
import qualified Test.Cardano.Api.Typed.CBOR
import qualified Test.Cardano.Api.Typed.RawBytes
Expand All @@ -16,6 +17,7 @@ main =
defaultMain
[ Test.Cardano.Api.CBOR.tests
, Test.Cardano.Api.Convert.tests
, Test.Cardano.Api.Ledger.tests
, Test.Cardano.Api.View.tests
, Test.Cardano.Api.tests
, Test.Cardano.Api.Typed.CBOR.tests
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs
Expand Up @@ -52,7 +52,7 @@ import qualified Shelley.Spec.Ledger.TxData as Shelley
import Cardano.Api.Shelley.Address (ShelleyAddress)
import Cardano.Api.Shelley.ColdKeys (KeyRole (..), OperatorKeyRole (..),
readVerKey)
import Cardano.Config.Shelley.Genesis
import Cardano.Api.Shelley.Genesis
import Cardano.Api.Shelley.ColdKeys
import Cardano.Api.Shelley.OCert
import Cardano.Api.Shelley.VRF
Expand Down
48 changes: 0 additions & 48 deletions cardano-config/cardano-config.cabal
Expand Up @@ -26,15 +26,11 @@ library
Cardano.Config.GitRev
Cardano.Config.GitRevFromGit
Cardano.Config.LedgerQueries
Cardano.Config.Logging
Cardano.Config.Orphanage
Cardano.Config.Parsers
Cardano.Config.Shelley.Genesis
Cardano.Config.Shelley.Orphans
Cardano.Config.Shelley.Parsers
Cardano.Config.Topology
Cardano.Config.TopHandler
Cardano.Config.TraceConfig
Cardano.Config.Types
Cardano.TracingOrphanInstances.Byron
Cardano.TracingOrphanInstances.Common
Expand Down Expand Up @@ -107,47 +103,3 @@ library
-Wredundant-constraints
-Wpartial-fields
-Wcompat

test-suite cardano-config-test
hs-source-dirs: test
main-is: cardano-config-test.hs
type: exitcode-stdio-1.0

build-depends:
base >= 4.12 && < 5
, aeson
, bytestring
, cardano-config
, cardano-crypto-class
, cardano-crypto-test
, cardano-crypto-wrapper
, cardano-prelude
, cardano-prelude-test
, cardano-slotting
, containers
, cryptonite
, iproute
, ouroboros-consensus
, ouroboros-consensus-shelley
, ouroboros-network
, shelley-spec-ledger
, shelley-spec-ledger-test
, time
, hedgehog
, hedgehog-corpus

other-modules: Test.Cardano.Config.Examples
Test.Cardano.Config.Gen
Test.Cardano.Config.Json
Test.Cardano.Config.Types

default-language: Haskell2010
default-extensions: NoImplicitPrelude

ghc-options: -Wall
-Wincomplete-record-updates
-Wincomplete-uni-patterns
-Wredundant-constraints
-Wpartial-fields
-Wcompat
-threaded -rtsopts -with-rtsopts=-N -with-rtsopts=-T

0 comments on commit 6917aae

Please sign in to comment.