Skip to content

Commit

Permalink
Drop NETWORK setup and use runtime provided network information
Browse files Browse the repository at this point in the history
  • Loading branch information
paluh committed Sep 15, 2023
1 parent a6da7c4 commit b1d206a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 26 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/`

Expand Down
3 changes: 2 additions & 1 deletion packages.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ in upstream
, "effect"
, "either"
, "exceptions"
, "foreign-generic"
, "foldable-traversable"
, "js-object"
, "js-promise-aff"
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
, "foldable-traversable"
, "foreign-object"
, "formatters"
, "free"
, "functions"
, "functors"
, "halogen-subscriptions"
Expand Down
25 changes: 15 additions & 10 deletions src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ 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)
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)
Expand All @@ -33,7 +35,6 @@ import Web.HTML.Window (document)
type Config =
{ marloweWebServerUrl :: ServerURL
, develMode :: Boolean
, network :: String
, aboutMarkdown :: String
}

Expand All @@ -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
}

Expand All @@ -63,19 +62,25 @@ 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 =<<
(getElementById "app-root" $ toNonElementParentNode doc)
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
Expand Down
1 change: 0 additions & 1 deletion src/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
11 changes: 0 additions & 11 deletions webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -56,7 +46,6 @@ export default function(_env, argv) {
new webpack.EnvironmentPlugin({
MARLOWE_WEB_SERVER_URL: webServerUrl,
DEVEL_MODE: develMode,
NETWORK: network,
}),
],
output: {
Expand Down

0 comments on commit b1d206a

Please sign in to comment.