Skip to content

Commit

Permalink
SCP-5012 Migrated marlowe-pipe from marlowe-lambda repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
bwbush committed Feb 6, 2023
1 parent 21923f2 commit 284d36c
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
23 changes: 23 additions & 0 deletions marlowe-apps/marlowe-apps.cabal
Expand Up @@ -64,6 +64,29 @@ library
default-language : Haskell2010


executable marlowe-pipe
main-is : Main.hs
hs-source-dirs : pipe
build-depends : base >= 4.9 && < 5
, aeson
, bytestring
, eventuo11y
, eventuo11y-dsl
, eventuo11y-json
, marlowe-apps
, mtl
, optparse-applicative
, text
ghc-options : -Wall
-Wnoncanonical-monad-instances
-Wincomplete-uni-patterns
-Wincomplete-record-updates
-Wredundant-constraints
-Widentities
-Wunused-packages
default-language : Haskell2010


executable marlowe-scaling
main-is : Main.hs
hs-source-dirs : scaling
Expand Down
56 changes: 56 additions & 0 deletions marlowe-apps/pipe/Main.hs
@@ -0,0 +1,56 @@


{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}


module Main
( main
) where


import Control.Monad.Except (liftIO, runExceptT)
import Data.Aeson (eitherDecode, encode)
import Data.Text (Text)
import Language.Marlowe.Runtime.App.Parser (getConfigParser)
import Language.Marlowe.Runtime.App.Transact (handleWithEvents)
import Observe.Event (addField, hoistEvent, withEvent)
import Observe.Event.Dynamic (DynamicEventSelector(..))
import Observe.Event.Render.JSON (DefaultRenderSelectorJSON(defaultRenderSelectorJSON))
import Observe.Event.Render.JSON.Handle (simpleJsonStderrBackend)
import Observe.Event.Syntax ((≔))

import qualified Data.ByteString.Lazy.Char8 as LBS8 (getContents, lines, putStrLn, unpack)
import qualified Options.Applicative as O


main :: IO ()
main =
do
configParser <- getConfigParser
config <-
O.execParser
$ O.info
(O.helper {- <*> O.versionOption -} <*> configParser)
(
O.fullDesc
<> O.progDesc "This command-line tool reads lines of JSON from standard input, interpets them as Marlowe App requests, executes them, and prints the response JSON on standard output."
<> O.header "marlowe-pipe: run marlowe application requests"
)
eventBackend <- simpleJsonStderrBackend defaultRenderSelectorJSON
requests <- LBS8.lines <$> LBS8.getContents
sequence_
[
withEvent eventBackend (DynamicEventSelector "MarloweApp")
$ \event ->
do
addField event $ ("line" :: Text) LBS8.unpack line
case eitherDecode line of
Right request -> runExceptT (handleWithEvents (hoistEvent liftIO event) "Handle" config request pure)
>>= \case
Right response -> LBS8.putStrLn $ encode response
Left message -> LBS8.putStrLn $ encode message
Left message -> LBS8.putStrLn $ encode message
|
line <- requests
]
1 change: 0 additions & 1 deletion marlowe-apps/src/Language/Marlowe/Runtime/App/Types.hs
Expand Up @@ -64,7 +64,6 @@ import Language.Marlowe.Runtime.History.Api
(ContractStep(..), CreateStep(..), RedeemStep(RedeemStep, datum, redeemingTx, utxo))
import Language.Marlowe.Runtime.Transaction.Api (MarloweTxCommand)
import Network.Protocol.Job.Client (JobClient)
import Network.Protocol.Query.Client (QueryClient)
import Network.Socket (HostName, PortNumber)

import qualified Cardano.Api as C
Expand Down

0 comments on commit 284d36c

Please sign in to comment.