Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
[CO-390] Create a 'demo' executable for cardano-sl-wallet-new
Browse files Browse the repository at this point in the history
This code makes use of the 'Cardano.Wallet.Demo' module and show
how it can be used to spawn a demo cluster of nodes.
More details in the README.md
  • Loading branch information
KtorZ committed Oct 4, 2018
1 parent 16cfabe commit 4d71034
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cluster/cardano-sl-cluster.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,23 @@ library
exposed-modules: Cardano.Cluster
Cardano.Cluster.Environment
Cardano.Cluster.Util


executable cardano-sl-demo
ghc-options: -threaded -O2 -rtsopts
default-language: Haskell2010
default-extensions: DeriveGeneric
LambdaCase
NoImplicitPrelude
OverloadedStrings
TupleSections
TypeApplications
ScopedTypeVariables

hs-source-dirs: demo
main-is: Main.hs

build-depends: base
, async
, cardano-sl-cluster
, universum
51 changes: 51 additions & 0 deletions cluster/demo/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{-| Demo cluster of wallet nodes. See cluster/README.md -}

module Main where

import Universum

import Control.Concurrent.Async (waitAny)
import System.IO (BufferMode (..), hSetBuffering, stdout)

import Cardano.Cluster (MaxWaitingTime (..), NodeName (..),
NodeType (..), RunningNode (..), startCluster,
waitForNode)


-- | Cluster configuration can be tweaked via ENV vars.
-- Each ENV var is prefixed with the following.
--
-- (e.g. `DEMO_NO_CLIENT_AUTH=True`)
prefix :: String
prefix = "DEMO_"


main :: IO ()
main = void $ do
hSetBuffering stdout NoBuffering -- Instead of LineBuffering

putTextLn "Cluster is starting..."
cluster <- startCluster prefix
[ ("core0", NodeCore)
, ("core1", NodeCore)
, ("core2", NodeCore)
, ("core3", NodeCore)
, ("relay", NodeRelay)
, ("wallet", NodeEdge)
]
handles <- forM cluster $ \case
RunningCoreNode (NodeName nodeId) handle -> do
putTextLn $ "..." <> nodeId <> " has no health-check API."
return handle

RunningRelayNode (NodeName nodeId) handle -> do
putTextLn $ "..." <> nodeId <> " has no health-check API."
return handle

RunningWalletNode (NodeName nodeId) client handle -> do
putText "..." >> waitForNode client (MaxWaitingTime 30)
putTextLn $ nodeId <> " OK!"
return handle
putTextLn "Cluster is (probably) ready!"

waitAny handles

0 comments on commit 4d71034

Please sign in to comment.