Skip to content

Commit

Permalink
Use bracket in place of allocate from ResourceT to run the cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed Apr 23, 2024
1 parent 0240127 commit d66daff
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions lib/local-cluster/exe/local-cluster.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ import Cardano.Wallet.Launch.Cluster.FileOf
import Cardano.Wallet.Primitive.Types.Coin
( Coin (..)
)
import Control.Exception
( bracket
)
import Control.Lens
( over
)
Expand All @@ -54,10 +57,6 @@ import Control.Monad.IO.Class
import Control.Monad.Trans
( lift
)
import Control.Monad.Trans.Resource
( allocate
, runResourceT
)
import Main.Utf8
( withUtf8
)
Expand Down Expand Up @@ -256,28 +255,23 @@ main = withUtf8 $ do
case parse . nodeSocketFile $ Cluster.runningNodeSocketPath node of
Left e -> error e
Right p -> pure p
lift $ runResourceT $ do
(_releaseKey, (_walletInstance, _walletApi)) <-
allocate
( WC.start
WC.WalletProcessConfig
{ WC.walletDir =
DirOf walletDir
, WC.walletNodeApi =
NC.NodeApi nodeSocket
, WC.walletDatabase =
DirOf $ clusterDir </> relDir "db"
, WC.walletListenHost =
Nothing
, WC.walletListenPort =
Nothing
, WC.walletByronGenesisForTestnet =
Just
$ FileOf
$ clusterDir
</> relFile "byron-genesis.json"
}
)
(WC.stop . fst)

threadDelay maxBound -- wait for Ctrl+C
let walletProcessConfig =
WC.WalletProcessConfig
{ WC.walletDir = DirOf walletDir
, WC.walletNodeApi = NC.NodeApi nodeSocket
, WC.walletDatabase = DirOf $ clusterDir </> relDir "db"
, WC.walletListenHost = Nothing
, WC.walletListenPort = Nothing
, WC.walletByronGenesisForTestnet =
Just
$ FileOf
$ clusterDir
</> relFile "byron-genesis.json"
}
lift
$ bracket
(WC.start walletProcessConfig)
(WC.stop . fst)
$ const
$ threadDelay maxBound -- wait for Ctrl+C

0 comments on commit d66daff

Please sign in to comment.