Skip to content

Commit 83f2a38

Browse files
Fix sandbox
run-full-compat: true
1 parent 09c043b commit 83f2a38

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

sdk/daml-assistant/daml-helper/src/DA/Daml/Helper/Main.hs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ commandParser = subparser $ fold
158158

159159
startCmd = do
160160
sandboxPortM <- sandboxPortOpt "sandbox-port" "Port number for the sandbox"
161-
jsonApiPortM <- jsonApiPortOpt "json-api-port" "Port that the HTTP JSON API should listen on or 'none' to disable it"
161+
jsonApiPort <- jsonApiPortOpt "json-api-port" "Port that the HTTP JSON API should listen on"
162162
onStartM <- optional (option str (long "on-start" <> metavar "COMMAND" <> help "Command to run once sandbox is running."))
163163
shouldWaitForSignal <- flagYesNoAuto "wait-for-signal" True "Wait for Ctrl+C or interrupt after starting servers." idm
164164
sandboxOptions <- many (strOption (long "sandbox-option" <> metavar "SANDBOX_OPTION" <> help "Pass option to sandbox"))
@@ -201,16 +201,13 @@ commandParser = subparser $ fold
201201
jsonApiPortOpt name desc = option
202202
readJsonApiPort
203203
( long name
204-
<> value (Just $ JsonApiPort 7575)
204+
<> value (JsonApiPort 7575)
205205
<> help desc
206206
)
207207

208-
readJsonApiPort = eitherReader $ \case
209-
"none" -> Right Nothing
210-
s -> maybe
211-
(Left $ "Failed to parse port " <> show s)
212-
(Right . Just . JsonApiPort)
213-
(readMaybe s)
208+
readJsonApiPort =
209+
eitherReader $ \s ->
210+
maybe (Left $ "Failed to parse port " <> show s) (Right . JsonApiPort) $ readMaybe s
214211

