Skip to content

Commit

Permalink
[ADP-3120] Remove cardano-wallet-api-http build-depends from cardano-…
Browse files Browse the repository at this point in the history
…wallet-local-cluster sub-lib (#4087)

ADP-3120
  • Loading branch information
paolino authored Aug 14, 2023
2 parents 33a4c26 + ff4ad32 commit 82f1ed4
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 384 deletions.
7 changes: 4 additions & 3 deletions lib/local-cluster/lib/Service.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import Cardano.CLI
)
import Cardano.Startup
( installSignalHandlers, setDefaultFilePermissions, withUtf8Encoding )
import Cardano.Wallet.Api.Http.Shelley.Server
( walletListenFromEnv )
import Cardano.Wallet.Faucet
( byronIntegrationTestFunds
, genRewardAccounts
Expand All @@ -36,7 +38,7 @@ import Cardano.Wallet.Faucet
, shelleyIntegrationTestFunds
)
import Cardano.Wallet.Launch
( withSystemTempDir )
( envFromText, withSystemTempDir )
import Cardano.Wallet.Launch.Cluster
( ClusterLog (..)
, Credential (..)
Expand All @@ -46,7 +48,6 @@ import Cardano.Wallet.Launch.Cluster
, oneMillionAda
, testMinSeverityFromEnv
, tokenMetadataServerFromEnv
, walletListenFromEnv
, walletMinSeverityFromEnv
, withCluster
)
Expand Down Expand Up @@ -231,7 +232,7 @@ main = withLocalClusterSetup $ \dir clusterLogs walletLogs ->
let tracers = setupTracers (tracerSeverities (Just Debug)) tr
let db = dir </> "wallets"
createDirectory db
listen <- walletListenFromEnv
listen <- walletListenFromEnv envFromText
tokenMetadataServer <- tokenMetadataServerFromEnv

prometheusUrl <- (maybe "none"
Expand Down
11 changes: 11 additions & 0 deletions lib/wallet/api/http/Cardano/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module Cardano.CLI
, tokenMetadataSourceOption
, metadataOption
, timeToLiveOption
, modeOption

-- * Option parsers for configuring tracing
, LoggingOptions (..)
Expand All @@ -72,6 +73,7 @@ module Cardano.CLI
, Service
, TxId
, Port (..)
, Mode (..)

-- * Logging
, withLogging
Expand Down Expand Up @@ -2054,3 +2056,12 @@ optionalE :: (Monoid m, Eq m) => (m -> Either e a) -> (m -> Either e (Maybe a))
optionalE parse = \case
m | m == mempty -> Right Nothing
m -> Just <$> parse m

data Mode c = Normal c SyncTolerance
deriving (Show)

modeOption :: Parser c -> Parser (Mode c)
modeOption nodeSocketOption = normalMode
where
normalMode =
Normal <$> nodeSocketOption <*> syncToleranceOption
13 changes: 13 additions & 0 deletions lib/wallet/api/http/Cardano/Wallet/Api/Http/Shelley/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ module Cardano.Wallet.Api.Http.Shelley.Server

-- * Logging
, WalletEngineLog (..)
, walletListenFromEnv
)
where

Expand Down Expand Up @@ -660,6 +661,8 @@ import Servant
( Application, NoContent (..), err400, err404, err500, serve )
import Servant.Server
( Handler (..), runHandler )
import System.Exit
( die )
import System.IO.Error
( ioeGetErrorType
, isAlreadyInUseError
Expand Down Expand Up @@ -717,6 +720,16 @@ import qualified Network.Wai.Handler.Warp as Warp
import qualified Network.Wai.Handler.WarpTLS as Warp



-- | Allow configuring which port the wallet server listen to in an integration
-- setup. Crashes if the variable is not a number.
walletListenFromEnv :: Show e
=> (String -> IO (Maybe (Either e Port))) -> IO Listen
walletListenFromEnv envFromText = envFromText "CARDANO_WALLET_PORT" >>= \case
Nothing -> pure ListenOnRandomPort
Just (Right port) -> pure $ ListenOnPort port
Just (Left e) -> die $ show e

-- | How the server should listen for incoming requests.
data Listen
= ListenOnPort Port
Expand Down
5 changes: 3 additions & 2 deletions lib/wallet/bench/latency-bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import Cardano.Mnemonic
( Mnemonic, SomeMnemonic (..), mnemonicToText )
import Cardano.Startup
( withUtf8Encoding )
import Cardano.Wallet.Api.Http.Shelley.Server
( Listen (ListenOnRandomPort) )
import Cardano.Wallet.Api.Types
( ApiAddressWithPath
, ApiAsset (..)
Expand Down Expand Up @@ -58,7 +60,6 @@ import Cardano.Wallet.Launch.Cluster
, LogFileConfig (..)
, RunningNode (..)
, defaultPoolConfigs
, walletListenFromEnv
, withCluster
)
import Cardano.Wallet.Logging
Expand Down Expand Up @@ -506,7 +507,7 @@ withShelleyServer tracers action = do
}

onClusterStart act db (RunningNode conn block0 (np, vData) _) = do
listen <- walletListenFromEnv
let listen = ListenOnRandomPort
serveWallet
(NodeSource conn vData (SyncTolerance 10))
np
Expand Down
1 change: 0 additions & 1 deletion lib/wallet/cardano-wallet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,6 @@ library cardano-wallet-local-cluster
, cardano-ledger-core
, cardano-ledger-shelley
, cardano-wallet
, cardano-wallet-api-http
, cardano-wallet-launcher
, cardano-wallet-primitive
, cardano-wallet-test-utils
Expand Down
10 changes: 6 additions & 4 deletions lib/wallet/exe/cardano-wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Cardano.BM.Trace
import Cardano.CLI
( LogOutput (..)
, LoggingOptions
, Mode (..)
, cli
, cmdAddress
, cmdKey
Expand All @@ -54,6 +55,7 @@ import Cardano.CLI
, loggingOptions
, loggingSeverityOrOffReader
, loggingTracers
, modeOption
, poolMetadataSourceOption
, runCli
, setupDirectory
Expand All @@ -78,10 +80,10 @@ import Cardano.Wallet.Api.Client
import Cardano.Wallet.Api.Http.Shelley.Server
( HostPreference, Listen (..), TlsConfiguration )
import Cardano.Wallet.Launch
( Mode (Normal)
( CardanoNodeConn
, NetworkConfiguration (..)
, modeOption
, networkConfigurationOption
, nodeSocketOption
, parseGenesisData
)
import Cardano.Wallet.Logging
Expand Down Expand Up @@ -178,7 +180,7 @@ beforeMainLoop tr = logInfo tr . MsgListenAddress
-- | Arguments for the 'serve' command
data ServeArgs = ServeArgs
{ _hostPreference :: HostPreference
, _mode :: Mode
, _mode :: Mode CardanoNodeConn
, _listen :: Listen
, _tlsConfig :: Maybe TlsConfiguration
, _networkConfiguration :: NetworkConfiguration
Expand All @@ -197,7 +199,7 @@ cmdServe = command "serve" $ info (helper <*> helper' <*> cmd) $

cmd = fmap exec $ ServeArgs
<$> hostPreferenceOption
<*> modeOption
<*> modeOption nodeSocketOption
<*> listenOption
<*> optional tlsOption
<*> networkConfigurationOption
Expand Down
Loading

0 comments on commit 82f1ed4

Please sign in to comment.