Skip to content

Commit

Permalink
Add http api to local-cluster executable
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed May 6, 2024
1 parent 9ec2cd6 commit 3f9c600
Showing 1 changed file with 51 additions and 10 deletions.
61 changes: 51 additions & 10 deletions lib/local-cluster/exe/local-cluster.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ import Cardano.Wallet.Launch.Cluster.FileOf
, mkRelDirOf
, toFilePath
)
import Cardano.Wallet.Launch.Cluster.Monitoring.Http.Application.Server
( newNodeConnVar
)
import Cardano.Wallet.Launch.Cluster.Monitoring.Monitor
( withMonitoringServer
)
import Cardano.Wallet.Launch.Cluster.Monitoring.Phase
( Phase (..)
, RelayNode (..)
)
import Cardano.Wallet.Primitive.NetworkId
( NetworkId (..)
, withSNetworkId
)
import Cardano.Wallet.Primitive.Types.Coin
( Coin (..)
)
Expand All @@ -56,6 +70,13 @@ import Control.Monad.Cont
import Control.Monad.IO.Class
( MonadIO (..)
)
import Control.Tracer
( Tracer (..)
, traceWith
)
import Data.Text.Class
( ToText
)
import Main.Utf8
( withUtf8
)
Expand Down Expand Up @@ -211,7 +232,8 @@ main = withUtf8 $ do
setDefaultFilePermissions

skipCleanup <- SkipCleanup <$> isEnvSet "NO_CLEANUP"
let tr = stdoutTextTracer
let tr :: ToText a => Tracer IO a
tr = stdoutTextTracer
clusterEra <- Cluster.clusterEraFromEnv
cfgNodeLogging <-
Cluster.logFileConfigFromEnv
Expand All @@ -223,6 +245,7 @@ main = withUtf8 $ do
, clusterDir
, clusterLogs
, nodeToClientSocket
, monitoring
} <-
parseCommandLineOptions
evalContT $ do
Expand All @@ -231,15 +254,9 @@ main = withUtf8 $ do
case clusterDir of
Just path -> pure path
Nothing ->
fmap (DirOf . absDir) $
ContT $ withSystemTempDir tr "test-cluster" skipCleanup
-- Start the faucet
faucetClientEnv <- ContT withFaucet
maryAllegraFunds <-
liftIO
$ runFaucetM faucetClientEnv
$ Faucet.maryAllegraFunds (Coin 10_000_000) shelleyTestnet
-- Start the cluster
fmap (DirOf . absDir)
$ ContT
$ withSystemTempDir tr "test-cluster" skipCleanup
let clusterCfg =
Cluster.Config
{ cfgStakePools = Cluster.defaultPoolConfigs
Expand All @@ -255,6 +272,23 @@ main = withUtf8 $ do
, cfgClusterLogFile = clusterLogs
, cfgNodeToClientSocket = nodeToClientSocket
}
(_, phaseTracer) <- withSNetworkId (NTestnet 42)
$ \network -> do
nodeConn <- liftIO newNodeConnVar
withMonitoringServer
network
nodeConn
clusterCfg
tr
monitoring
-- Start the faucet
faucetClientEnv <- ContT withFaucet
maryAllegraFunds <-
liftIO
$ runFaucetM faucetClientEnv
$ Faucet.maryAllegraFunds (Coin 10_000_000) shelleyTestnet
-- Start the cluster

node <-
ContT
$ Cluster.withCluster
Expand Down Expand Up @@ -287,7 +321,14 @@ main = withUtf8 $ do
$ clusterDirPath
</> relFile "byron-genesis.json"
}

(_walletInstance, _walletApi) <-
ContT $ bracket (WC.start walletProcessConfig) (WC.stop . fst)
liftIO
$ traceWith phaseTracer
$ Cluster
$ Just
$ RelayNode
$ toFilePath nodeSocket
-- Wait forever or ctrl-c
threadDelay maxBound

0 comments on commit 3f9c600

Please sign in to comment.