215212
codegenCmd = asum
216213
[ subparser $ fold
@@ -416,8 +413,8 @@ commandParser = subparser $ fold
416413
cantonSequencerPublicApi <- option auto (long "sequencer-public-port" <> value (sequencerPublic defaultSandboxPorts))
417414
cantonSequencerAdminApi <- option auto (long "sequencer-admin-port" <> value (sequencerAdmin defaultSandboxPorts))
418415
cantonMediatorAdminApi <- option auto (long "mediator-admin-port" <> value (mediatorAdmin defaultSandboxPorts))
419-
cantonJsonApi <- optional $ option auto (long "json-api-port"
420-
<> help "Port that the HTTP JSON API should listen on, omit to disable it")
416+
cantonJsonApi <- option auto (long "json-api-port"
417+
<> help "Port that the HTTP JSON API should listen on" <> value (jsonApi defaultSandboxPorts))
421418
cantonJsonApiPortFileM <- optional $ option str (long "json-api-port-file" <> metavar "PATH"
422419
<> help "File to write canton json-api port when ready")
423420
cantonPortFileM <- optional $ option str (long "canton-port-file" <> metavar "PATH"

sdk/daml-assistant/daml-helper/src/DA/Daml/Helper/Start.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ getPortForSandbox defaultPortSpec portSpecM =
5050
SpecifiedPort port -> pure (unSandboxPort port)
5151
FreePort -> fromIntegral <$> getFreePort
5252

53-
determineCantonOptions :: Maybe SandboxPortSpec -> SandboxCantonPortSpec -> FilePath -> Maybe JsonApiPort -> IO CantonOptions
53+
determineCantonOptions :: Maybe SandboxPortSpec -> SandboxCantonPortSpec -> FilePath -> JsonApiPort -> IO CantonOptions
5454
determineCantonOptions ledgerApiSpec SandboxCantonPortSpec{..} portFile jsonApi = do
5555
cantonLedgerApi <- getPortForSandbox (SpecifiedPort (SandboxPort (ledger defaultSandboxPorts))) ledgerApiSpec
5656
cantonAdminApi <- getPortForSandbox (SpecifiedPort (SandboxPort (admin defaultSandboxPorts))) adminApiSpec
@@ -61,7 +61,7 @@ determineCantonOptions ledgerApiSpec SandboxCantonPortSpec{..} portFile jsonApi
6161
let cantonStaticTime = StaticTime False
6262
let cantonHelp = False
6363
let cantonConfigFiles = []
64-
let cantonJsonApi = fmap unJsonApiPort jsonApi
64+
let cantonJsonApi = unJsonApiPort jsonApi
6565
let cantonJsonApiPortFileM = Nothing
6666
pure CantonOptions {..}
6767

@@ -71,7 +71,7 @@ withSandbox StartOptions{..} darPath sandboxArgs kont =
7171
where
7272
cantonSandbox = withTempDir $ \tempDir -> do
7373
let portFile = tempDir </> "sandbox-portfile"
74-
cantonOptions <- determineCantonOptions sandboxPortM sandboxPortSpec portFile jsonApiPortM
74+
cantonOptions <- determineCantonOptions sandboxPortM sandboxPortSpec portFile jsonApiPort
7575
putStrLn "Waiting for canton sandbox to start."
7676
withCantonSandbox cantonOptions sandboxArgs $ \(ph, sandboxPort) -> do
7777
runLedgerUploadDar (sandboxLedgerFlags sandboxPort) (DryRun False) (Just darPath)
@@ -93,7 +93,7 @@ withOptsFromPackageConfig fieldName cliOpts packageConfig = do
9393

9494
data StartOptions = StartOptions
9595
{ sandboxPortM :: Maybe SandboxPortSpec
96-
, jsonApiPortM :: Maybe JsonApiPort
96+
, jsonApiPort :: JsonApiPort
9797
, onStartM :: Maybe String
9898
, shouldWaitForSignal :: Bool
9999
, sandboxOptions :: [String]
@@ -141,7 +141,7 @@ runStart startOptions@StartOptions{..} =
141141
runProcess_ procScript
142142
doRunInitScript
143143
whenJust onStartM $ \onStart -> runProcess_ (shell onStart)
144-
whenJust jsonApiPortM $ \jsonApiPort -> waitForJsonApi sandboxPh jsonApiPort
144+
waitForJsonApi sandboxPh jsonApiPort
145145
printReadyInstructions
146146
when shouldWaitForSignal $
147147
void $ waitAnyCancel =<< mapM (async . waitExitCode) [sandboxPh]

sdk/daml-assistant/daml-helper/src/DA/Daml/Helper/Util.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,11 @@ data SandboxPorts = SandboxPorts
260260
, sequencerPublic :: Int
261261
, sequencerAdmin :: Int
262262
, mediatorAdmin :: Int
263+
, jsonApi :: Int
263264
}
264265

265266
defaultSandboxPorts :: SandboxPorts
266-
defaultSandboxPorts = SandboxPorts 6865 6866 6867 6868 6869
267+
defaultSandboxPorts = SandboxPorts 6865 6866 6867 6868 6869 6870
267268

268269
runCantonSandbox :: CantonOptions -> [String] -> IO ()
269270
runCantonSandbox options args = withCantonSandbox options args (const $ pure ())
@@ -337,7 +338,7 @@ data CantonOptions = CantonOptions
337338
, cantonStaticTime :: StaticTime
338339
, cantonHelp :: Bool
339340
, cantonConfigFiles :: [FilePath]
340-
, cantonJsonApi :: Maybe Int
341+
, cantonJsonApi :: Int
341342
, cantonJsonApiPortFileM :: Maybe FilePath
342343
}
343344

@@ -368,7 +369,7 @@ cantonConfig CantonOptions{..} =
368369
] <>
369370
[ "http-ledger-api" Aeson..= Aeson.object
370371
[ "server" Aeson..= Aeson.object ( concat
371-
[ [ "port" Aeson..= port | Just port <- [cantonJsonApi] ]
372+
[ [ "port" Aeson..= cantonJsonApi ]
372373
, [ "port-file" Aeson..= portFile | Just portFile <- [cantonJsonApiPortFileM] ]
373374
])
374375
]

0 commit comments

Comments
 (0)