Merge pull request #449 from input-output-hk/SCP-5012
SCP-5012 Upgrade `marlowe-apps` to use `marlowe-sync`
SCP-5012 Upgrade `marlowe-apps` to use `marlowe-sync`
Usage: marlowe-finder [--chain-seek-host HOST_NAME]
[--chain-seek-command-port PORT_NUMBER]
[--chain-seek-query-port PORT_NUMBER]
[--chain-seek-sync-port PORT_NUMBER]
[--history-host HOST_NAME]
[--history-command-port PORT_NUMBER]
[--history-query-port PORT_NUMBER]
[--history-sync-port PORT_NUMBER]
[--discovery-host HOST_NAME]
[--discovery-query-port PORT_NUMBER]
[--discovery-sync-port PORT_NUMBER] [--tx-host HOST_NAME]
[--tx-command-port PORT_NUMBER]
[--marlowe-sync-host HOST_NAME]
[--marlowe-sync-port PORT_NUMBER]
[--marlowe-header-sync-port PORT_NUMBER]
[--marlowe-query-sync-port PORT_NUMBER]
[--tx-host HOST_NAME] [--tx-command-port PORT_NUMBER]
[--timeout-seconds INTEGER] [--build-seconds INTEGER]
[--confirm-seconds INTEGER] [--retry-seconds INTEGER]
[--retry-limit INTEGER] [--polling SECONDS]
--chain-seek-host HOST_NAME
The hostname of the Marlowe Runtime chain-seek
server. Can be set as the environment variable
MARLOWE_RT_CHAINSEEK_HOST (default: "127.0.0.1")
MARLOWE_CHAINSEEKD_HOST (default: "127.0.0.1")
--chain-seek-command-port PORT_NUMBER
The port number of the chain-seek server's job API.
Can be set as the environment variable
MARLOWE_RT_CHAINSEEK_COMMAND_PORT (default: 3720)
--chain-seek-query-port PORT_NUMBER
The port number of the chain-seek server's query API.
Can be set as the environment variable
MARLOWE_RT_CHAINSEEK_QUERY_PORT (default: 3716)
MARLOWE_CHAINSEEKD_COMMAND_PORT (default: 3720)
--chain-seek-sync-port PORT_NUMBER
The port number of the chain-seek server's
synchronization API. Can be set as the environment
variable MARLOWE_RT_CHAINSEEK_SYNC_PORT
(default: 3715)
--history-host HOST_NAME The hostname of the Marlowe Runtime history server.
Can be set as the environment variable
MARLOWE_RT_HISTORY_HOST (default: "127.0.0.1")
--history-command-port PORT_NUMBER
The port number of the history server's job API. Can
be set as the environment variable
MARLOWE_RT_HISTORY_COMMAND_PORT (default: 3717)
--history-query-port PORT_NUMBER
The port number of the history server's query API.
Can be set as the environment variable
MARLOWE_RT_HISTORY_QUERY_PORT (default: 3718)
--history-sync-port PORT_NUMBER
The port number of the history server's
variable MARLOWE_CHAINSEEKD_PORT (default: 3715)
--marlowe-sync-host HOST_NAME
The hostname of the Marlowe Runtime marlowe-sync
server. Can be set as the environment variable
MARLOWE_RT_SYNC_HOST (default: "127.0.0.1")
--marlowe-sync-port PORT_NUMBER
The port number of the marlowe-sync server's
synchronization API. Can be set as the environment
variable MARLOWE_RT_HISTORY_SYNC_PORT (default: 3719)
--discovery-host HOST_NAME
The hostname of the Marlowe Runtime discovery server.
Can be set as the environment variable
MARLOWE_RT_DISCOVERY_HOST (default: "127.0.0.1")
--discovery-query-port PORT_NUMBER
The port number of the discovery server's query API.
Can be set as the environment variable
MARLOWE_RT_DISCOVERY_QUERY_PORT (default: 3721)
--discovery-sync-port PORT_NUMBER
The port number of the discovery server's
variable MARLOWE_RT_SYNC_MARLOWE_SYNC_PORT
(default: 3724)
--marlowe-header-sync-port PORT_NUMBER
The port number of the marlowe-sync server's header
synchronization API. Can be set as the environment
variable MARLOWE_RT_DISCOVERY_SYNC_PORT
(default: 3722)
variable MARLOWE_RT_SYNC_HEADER_SYNC_PORT
(default: 3725)
--marlowe-query-sync-port PORT_NUMBER
The port number of the marlowe-sync server's query
API. Can be set as the environment variable
MARLOWE_RT_SYNC_QUERY_SYNC_PORT (default: 3726)
--tx-host HOST_NAME The hostname of the Marlowe Runtime transaction
server. Can be set as the environment variable
MARLOWE_RT_TX_HOST (default: "127.0.0.1")
Usage: marlowe-oracle [--chain-seek-host HOST_NAME]
[--chain-seek-command-port PORT_NUMBER]
[--chain-seek-query-port PORT_NUMBER]
[--chain-seek-sync-port PORT_NUMBER]
[--history-host HOST_NAME]
[--history-command-port PORT_NUMBER]
[--history-query-port PORT_NUMBER]
[--history-sync-port PORT_NUMBER]
[--discovery-host HOST_NAME]
[--discovery-query-port PORT_NUMBER]
[--discovery-sync-port PORT_NUMBER] [--tx-host HOST_NAME]
[--tx-command-port PORT_NUMBER]
[--marlowe-sync-host HOST_NAME]
[--marlowe-sync-port PORT_NUMBER]
[--marlowe-header-sync-port PORT_NUMBER]
[--marlowe-query-sync-port PORT_NUMBER]
[--tx-host HOST_NAME] [--tx-command-port PORT_NUMBER]
[--timeout-seconds INTEGER] [--build-seconds INTEGER]
[--confirm-seconds INTEGER] [--retry-seconds INTEGER]
[--retry-limit INTEGER] [--polling SECONDS]
--chain-seek-host HOST_NAME
The hostname of the Marlowe Runtime chain-seek
server. Can be set as the environment variable
MARLOWE_RT_CHAINSEEK_HOST (default: "127.0.0.1")
MARLOWE_CHAINSEEKD_HOST (default: "127.0.0.1")
--chain-seek-command-port PORT_NUMBER
The port number of the chain-seek server's job API.
Can be set as the environment variable
MARLOWE_RT_CHAINSEEK_COMMAND_PORT (default: 3720)
--chain-seek-query-port PORT_NUMBER
The port number of the chain-seek server's query API.
Can be set as the environment variable
MARLOWE_RT_CHAINSEEK_QUERY_PORT (default: 3716)
MARLOWE_CHAINSEEKD_COMMAND_PORT (default: 3720)
--chain-seek-sync-port PORT_NUMBER
The port number of the chain-seek server's
synchronization API. Can be set as the environment
variable MARLOWE_RT_CHAINSEEK_SYNC_PORT
(default: 3715)
--history-host HOST_NAME The hostname of the Marlowe Runtime history server.
Can be set as the environment variable
MARLOWE_RT_HISTORY_HOST (default: "127.0.0.1")
--history-command-port PORT_NUMBER
The port number of the history server's job API. Can
be set as the environment variable
MARLOWE_RT_HISTORY_COMMAND_PORT (default: 3717)
--history-query-port PORT_NUMBER
The port number of the history server's query API.
Can be set as the environment variable
MARLOWE_RT_HISTORY_QUERY_PORT (default: 3718)
--history-sync-port PORT_NUMBER
The port number of the history server's
variable MARLOWE_CHAINSEEKD_PORT (default: 3715)
--marlowe-sync-host HOST_NAME
The hostname of the Marlowe Runtime marlowe-sync
server. Can be set as the environment variable
MARLOWE_RT_SYNC_HOST (default: "127.0.0.1")
--marlowe-sync-port PORT_NUMBER
The port number of the marlowe-sync server's
synchronization API. Can be set as the environment
variable MARLOWE_RT_HISTORY_SYNC_PORT (default: 3719)
--discovery-host HOST_NAME
The hostname of the Marlowe Runtime discovery server.
Can be set as the environment variable
MARLOWE_RT_DISCOVERY_HOST (default: "127.0.0.1")
--discovery-query-port PORT_NUMBER
The port number of the discovery server's query API.
Can be set as the environment variable
MARLOWE_RT_DISCOVERY_QUERY_PORT (default: 3721)
--discovery-sync-port PORT_NUMBER
The port number of the discovery server's
variable MARLOWE_RT_SYNC_MARLOWE_SYNC_PORT
(default: 3724)
--marlowe-header-sync-port PORT_NUMBER
The port number of the marlowe-sync server's header
synchronization API. Can be set as the environment
variable MARLOWE_RT_DISCOVERY_SYNC_PORT
(default: 3722)
variable MARLOWE_RT_SYNC_HEADER_SYNC_PORT
(default: 3725)
--marlowe-query-sync-port PORT_NUMBER
The port number of the marlowe-sync server's query
API. Can be set as the environment variable
MARLOWE_RT_SYNC_QUERY_SYNC_PORT (default: 3726)
--tx-host HOST_NAME The hostname of the Marlowe Runtime transaction
server. Can be set as the environment variable
MARLOWE_RT_TX_HOST (default: "127.0.0.1")
Usage: marlowe-scaling [--chain-seek-host HOST_NAME]
[--chain-seek-command-port PORT_NUMBER]
[--chain-seek-query-port PORT_NUMBER]
[--chain-seek-sync-port PORT_NUMBER]
[--history-host HOST_NAME]
[--history-command-port PORT_NUMBER]
[--history-query-port PORT_NUMBER]
[--history-sync-port PORT_NUMBER]
[--discovery-host HOST_NAME]
[--discovery-query-port PORT_NUMBER]
[--discovery-sync-port PORT_NUMBER] [--tx-host HOST_NAME]
[--tx-command-port PORT_NUMBER]
[--marlowe-sync-host HOST_NAME]
[--marlowe-sync-port PORT_NUMBER]
[--marlowe-header-sync-port PORT_NUMBER]
[--marlowe-query-sync-port PORT_NUMBER]
[--tx-host HOST_NAME] [--tx-command-port PORT_NUMBER]
[--timeout-seconds INTEGER] [--build-seconds INTEGER]
[--confirm-seconds INTEGER] [--retry-seconds INTEGER]
[--retry-limit INTEGER] NATURAL [ADDRESS=KEYFILE]
--chain-seek-host HOST_NAME
The hostname of the Marlowe Runtime chain-seek
server. Can be set as the environment variable
MARLOWE_RT_CHAINSEEK_HOST (default: "127.0.0.1")
MARLOWE_CHAINSEEKD_HOST (default: "127.0.0.1")
--chain-seek-command-port PORT_NUMBER
The port number of the chain-seek server's job API.
Can be set as the environment variable
MARLOWE_RT_CHAINSEEK_COMMAND_PORT (default: 3720)
--chain-seek-query-port PORT_NUMBER
The port number of the chain-seek server's query API.
Can be set as the environment variable
MARLOWE_RT_CHAINSEEK_QUERY_PORT (default: 3716)
MARLOWE_CHAINSEEKD_COMMAND_PORT (default: 3720)
--chain-seek-sync-port PORT_NUMBER
The port number of the chain-seek server's
synchronization API. Can be set as the environment
variable MARLOWE_RT_CHAINSEEK_SYNC_PORT
(default: 3715)
--history-host HOST_NAME The hostname of the Marlowe Runtime history server.
Can be set as the environment variable
MARLOWE_RT_HISTORY_HOST (default: "127.0.0.1")
--history-command-port PORT_NUMBER
The port number of the history server's job API. Can
be set as the environment variable
MARLOWE_RT_HISTORY_COMMAND_PORT (default: 3717)
--history-query-port PORT_NUMBER
The port number of the history server's query API.
Can be set as the environment variable
MARLOWE_RT_HISTORY_QUERY_PORT (default: 3718)
--history-sync-port PORT_NUMBER
The port number of the history server's
variable MARLOWE_CHAINSEEKD_PORT (default: 3715)
--marlowe-sync-host HOST_NAME
The hostname of the Marlowe Runtime marlowe-sync
server. Can be set as the environment variable
MARLOWE_RT_SYNC_HOST (default: "127.0.0.1")
--marlowe-sync-port PORT_NUMBER
The port number of the marlowe-sync server's
synchronization API. Can be set as the environment
variable MARLOWE_RT_HISTORY_SYNC_PORT (default: 3719)
--discovery-host HOST_NAME
The hostname of the Marlowe Runtime discovery server.
Can be set as the environment variable
MARLOWE_RT_DISCOVERY_HOST (default: "127.0.0.1")
--discovery-query-port PORT_NUMBER
The port number of the discovery server's query API.
Can be set as the environment variable
MARLOWE_RT_DISCOVERY_QUERY_PORT (default: 3721)
--discovery-sync-port PORT_NUMBER
The port number of the discovery server's
variable MARLOWE_RT_SYNC_MARLOWE_SYNC_PORT
(default: 3724)
--marlowe-header-sync-port PORT_NUMBER
The port number of the marlowe-sync server's header
synchronization API. Can be set as the environment
variable MARLOWE_RT_DISCOVERY_SYNC_PORT
(default: 3722)
variable MARLOWE_RT_SYNC_HEADER_SYNC_PORT
(default: 3725)
--marlowe-query-sync-port PORT_NUMBER
The port number of the marlowe-sync server's query
API. Can be set as the environment variable
MARLOWE_RT_SYNC_QUERY_SYNC_PORT (default: 3726)
--tx-host HOST_NAME The hostname of the Marlowe Runtime transaction
server. Can be set as the environment variable
MARLOWE_RT_TX_HOST (default: "127.0.0.1")
cabal-version : 3.0
name : marlowe-apps
version : 0.2.1.0
version : 0.2.2.1
synopsis : Marlowe Runtimee applications
license : Apache-2.0
license-file : LICENSE
, marlowe-runtime:config
, marlowe-runtime:discovery-api
, marlowe-runtime:history-api
, marlowe-runtime:sync-api
, marlowe-runtime:tx-api
, marlowe-runtime
, monad-control
-Wunused-packages
default-language : Haskell2010
executable marlowe-scaling
main-is : Main.hs
hs-source-dirs : scaling
<$> configParser
<*> O.option O.auto (O.long "polling" <> O.value 5_000_000 <> O.metavar "SECONDS" <> O.help "The polling frequency for waiting on Marlowe Runtime.")
<*> O.option O.auto (O.long "requeue" <> O.value 20_000_000 <> O.metavar "SECONDS" <> O.help "The requeuing frequency for reviewing the progress of contracts on Marlowe Runtime.")
<*> (O.argument addressParser) (O.metavar "ADDRESS" <> O.help "The Bech32 address of the oracle.")
<*> O.argument addressParser (O.metavar "ADDRESS" <> O.help "The Bech32 address of the oracle.")
<*> O.strArgument (O.metavar "KEYFILE" <> O.help "The extended payment signing key file for the oracle.")
pure
$ O.info
import Data.Bifunctor (second)
import Data.Either (fromRight)
import Language.Marlowe.Runtime.App.Build (buildApplication, buildCreation, buildWithdrawal)
import Language.Marlowe.Runtime.App.List
(allContracts, followContract, followedContracts, getContract, unfollowContract)
import Language.Marlowe.Runtime.App.List (allContracts, allHeaders, getContract)
import Language.Marlowe.Runtime.App.Run (runClientWithConfig)
import Language.Marlowe.Runtime.App.Sign (sign)
import Language.Marlowe.Runtime.App.Submit (submit, waitForTx)
let
run =
case request of
List -> Right . Contracts <$> allContracts
Followed -> Right . Contracts <$> followedContracts
Follow{..} -> fmap FollowResult <$> followContract reqContractId
Unfollow{..} -> fmap FollowResult <$> unfollowContract reqContractId
ListContracts -> Right . Contracts <$> allContracts
ListHeaders -> Right . Headers <$> allHeaders
Get{..} -> fmap (uncurry Info) <$> getContract reqContractId
Create{..} -> second (uncurry mkBody) <$> buildCreation MarloweV1 reqContract reqRoles reqMinUtxo reqMetadata reqAddresses reqChange reqCollateral
Apply{..} -> second (uncurry mkBody) <$> buildApplication MarloweV1 reqContractId reqInputs reqValidityLowerBound reqValidityUpperBound reqMetadata reqAddresses reqChange reqCollateral
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Language.Marlowe.Runtime.App.List
( allContracts
, followContract
, followedContracts
, allHeaders
, getContract
, unfollowContract
) where
import Data.Bifunctor (first)
import Data.Type.Equality ((:~:)(Refl))
import Data.Void (Void, absurd)
import Language.Marlowe.Runtime.App.Run (runJobClient, runMarloweSyncClient, runQueryClient)
import Language.Marlowe.Runtime.App.Run (runMarloweSyncClient, runQueryClient)
import Language.Marlowe.Runtime.App.Types (Client, Services(..))
import Language.Marlowe.Runtime.Core.Api (ContractId, IsMarloweVersion(..), MarloweVersion, assertVersionsEqual)
import Language.Marlowe.Runtime.Discovery.Api (ContractHeader(contractId), DiscoveryQuery(..))
import Language.Marlowe.Runtime.History.Api (ContractStep, CreateStep, HistoryCommand(..), HistoryQuery(..))
import Network.Protocol.Job.Client (liftCommand)
import Language.Marlowe.Runtime.Discovery.Api (ContractHeader(contractId))
import Language.Marlowe.Runtime.History.Api (ContractStep, CreateStep)
import qualified Data.Map as M (keys)
import qualified Language.Marlowe.Protocol.Query.Client as Query
import qualified Language.Marlowe.Protocol.Query.Types as Query
import qualified Language.Marlowe.Protocol.Sync.Client as Sync
( ClientStFollow(ClientStFollow, recvMsgContractFound, recvMsgContractNotFound)
, ClientStIdle(SendMsgDone, SendMsgRequestNext)
, ClientStWait(SendMsgCancel)
, MarloweSyncClient(MarloweSyncClient)
)
import qualified Network.Protocol.Query.Client as Query
( ClientStInit(SendMsgRequest)
, ClientStNext(ClientStNext)
, ClientStNextCanReject(..)
, ClientStPage(..)
, QueryClient(QueryClient)
)
allContracts :: Client [ContractId]
allContracts = listContracts GetContractHeaders runDiscoveryQueryClient $ fmap contractId
allContracts = listContracts runSyncQueryClient $ fmap contractId
allHeaders :: Client [ContractHeader]
allHeaders = listContracts runSyncQueryClient id
followedContracts :: Client [ContractId]
followedContracts = listContracts GetFollowedContracts runHistoryQueryClient M.keys
pageSize :: Int
pageSize = 1024
listContracts
:: Monoid a
=> query delimiter Void results
-> (Services IO -> Query.QueryClient query IO a -> IO a)
-> (results -> a)
=> (Services IO -> Query.MarloweQueryClient IO (Query.Page ContractId ContractHeader) -> IO (Query.Page ContractId ContractHeader))
-> ([ContractHeader] -> a)
-> Client a
listContracts query run extract =
listContracts run =
let
handleNextPage previous results nextPage =
bundleContracts getContractHeaders extract =
let
cumulative = previous <> extract results
append = (. getContractHeaders) . (=<<) . handleNextPage
handleNextPage previous Query.Page{..} =
let
cumulative = previous <> extract items
in
case nextRange of
Nothing -> pure cumulative
Just range -> cumulative `append` range
in
pure
$ maybe
(Query.SendMsgDone cumulative)
(flip Query.SendMsgRequestNext . Query.ClientStNext $ handleNextPage cumulative)
nextPage
mempty `append` Query.Range Nothing 0 pageSize Query.Ascending
in
runQueryClient run
. Query.QueryClient
. pure
$ Query.SendMsgRequest query Query.ClientStNextCanReject
{ Query.recvMsgReject = absurd
, Query.recvMsgNextPage = handleNextPage mempty
}
followContract :: ContractId -> Client (Either String Bool)
followContract = followCommand FollowContract
unfollowContract :: ContractId -> Client (Either String Bool)
unfollowContract = followCommand StopFollowingContract
followCommand
:: Show e
=> (ContractId -> HistoryCommand Void e Bool)
-> ContractId
-> Client (Either String Bool)
followCommand command =
fmap (first show)
. runJobClient runHistoryCommandClient
. liftCommand
. command
bundleContracts
$ runQueryClient run . Query.getContractHeaders
getContract
$ Right (create, previous)
}
in
runMarloweSyncClient runHistorySyncClient
runMarloweSyncClient runSyncSyncClient
. Sync.MarloweSyncClient
. pure
$ Sync.SendMsgFollowContract contractId' Sync.ClientStFollow
import Data.Default (def)
import Language.Marlowe.Runtime.App.Types
(Config(Config, buildSeconds, confirmSeconds, retryLimit, retrySeconds, timeoutSeconds))
import Language.Marlowe.Runtime.CLI.Option (CliOption, host, optParserWithEnvDefault, port)
import Language.Marlowe.Runtime.CLI.Option (CliOption, optParserWithEnvDefault)
import Language.Marlowe.Runtime.ChainSync.Api (Address, fromBech32)
import Network.Socket (HostName, PortNumber)
import Text.Read (readMaybe)
import qualified Data.Text as T (pack)
import qualified Language.Marlowe.Runtime.CLI.Option as CLI
do
chainSeekHostParser <- optParserWithEnvDefault chainSeekHost
chainSeekCommandPortParser <- optParserWithEnvDefault chainSeekCommandPort
chainSeekQueryPortParser <- optParserWithEnvDefault chainSeekQueryPort
chainSeekSyncPortParser <- optParserWithEnvDefault chainSeekSyncPort
historyHostParser <- optParserWithEnvDefault CLI.historyHost
historyCommandPortParser <- optParserWithEnvDefault CLI.historyCommandPort
historyQueryPortParser <- optParserWithEnvDefault CLI.historyQueryPort
historySyncPortParser <- optParserWithEnvDefault CLI.historySyncPort
discoveryHostParser <- optParserWithEnvDefault CLI.discoveryHost
discoveryQueryPortParser <- optParserWithEnvDefault CLI.discoveryQueryPort
discoverySyncPortParser <- optParserWithEnvDefault CLI.discoverySyncPort
syncHostParser <- optParserWithEnvDefault CLI.syncHost
syncSyncPortParser <- optParserWithEnvDefault CLI.syncSyncPort
syncHeaderPortParser <- optParserWithEnvDefault CLI.syncHeaderPort
syncQueryPortParser <- optParserWithEnvDefault CLI.syncQueryPort
txHostParser <- optParserWithEnvDefault CLI.txHost
txCommandPortParser <- optParserWithEnvDefault CLI.txCommandPort
let
$ Config
<$> chainSeekHostParser
<*> chainSeekCommandPortParser
<*> chainSeekQueryPortParser
<*> chainSeekSyncPortParser
<*> historyHostParser
<*> historyCommandPortParser
<*> historyQueryPortParser
<*> historySyncPortParser
<*> discoveryHostParser
<*> discoveryQueryPortParser
<*> discoverySyncPortParser
<*> syncHostParser
<*> syncSyncPortParser
<*> syncHeaderPortParser
<*> syncQueryPortParser
<*> txHostParser
<*> txCommandPortParser
<*> timeoutSecondsParser
<*> retryLimitParser
chainSeekHost :: CliOption O.OptionFields HostName
chainSeekHost = host "chain-seek" "CHAINSEEK" "127.0.0.1" "The hostname of the Marlowe Runtime chain-seek server."
host' :: String -> String -> HostName -> String -> CliOption O.OptionFields HostName
host' optPrefix envPrefix defaultValue description = CLI.CliOption
{ CLI.env = env
, CLI.parseEnv = Just
, CLI.parser = O.strOption . (<>) (mconcat
[ O.long $ optPrefix <> "-host"
, O.value defaultValue
, O.metavar "HOST_NAME"
, O.help $ description <> " Can be set as the environment variable " <> env
, O.showDefault
])
}
where
env = "MARLOWE_" <> envPrefix <> "_HOST"
port' :: String -> String -> PortNumber -> String -> CliOption O.OptionFields PortNumber
port' optPrefix envPrefix defaultValue description = CLI.CliOption
{ CLI.env = env
, CLI.parseEnv = readMaybe
, CLI.parser = O.option O.auto . (<>) (mconcat
[ O.long $ optPrefix <> "-port"
, O.value defaultValue
, O.metavar "PORT_NUMBER"
, O.help $ description <> " Can be set as the environment variable " <> env
, O.showDefault
])
}
where
env = "MARLOWE_" <> envPrefix <> "_PORT"
chainSeekCommandPort :: CliOption O.OptionFields PortNumber
chainSeekCommandPort = port "chain-seek-command" "CHAINSEEK_COMMAND" 3720 "The port number of the chain-seek server's job API."
chainSeekHost :: CliOption O.OptionFields HostName
chainSeekHost = host' "chain-seek" "CHAINSEEKD" "127.0.0.1" "The hostname of the Marlowe Runtime chain-seek server."
chainSeekQueryPort :: CliOption O.OptionFields PortNumber
chainSeekQueryPort = port "chain-seek-query" "CHAINSEEK_QUERY" 3716 "The port number of the chain-seek server's query API."
chainSeekCommandPort :: CliOption O.OptionFields PortNumber
chainSeekCommandPort = port' "chain-seek-command" "CHAINSEEKD_COMMAND" 3720 "The port number of the chain-seek server's job API."
chainSeekSyncPort :: CliOption O.OptionFields PortNumber
chainSeekSyncPort = port "chain-seek-sync" "CHAINSEEK_SYNC" 3715 "The port number of the chain-seek server's synchronization API."
chainSeekSyncPort = port' "chain-seek-sync" "CHAINSEEKD" 3715 "The port number of the chain-seek server's synchronization API."
addressParser :: O.ReadM Address
import Language.Marlowe.Protocol.HeaderSync.Client
(MarloweHeaderSyncClient, hoistMarloweHeaderSyncClient, marloweHeaderSyncClientPeer)
import Language.Marlowe.Protocol.HeaderSync.Codec (codecMarloweHeaderSync)
import Language.Marlowe.Protocol.Query.Client (MarloweQueryClient, hoistMarloweQueryClient, marloweQueryClientPeer)
import Language.Marlowe.Protocol.Query.Codec (codecMarloweQuery)
import Language.Marlowe.Protocol.Sync.Client (MarloweSyncClient, hoistMarloweSyncClient, marloweSyncClientPeer)
import Language.Marlowe.Protocol.Sync.Codec (codecMarloweSync)
import Language.Marlowe.Runtime.App.Types (Client(..), Config(..), RunClient, Services(..))
import Network.Protocol.Driver (mkDriver)
import Network.Protocol.Job.Client (JobClient, hoistJobClient, jobClientPeer)
import Network.Protocol.Job.Codec (codecJob)
import Network.Protocol.Query.Client (QueryClient, hoistQueryClient, queryClientPeer)
import Network.Protocol.Query.Codec (codecQuery)
import Network.Socket
(AddrInfo, SocketType(..), addrAddress, addrSocketType, close, connect, defaultHints, getAddrInfo, openSocket)
import Network.TypedProtocol (Driver(startDState), Peer, PeerRole(..), runPeerWithDriver)
import Network.TypedProtocol.Codec (Codec)
runQueryClient
:: (Services IO -> QueryClient q IO a -> IO a)
-> QueryClient q Client a
:: (Services IO -> MarloweQueryClient IO a -> IO a)
-> MarloweQueryClient Client a
-> Client a
runQueryClient query client =
do
services <- Client ask
liftBaseWith $ \runInBase -> query services $ hoistQueryClient runInBase client
liftBaseWith $ \runInBase -> query services $ hoistMarloweQueryClient runInBase client
runJobClient
-> IO a
runClientWithConfig Config{..} client = do
chainSeekCommandAddr <- resolve chainSeekHost chainSeekCommandPort
chainSeekQueryAddr <- resolve chainSeekHost chainSeekQueryPort
chainSeekSyncAddr <- resolve chainSeekHost chainSeekSyncPort
historyJobAddr <- resolve historyHost historyCommandPort
historyQueryAddr <- resolve historyHost historyQueryPort
historySyncAddr <- resolve historyHost historySyncPort
discoveryQueryAddr <- resolve discoveryHost discoveryQueryPort
discoverySyncAddr <- resolve discoveryHost discoverySyncPort
syncSyncAddr <- resolve syncHost syncSyncPort
syncHeaderAddr <- resolve syncHost syncHeaderPort
syncQueryAddr <- resolve syncHost syncQueryPort
txJobAddr <- resolve txHost txCommandPort
runReaderT (runClient client) Services
{ runChainSeekCommandClient = runClientPeerOverSocket chainSeekCommandAddr codecJob jobClientPeer
, runChainSeekQueryClient = runClientPeerOverSocket chainSeekQueryAddr codecQuery queryClientPeer
, runChainSeekSyncClient = runClientPeerOverSocket chainSeekSyncAddr codecChainSeek (chainSeekClientPeer Genesis)
, runHistoryCommandClient = runClientPeerOverSocket historyJobAddr codecJob jobClientPeer
, runHistoryQueryClient = runClientPeerOverSocket historyQueryAddr codecQuery queryClientPeer
, runHistorySyncClient = runClientPeerOverSocket historySyncAddr codecMarloweSync marloweSyncClientPeer
, runSyncSyncClient = runClientPeerOverSocket syncSyncAddr codecMarloweSync marloweSyncClientPeer
, runSyncHeaderClient = runClientPeerOverSocket syncHeaderAddr codecMarloweHeaderSync marloweHeaderSyncClientPeer
, runSyncQueryClient = runClientPeerOverSocket syncQueryAddr codecMarloweQuery marloweQueryClientPeer
, runTxCommandClient = runClientPeerOverSocket txJobAddr codecJob jobClientPeer
, runDiscoveryQueryClient = runClientPeerOverSocket discoveryQueryAddr codecQuery queryClientPeer
, runDiscoverySyncClient = runClientPeerOverSocket discoverySyncAddr codecMarloweHeaderSync marloweHeaderSyncClientPeer
}
where
resolve host port =
-> TChan a
-> Client (Either String ())
streamContractHeaders eventBackend pollingFrequency extract channel =
runMarloweHeaderSyncClient runDiscoverySyncClient
runMarloweHeaderSyncClient runSyncHeaderClient
$ streamContractHeadersClient eventBackend pollingFrequency extract channel
-> TChan (ContractStream v)
-> Client ()
streamContractSteps eventBackend pollingFrequency finishOnClose finishOnWait accept csContractId channel =
runMarloweSyncClient runHistorySyncClient
runMarloweSyncClient runSyncSyncClient
$ streamContractStepsClient eventBackend pollingFrequency finishOnClose finishOnWait accept csContractId channel
import Data.String (fromString)
import Language.Marlowe (POSIXTime(..))
import Language.Marlowe.Protocol.HeaderSync.Client (MarloweHeaderSyncClient)
import Language.Marlowe.Protocol.Query.Client (MarloweQueryClient)
import Language.Marlowe.Protocol.Sync.Client (MarloweSyncClient)
import Language.Marlowe.Runtime.Cardano.Api (fromCardanoTxId)
import Language.Marlowe.Runtime.ChainSync.Api
( Address
, ChainSyncCommand
, ChainSyncQuery
, Lovelace(..)
, RuntimeChainSeekClient
, TokenName
, TransactionScriptOutput(..)
, renderContractId
)
import Language.Marlowe.Runtime.Discovery.Api (DiscoveryQuery)
import Language.Marlowe.Runtime.Discovery.Api (ContractHeader)
import Language.Marlowe.Runtime.History.Api
(ContractStep(..), CreateStep(..), HistoryCommand, HistoryQuery, RedeemStep(RedeemStep, datum, redeemingTx, utxo))
(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
Config
{ chainSeekHost :: HostName
, chainSeekCommandPort :: PortNumber
, chainSeekQueryPort :: PortNumber
, chainSeekSyncPort :: PortNumber
, historyHost :: HostName
, historyCommandPort :: PortNumber
, historyQueryPort :: PortNumber
, historySyncPort :: PortNumber
, discoveryHost :: HostName
, discoveryQueryPort :: PortNumber
, discoverySyncPort :: PortNumber
, syncHost :: HostName
, syncSyncPort :: PortNumber
, syncHeaderPort :: PortNumber
, syncQueryPort :: PortNumber
, txHost :: HostName
, txCommandPort :: PortNumber
, timeoutSeconds :: Int
Config
{ chainSeekHost = "127.0.0.1"
, chainSeekCommandPort = 3720
, chainSeekQueryPort = 3716
, chainSeekSyncPort = 3715
, historyHost = "127.0.0.1"
, historyCommandPort = 3717
, historyQueryPort = 3718
, historySyncPort = 3719
, discoveryHost = "127.0.0.1"
, discoveryQueryPort = 3721
, discoverySyncPort = 3722
, syncHost = "127.0.0.1"
, syncSyncPort = 3724
, syncHeaderPort = 3725
, syncQueryPort = 3726
, txHost = "127.0.0.1"
, txCommandPort = 3723
, timeoutSeconds = 600
data Services m =
Services
{ runChainSeekCommandClient :: RunClient m (JobClient ChainSyncCommand)
, runChainSeekQueryClient :: RunClient m (QueryClient ChainSyncQuery)
, runChainSeekSyncClient :: RunClient m RuntimeChainSeekClient
, runHistoryCommandClient :: RunClient m (JobClient HistoryCommand)
, runHistoryQueryClient :: RunClient m (QueryClient HistoryQuery)
, runHistorySyncClient :: RunClient m MarloweSyncClient
, runDiscoveryQueryClient :: RunClient m (QueryClient DiscoveryQuery)
, runDiscoverySyncClient :: RunClient m MarloweHeaderSyncClient
, runSyncSyncClient :: RunClient m MarloweSyncClient
, runSyncHeaderClient :: RunClient m MarloweHeaderSyncClient
, runSyncQueryClient :: RunClient m MarloweQueryClient
, runTxCommandClient :: RunClient m (JobClient MarloweTxCommand)
}
data MarloweRequest v =
List
| Followed
| Follow
{ reqContractId :: ContractId
}
| Unfollow
{ reqContractId :: ContractId
}
ListContracts
| ListHeaders
| Get
{ reqContractId :: ContractId
}
$ \o ->
(o A..: "request" :: A.Parser String)
>>= \case
"list" -> pure List
"followed" -> pure Followed
"follow" -> do
reqContractId <- fromString <$> o A..: "contractId"
pure Follow{..}
"unfollow" -> do
reqContractId <- fromString <$> o A..: "contractId"
pure Unfollow{..}
"list" -> pure ListContracts
"headers" -> pure ListHeaders
"get" -> do
reqContractId <- fromString <$> o A..: "contractId"
pure Get{..}
request -> fail $ "Invalid request: " <> request <> "."
instance A.ToJSON (MarloweRequest 'V1) where
toJSON List = A.object ["request" A..= ("list" :: String)]
toJSON Followed = A.object ["request" A..= ("followed" :: String)]
toJSON Follow{..} =
A.object
[ "request" A..= ("follow" :: String)
, "contractId" A..= renderContractId reqContractId
]
toJSON Unfollow{..} =
A.object
[ "request" A..= ("unfollow" :: String)
, "contractId" A..= renderContractId reqContractId
]
toJSON ListContracts = A.object ["request" A..= ("list" :: String)]
toJSON ListHeaders = A.object ["request" A..= ("headers" :: String)]
toJSON Get{..} =
A.object
[ "request" A..= ("get" :: String)
Contracts
{ resContractIds :: [ContractId]
}
| Headers
{ resContractHeaders :: [ContractHeader]
}
| FollowResult
{ resResult :: Bool
}
[ "response" A..= ("contracts" :: String)
, "contractIds" A..= fmap renderContractId resContractIds
]
toJSON Headers{..} =
A.object
[ "response" A..= ("headers" :: String)
, "contractHeaders" A..= resContractHeaders
]
toJSON FollowResult{..} =
A.object
[ "response" A..= ("result" :: String)
, parser :: !(Mod f a -> Parser a)
}
syncHost :: CliOption OptionFields HostName
syncHost = host "marlowe-sync" "SYNC" "127.0.0.1" "The hostname of the Marlowe Runtime marlowe-sync server."
syncSyncPort :: CliOption OptionFields PortNumber
syncSyncPort = port "marlowe-sync" "SYNC_MARLOWE_SYNC" 3724 "The port number of the marlowe-sync server's synchronization API."
syncHeaderPort :: CliOption OptionFields PortNumber
syncHeaderPort = port "marlowe-header-sync" "SYNC_HEADER_SYNC" 3725 "The port number of the marlowe-sync server's header synchronization API."
syncQueryPort :: CliOption OptionFields PortNumber
syncQueryPort = port "marlowe-query-sync" "SYNC_QUERY_SYNC" 3726 "The port number of the marlowe-sync server's query API."
historyHost :: CliOption OptionFields HostName
historyHost = host "history" "HISTORY" "127.0.0.1" "The hostname of the Marlowe Runtime history server."
flags = {};
package = {
specVersion = "3.0";
identifier = { name = "marlowe-apps"; version = "0.2.1.0"; };
identifier = { name = "marlowe-apps"; version = "0.2.2.1"; };
license = "Apache-2.0";
copyright = "";
maintainer = "Brian W Bush <[email protected]>";
(hsPkgs."marlowe-runtime".components.sublibs.config or (errorHandler.buildDepError "marlowe-runtime:config"))
(hsPkgs."marlowe-runtime".components.sublibs.discovery-api or (errorHandler.buildDepError "marlowe-runtime:discovery-api"))
(hsPkgs."marlowe-runtime".components.sublibs.history-api or (errorHandler.buildDepError "marlowe-runtime:history-api"))
(hsPkgs."marlowe-runtime".components.sublibs.sync-api or (errorHandler.buildDepError "marlowe-runtime:sync-api"))
(hsPkgs."marlowe-runtime".components.sublibs.tx-api or (errorHandler.buildDepError "marlowe-runtime:tx-api"))
(hsPkgs."marlowe-runtime" or (errorHandler.buildDepError "marlowe-runtime"))
(hsPkgs."monad-control" or (errorHandler.buildDepError "monad-control"))
flags = {};
package = {
specVersion = "3.0";
identifier = { name = "marlowe-apps"; version = "0.2.1.0"; };
identifier = { name = "marlowe-apps"; version = "0.2.2.1"; };
license = "Apache-2.0";
copyright = "";
maintainer = "Brian W Bush <[email protected]>";
(hsPkgs."marlowe-runtime".components.sublibs.config or (errorHandler.buildDepError "marlowe-runtime:config"))
(hsPkgs."marlowe-runtime".components.sublibs.discovery-api or (errorHandler.buildDepError "marlowe-runtime:discovery-api"))
(hsPkgs."marlowe-runtime".components.sublibs.history-api or (errorHandler.buildDepError "marlowe-runtime:history-api"))
(hsPkgs."marlowe-runtime".components.sublibs.sync-api or (errorHandler.buildDepError "marlowe-runtime:sync-api"))
(hsPkgs."marlowe-runtime".components.sublibs.tx-api or (errorHandler.buildDepError "marlowe-runtime:tx-api"))
(hsPkgs."marlowe-runtime" or (errorHandler.buildDepError "marlowe-runtime"))
(hsPkgs."monad-control" or (errorHandler.buildDepError "monad-control"))
export MARLOWE_RT_SYNC_HOST=127.0.0.1
export MARLOWE_RT_SYNC_MARLOWE_SYNC_PORT=$(docker-compose port marlowe-sync 3724 | sed -e s/://)
export MARLOWE_RT_SYNC_MARLOWE_HEADER_SYNC_PORT=$(docker-compose port marlowe-sync 3725 | sed -e s/://)
export MARLOWE_RT_SYNC_MARLOWE_QUERY_SYNC_PORT=$(docker-compose port marlowe-sync 3726 | sed -e s/://)
export MARLOWE_RT_HISTORY_HOST=127.0.0.1
export MARLOWE_RT_HISTORY_SYNC_PORT=$(docker-compose port marlowe-history 3719 | sed -e s/://)