Skip to content

Commit

Permalink
Add a mock network env to the deposit wallet application
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed Nov 10, 2024
1 parent a744418 commit e29b2d2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Cardano.Wallet.Deposit.REST.Start
( loadDepositWalletFromDisk
, fakeBootEnv
, newFakeBootEnv
)
where

Expand All @@ -9,6 +9,12 @@ import Prelude
import Cardano.Wallet.Deposit.IO
( WalletBootEnv (..)
)
import Cardano.Wallet.Deposit.IO.Network.Mock
( newNetworkEnvMock
)
import Cardano.Wallet.Deposit.IO.Network.Type
( mapBlock
)
import Cardano.Wallet.Deposit.REST
( WalletResource
, loadWallet
Expand Down Expand Up @@ -52,10 +58,10 @@ loadDepositWalletFromDisk tr dir env resource = do
Left e -> error $ show e
Right _ -> pure ()

fakeBootEnv :: MonadIO m => WalletBootEnv m
fakeBootEnv =
( WalletBootEnv
newFakeBootEnv :: IO (WalletBootEnv IO)
newFakeBootEnv =
WalletBootEnv
(show >$< stdoutTracer)
Read.mockGenesisDataMainnet
(error "network env not defined")
)
. mapBlock Read.EraValue
<$> newNetworkEnvMock
26 changes: 20 additions & 6 deletions lib/exe/lib/Cardano/Wallet/Application.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,18 @@ import Cardano.Wallet.DB.Layer
import Cardano.Wallet.DB.Sqlite.Migration.Old
( DefaultFieldValues (..)
)
import Cardano.Wallet.Deposit.IO
( WalletBootEnv
)
import Cardano.Wallet.Deposit.IO.Resource
( withResource
)
import Cardano.Wallet.Deposit.REST
( WalletResource
)
import Cardano.Wallet.Deposit.REST.Start
( fakeBootEnv
, loadDepositWalletFromDisk
( loadDepositWalletFromDisk
, newFakeBootEnv
)
import Cardano.Wallet.Flavor
( CredFromOf
Expand Down Expand Up @@ -378,6 +381,7 @@ serveWallet
eDepositUiSocket <- bindDepositUiSocket
eDepositSocket <- bindDepositSocket
eShelleySocket <- bindApiSocket
fakeBootEnv <- lift newFakeBootEnv
callCC $ \exit -> do
case eShelleyUiSocket of
Left err -> do
Expand Down Expand Up @@ -438,6 +442,7 @@ serveWallet
let uiService =
startDepositUiServer
ui
fakeBootEnv
databaseDir'
socket
sNetwork
Expand Down Expand Up @@ -476,6 +481,7 @@ serveWallet
let depositService =
startDepositServer
resource
fakeBootEnv
databaseDir'
socket
ContT $ \k ->
Expand Down Expand Up @@ -503,23 +509,26 @@ serveWallet
bindApiSocket :: ContT r IO (Either ListenError (Warp.Port, Socket))
bindApiSocket = ContT $ withListeningSocket hostPref listenShelley

bindShelleyUiSocket :: ContT r IO (Either ListenError (Maybe (Warp.Port, Socket)))
bindShelleyUiSocket
:: ContT r IO (Either ListenError (Maybe (Warp.Port, Socket)))
bindShelleyUiSocket = case mListenShelleyUi of
Nothing -> pure $ Right Nothing
Just listenUi -> do
fmap (fmap Just)
$ ContT
$ withListeningSocket hostPref listenUi

bindDepositUiSocket :: ContT r IO (Either ListenError (Maybe (Warp.Port, Socket)))
bindDepositUiSocket
:: ContT r IO (Either ListenError (Maybe (Warp.Port, Socket)))
bindDepositUiSocket = case mListenDepositUi of
Nothing -> pure $ Right Nothing
Just listenUi -> do
fmap (fmap Just)
$ ContT
$ withListeningSocket hostPref listenUi

bindDepositSocket :: ContT r IO (Either ListenError (Maybe (Warp.Port, Socket)))
bindDepositSocket
:: ContT r IO (Either ListenError (Maybe (Warp.Port, Socket)))
bindDepositSocket = case mListenDeposit of
Nothing -> pure $ Right Nothing
Just listenDeposit ->
Expand Down Expand Up @@ -607,11 +616,13 @@ serveWallet

startDepositServer
:: WalletResource
-> WalletBootEnv IO
-> FilePath
-> Socket
-> IO ()
startDepositServer
resource
fakeBootEnv
databaseDir'
socket =
do
Expand All @@ -635,6 +646,7 @@ serveWallet
. ( HasSNetworkId n
)
=> UILayer WalletResource
-> WalletBootEnv IO
-> FilePath
-> Socket
-> SNetworkId n
Expand All @@ -643,6 +655,7 @@ serveWallet
-> IO ()
startDepositUiServer
ui
fakeBootEnv
databaseDir'
socket
_proxy
Expand Down Expand Up @@ -781,7 +794,8 @@ serveWallet
tokenMetaClient
coworker

handleWalletExceptions :: forall x. Servant.Handler x -> Servant.Handler x
handleWalletExceptions
:: forall x. Servant.Handler x -> Servant.Handler x
handleWalletExceptions =
Servant.Handler
. ExceptT
Expand Down

0 comments on commit e29b2d2

Please sign in to comment.