-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from input-output-hk/anviking/218/jörmungandr…
…-blocks Scaffold `lib/jormungandr` folder
- Loading branch information
Showing
32 changed files
with
481 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
|
||
-- | | ||
-- Copyright: © 2018-2019 IOHK | ||
-- License: MIT | ||
-- | ||
-- This module contains static configuration parameters. Rather than providing | ||
-- and carrying around a configuration file through the application, we resolve | ||
-- configuration data at runtime using the available environment. | ||
-- | ||
-- This gives us a flexible and portable approach to software configuration, and | ||
-- remove some pain from the development perspective. Prior to starting, the | ||
-- wallet is expected to have a few configuration parameter available. One may | ||
-- rely on a `.env` file to bundle configuration settings together for a given | ||
-- target environment. | ||
|
||
module Cardano.Environment.HttpBridge | ||
( | ||
-- * Networking | ||
Network(..) | ||
, network | ||
, ProtocolMagic(..) | ||
, protocolMagic | ||
) where | ||
|
||
import Prelude | ||
|
||
import Cardano.Environment | ||
( unsafeLookupEnv ) | ||
import Data.Int | ||
( Int32 ) | ||
import Data.Text.Class | ||
( FromText (..), TextDecodingError (..), ToText (..) ) | ||
import GHC.Generics | ||
( Generic ) | ||
|
||
import qualified Data.Text as T | ||
|
||
-- | Available network options. | ||
data Network = Mainnet | Testnet | Staging | ||
deriving (Generic, Show, Eq, Enum) | ||
|
||
instance FromText Network where | ||
fromText = \case | ||
"mainnet" -> Right Mainnet | ||
"testnet" -> Right Testnet | ||
"staging" -> Right Staging | ||
s -> Left $ TextDecodingError $ T.unpack s | ||
<> " is neither \"mainnet\", \"testnet\" nor \"staging\"." | ||
|
||
instance ToText Network where | ||
toText = \case | ||
Mainnet -> "mainnet" | ||
Testnet -> "testnet" | ||
Staging -> "staging" | ||
|
||
-- | Get the current target 'Network' from the Environment. | ||
-- | ||
-- Throws a runtime exception is the ENV var isn't set or, is invalid. | ||
network :: Network | ||
network = | ||
unsafeLookupEnv "NETWORK" | ||
{-# NOINLINE network #-} | ||
|
||
newtype ProtocolMagic = ProtocolMagic Int32 | ||
deriving (Generic, Show) | ||
|
||
-- | Get the 'ProtocolMagic' corresponding to a given 'Network'. | ||
protocolMagic :: Network -> ProtocolMagic | ||
protocolMagic = \case | ||
Mainnet -> ProtocolMagic 764824073 | ||
Staging -> ProtocolMagic 633343913 | ||
Testnet -> ProtocolMagic 1097911063 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.