diff --git a/README.md b/README.md index 3f74a26f..845b0392 100644 --- a/README.md +++ b/README.md @@ -29,12 +29,11 @@ spago test To start the server you can use the `npm run start` command, for example: ```bash -NETWORK="preview" MARLOWE_WEB_SERVER_URL="http://localhost:3780" npm run start +MARLOWE_WEB_SERVER_URL="http://localhost:3780" npm run start ``` In the previous example: -- `NETWORK`: Specifies the Cardano network to use. In the example above, it's set to `preview`. -- `MARLOWE_WEB_SERVER_URL`: Specifies URL for the Marlowe Runtime Web server of the network specified (`NETWORK`). +- `MARLOWE_WEB_SERVER_URL`: Specifies URL for the Marlowe Runtime Web server. After this, the Marlowe Runner instance should be available by default at: `http://localhost:8080/` diff --git a/packages.dhall b/packages.dhall index 2472a940..e8758862 100644 --- a/packages.dhall +++ b/packages.dhall @@ -309,6 +309,7 @@ in upstream , "effect" , "either" , "exceptions" + , "foreign-generic" , "foldable-traversable" , "js-object" , "js-promise-aff" @@ -331,7 +332,7 @@ in upstream "https://github.com/input-output-hk/purescript-cardano-wallet-client.git" "main" - with marlowe-runtime-client = + with marlowe-runtime-client = -- ./purescript-marlowe-runtime-client/spago.dhall as Location mkPackage [ "aff" , "aff-promise" diff --git a/spago.dhall b/spago.dhall index 34a932ce..391b133d 100644 --- a/spago.dhall +++ b/spago.dhall @@ -24,6 +24,7 @@ , "foldable-traversable" , "foreign-object" , "formatters" + , "free" , "functions" , "functors" , "halogen-subscriptions" diff --git a/src/Main.purs b/src/Main.purs index 318bc541..ee5969e7 100644 --- a/src/Main.purs +++ b/src/Main.purs @@ -12,6 +12,7 @@ import Contrib.JsonBigInt as JsonBigInt import Control.Monad.Reader (runReaderT) import Data.Argonaut (Json, decodeJson, (.:)) import Data.BigInt.Argonaut as BigInt +import Data.Either (Either(..)) import Data.Maybe (Maybe(..), fromJust, maybe) import Data.Tuple.Nested ((/\)) import Effect (Effect) @@ -19,8 +20,9 @@ import Effect.Aff (launchAff_) import Effect.Class (liftEffect) import Effect.Class.Console as Console import Effect.Exception (throw) +import JS.Unsafe.Stringify (unsafeStringify) import Marlowe.Runtime.Web as Marlowe.Runtime.Web -import Marlowe.Runtime.Web.Types (ServerURL(..)) +import Marlowe.Runtime.Web.Types (HealthCheck(..), NetworkId(..), ServerURL(..)) import Partial.Unsafe (unsafePartial) import React.Basic (createContext) import React.Basic.DOM.Client (createRoot, renderRoot) @@ -33,7 +35,6 @@ import Web.HTML.Window (document) type Config = { marloweWebServerUrl :: ServerURL , develMode :: Boolean - , network :: String , aboutMarkdown :: String } @@ -42,12 +43,10 @@ decodeConfig json = do obj <- decodeJson json marloweWebServerUrl <- obj .: "marloweWebServerUrl" develMode <- obj .: "develMode" - network <- obj .: "network" aboutMarkdown <- obj .: "aboutMarkdown" pure { marloweWebServerUrl: ServerURL marloweWebServerUrl , develMode - , network , aboutMarkdown } @@ -63,12 +62,7 @@ main configJson = do logger = if config.develMode then Console.log else const (pure unit) - runtime = Marlowe.Runtime.Web.runtime config.marloweWebServerUrl - -- FIXME: Slotting numbers have to be provided by Marlowe Runtime - slotting = - case config.network of - "mainnet" -> Slotting { slotLength: BigInt.fromInt 1000, slotZeroTime: unsafePartial $ fromJust $ BigInt.fromString "1591566291000" } - _ -> Slotting { slotLength: BigInt.fromInt 1000, slotZeroTime: unsafePartial $ fromJust $ BigInt.fromString "1666656000000" } + runtime@(Marlowe.Runtime.Web.Runtime { serverURL }) = Marlowe.Runtime.Web.runtime config.marloweWebServerUrl doc :: HTMLDocument <- document =<< window container :: Element <- maybe (throw "Could not find element with id 'app-root'") pure =<< @@ -76,6 +70,17 @@ main configJson = do reactRoot <- createRoot container launchAff_ do + HealthCheck { networkId } <- Marlowe.Runtime.Web.getHealthCheck serverURL >>= case _ of + Left err -> liftEffect $ throw $ unsafeStringify err + Right healthCheck -> pure healthCheck + + let + -- FIXME: Slotting numbers have to be provided by Marlowe Runtime + slotting = case networkId of + Mainnet -> Slotting { slotLength: BigInt.fromInt 1000, slotZeroTime: unsafePartial $ fromJust $ BigInt.fromString "1591566291000" } + _ -> Slotting { slotLength: BigInt.fromInt 1000, slotZeroTime: unsafePartial $ fromJust $ BigInt.fromString "1666656000000" } + + CardanoMultiplatformLib.importLib >>= case _ of Nothing -> liftEffect $ logger "Cardano serialization lib loading failed" Just cardanoMultiplatformLib -> do diff --git a/src/frontend.js b/src/frontend.js index c4c84527..d86544f4 100644 --- a/src/frontend.js +++ b/src/frontend.js @@ -11,7 +11,6 @@ import aboutMarkdown from "../public/about.md"; const config = { develMode: process.env.DEVEL_MODE, marloweWebServerUrl: process.env.MARLOWE_WEB_SERVER_URL, - network: process.env.NETWORK, aboutMarkdown: aboutMarkdown, }; diff --git a/webpack.js b/webpack.js index a57c52a9..fb76759b 100644 --- a/webpack.js +++ b/webpack.js @@ -21,19 +21,9 @@ function getWebServerUrl() { } }; -function getNetwork() { - if(!process.env.NETWORK) { - console.log("NETWORK not configured, defaulting to the 'preview' network. For explicitly setting the network, do : export NETWORK=preview"); - return "preview"; - } else { - return process.env.NETWORK; - } -}; - export default function(_env, argv) { const develMode = argv.mode == "development"; const webServerUrl = getWebServerUrl(); - const network = getNetwork(); return { experiments: { @@ -56,7 +46,6 @@ export default function(_env, argv) { new webpack.EnvironmentPlugin({ MARLOWE_WEB_SERVER_URL: webServerUrl, DEVEL_MODE: develMode, - NETWORK: network, }), ], output: {