Skip to content

Commit

Permalink
do stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed Mar 7, 2019
1 parent 8ec4cfd commit b6928ea
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 2 deletions.
45 changes: 45 additions & 0 deletions app/server/Launcher.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module Launcher where

import Control.Concurrent.Async
import Prelude
import System.Process

-- What is @bracket@?
--
-- When you want to acquire a resource, do some work with it, and then release
-- the resource, it is a good idea to use bracket, because bracket will install
-- the necessary exception handler to release the resource in the event that an
-- exception is raised during the computation. If an exception is raised, then
-- bracket will re-raise the exception (after performing the release).
--
-- http://hackage.haskell.org/package/base-4.12.0.0/docs/Control-Exception-Base.html#v:bracket









-- | Run an external process alongside a haskell IO action
--
-- Both are expected to run forever.
--
-- Sadly you cannot quit this in ghci
bracketProcess :: CreateProcess -> IO () -> IO ()
bracketProcess process action = do
_ <- withCreateProcess
process {delegate_ctlc = True, std_out = CreatePipe }
$ \_stdin _stdout _stderr ph -> do
-- if this IO action throws, @withCreateProcess@ will kill the node and
-- rethrow.
concurrently action (node ph)
return ()
where
node ph = do
_ <- waitForProcess ph
fail "why is the node gone?"



35 changes: 33 additions & 2 deletions app/server/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
-}
module Main where

import Control.Concurrent
import Control.Monad
( when )
import Launcher
import Prelude
import System.Console.Docopt
( Arguments
Expand All @@ -25,6 +27,7 @@ import System.Console.Docopt
)
import System.Environment
( getArgs )
import System.Process
import Text.Read
( readMaybe )

Expand Down Expand Up @@ -60,10 +63,38 @@ main = do
walletPort <- getArg args (longOption "wallet-server-port") readInt

putStrLn $
"TODO: start wallet on port " ++ (show walletPort) ++
",\n connecting to " ++ (show network) ++
"Starting wallet on port " ++ (show walletPort) ++
",\n connecting to " ++ (show network) ++
" node on port " ++ (show nodePort)

bracketProcess
(nodeHttpBridgeOn nodePort network)
(walletOn walletPort)


sleep :: CreateProcess
sleep = (proc "sleep" ["10"])


-- |
-- Requires cardano-http-bridge to be installed
--
-- git clone https://github.com/input-output-hk/cardano-http-bridge
-- follow instructions in its readme
-- cargo install --path .
--
nodeHttpBridgeOn :: Int -> Network -> CreateProcess
nodeHttpBridgeOn port _network =
(proc "cardano-http-bridge" ["start", "--port", show port])

-- TODO: Start actual wallet
walletOn :: Int -> IO ()
walletOn _port = go
where
go = do
putStrLn "I'm wallet-ing"
threadDelay $ 200*1000
go

-- Functions for parsing the values of command line options
--
Expand Down
5 changes: 5 additions & 0 deletions cardano-wallet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ executable cardano-wallet-server
build-depends:
base
, docopt
, process
, async
, unix
hs-source-dirs:
app/server
other-modules:
Launcher
main-is:
Main.hs

Expand Down

0 comments on commit b6928ea

Please sign in to comment.