Skip to content

Commit d8b5940

Browse files
author
Jamie Bertram
authored
Merge pull request #505 from input-output-hk/scp-5010-cli-proxy
SCP-5010 Update `marlowe` to use `marlowe-proxy`
2 parents 0daada2 + 58c226b commit d8b5940

File tree

25 files changed

+448
-281
lines changed

25 files changed

+448
-281
lines changed

cabal.project

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ packages:
3131
marlowe-integration-tests
3232
marlowe-protocols
3333
marlowe-runtime
34+
marlowe-runtime-cli
3435
marlowe-runtime-web
3536
marlowe-test
3637

@@ -84,6 +85,9 @@ package marlowe-protocols
8485
package marlowe-runtime
8586
ghc-options: -Werror
8687

88+
package marlowe-runtime-cli
89+
ghc-options: -Werror
90+
8791
package marlowe-runtime-web
8892
ghc-options: -Werror
8993

marlowe-runtime-cli/LICENSE

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Apache License
2+
3+
Version 2.0, January 2004
4+
5+
http://www.apache.org/licenses/
6+
7+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8+
9+
1. Definitions.
10+
11+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
12+
13+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
14+
15+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
16+
17+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
18+
19+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
20+
21+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
22+
23+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
24+
25+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
26+
27+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
28+
29+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
30+
31+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32+
33+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
34+
35+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
36+
37+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
38+
You must cause any modified files to carry prominent notices stating that You changed the files; and
39+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
40+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
41+
42+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
43+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
44+
45+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
46+
47+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
48+
49+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
50+
51+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
52+
53+
END OF TERMS AND CONDITIONS

marlowe-runtime-cli/NOTICE

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Copyright 2019 Input Output (Hong Kong) Ltd.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+

marlowe-runtime/cli/Language/Marlowe/Runtime/CLI/Command.hs renamed to marlowe-runtime-cli/app/Language/Marlowe/Runtime/CLI/Command.hs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module Language.Marlowe.Runtime.CLI.Command
88
import Control.Concurrent.STM (STM)
99
import Control.Monad.Trans.Reader (runReaderT)
1010
import Data.Foldable (asum)
11-
import Language.Marlowe.Protocol.Sync.Client (marloweSyncClientPeer)
1211
import Language.Marlowe.Runtime.CLI.Command.Apply
1312
( ApplyCommand
1413
, advanceCommandParser
@@ -27,19 +26,14 @@ import Language.Marlowe.Runtime.CLI.Env (Env(..))
2726
import Language.Marlowe.Runtime.CLI.Monad (CLI, runCLI)
2827
import Language.Marlowe.Runtime.CLI.Option (optParserWithEnvDefault)
2928
import qualified Language.Marlowe.Runtime.CLI.Option as O
30-
import Network.Protocol.Connection (SomeConnector(..))
31-
import Network.Protocol.Driver (tcpClient)
32-
import Network.Protocol.Handshake.Client (handshakeClientConnector)
33-
import Network.Protocol.Job.Client (jobClientPeer)
29+
import Language.Marlowe.Runtime.Client (connectToMarloweRuntime)
3430
import Network.Socket (HostName, PortNumber)
3531
import Options.Applicative
3632

3733
-- | Top-level options for running a command in the Marlowe Runtime CLI.
3834
data Options = Options
39-
{ historyHost :: !HostName
40-
, historySyncPort :: !PortNumber
41-
, txHost :: !HostName
42-
, txCommandPort :: !PortNumber
35+
{ host :: !HostName
36+
, port :: !PortNumber
4337
, cmd :: !Command
4438
}
4539

@@ -54,10 +48,8 @@ data Command
5448
-- | Read options from the environment and the command line.
5549
getOptions :: IO Options
5650
getOptions = do
57-
syncHostParser <- optParserWithEnvDefault O.syncHost
58-
syncSyncPort <- optParserWithEnvDefault O.syncSyncPort
59-
txHostParser <- optParserWithEnvDefault O.txHost
60-
txCommandPortParser <- optParserWithEnvDefault O.txCommandPort
51+
hostParser <- optParserWithEnvDefault O.runtimeHost
52+
portParser <- optParserWithEnvDefault O.runtimePort
6153
let
6254
commandParser = asum
6355
[ hsubparser $ mconcat
@@ -80,10 +72,8 @@ getOptions = do
8072
]
8173
]
8274
parser = Options
83-
<$> syncHostParser
84-
<*> syncSyncPort
85-
<*> txHostParser
86-
<*> txCommandPortParser
75+
<$> hostParser
76+
<*> portParser
8777
<*> commandParser
8878
infoMod = mconcat
8979
[ fullDesc
@@ -102,8 +92,4 @@ runCommand = \case
10292

10393
-- | Interpret a CLI action in IO using the provided options.
10494
runCLIWithOptions :: STM () -> Options -> CLI a -> IO a
105-
runCLIWithOptions sigInt Options{..} cli = runReaderT (runCLI cli) Env
106-
{ marloweSyncConnector = SomeConnector $ handshakeClientConnector $ tcpClient historyHost historySyncPort marloweSyncClientPeer
107-
, txJobConnector = SomeConnector $ handshakeClientConnector $ tcpClient txHost txCommandPort jobClientPeer
108-
, sigInt
109-
}
95+
runCLIWithOptions sigInt Options{..} cli = runReaderT (connectToMarloweRuntime host port $ runCLI cli) Env { sigInt }

marlowe-runtime/cli/Language/Marlowe/Runtime/CLI/Command/Apply.hs renamed to marlowe-runtime-cli/app/Language/Marlowe/Runtime/CLI/Command/Apply.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ import Language.Marlowe (POSIXTime(..))
2424
import qualified Language.Marlowe.Core.V1.Semantics.Types as V1
2525
import qualified Language.Marlowe.Core.V1.Semantics.Types.Address as V1
2626
import Language.Marlowe.Runtime.CLI.Command.Tx (SigningMethod(Manual), TxCommand(..), txCommandParser)
27-
import Language.Marlowe.Runtime.CLI.Monad (CLI, runCLIExceptT, runTxCommand)
27+
import Language.Marlowe.Runtime.CLI.Monad (CLI, runCLIExceptT)
2828
import Language.Marlowe.Runtime.CLI.Option (txOutRefParser)
2929
import Language.Marlowe.Runtime.ChainSync.Api (TransactionMetadata, fromJSONEncodedTransactionMetadata, unPolicyId)
30+
import Language.Marlowe.Runtime.Client (applyInputs')
3031
import Language.Marlowe.Runtime.Core.Api
3132
(ContractId(..), IsMarloweVersion(..), MarloweVersion(MarloweV1), MarloweVersionTag(..))
32-
import Language.Marlowe.Runtime.Transaction.Api (ApplyInputsError, InputsApplied(..), MarloweTxCommand(ApplyInputs))
33+
import Language.Marlowe.Runtime.Transaction.Api (ApplyInputsError, InputsApplied(..))
3334
import qualified Language.Marlowe.Util as V1
3435
import Options.Applicative
3536
import qualified Plutus.V1.Ledger.Api as P
@@ -222,8 +223,7 @@ runApplyCommand TxCommand { walletAddresses, signingMethod, metadataFile, subCom
222223
validityLowerBound'= posixTimeToUTCTime <$> validityLowerBound
223224
validityUpperBound'= posixTimeToUTCTime <$> validityUpperBound
224225

225-
cmd = ApplyInputs MarloweV1 walletAddresses contractId metadata validityLowerBound' validityUpperBound' inputs'
226-
InputsApplied{txBody} <- ExceptT $ first ApplyFailed <$> runTxCommand cmd
226+
InputsApplied{txBody} <- ExceptT $ first ApplyFailed <$> applyInputs' MarloweV1 walletAddresses contractId metadata validityLowerBound' validityUpperBound' inputs'
227227
case signingMethod of
228228
Manual outputFile -> do
229229
ExceptT $ liftIO $ first TransactionFileWriteFailed <$> C.writeFileTextEnvelope outputFile Nothing txBody

marlowe-runtime/cli/Language/Marlowe/Runtime/CLI/Command/Create.hs renamed to marlowe-runtime-cli/app/Language/Marlowe/Runtime/CLI/Command/Create.hs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import qualified Data.Yaml as Yaml
1919
import Data.Yaml.Aeson (decodeFileEither)
2020
import Language.Marlowe (POSIXTime(POSIXTime))
2121
import Language.Marlowe.Runtime.CLI.Command.Tx (SigningMethod(Manual), TxCommand(..), txCommandParser)
22-
import Language.Marlowe.Runtime.CLI.Monad (CLI, runCLIExceptT, runTxCommand)
22+
import Language.Marlowe.Runtime.CLI.Monad (CLI, runCLIExceptT)
2323
import Language.Marlowe.Runtime.CLI.Option (keyValueOption, marloweVersionParser, parseAddress)
2424
import Language.Marlowe.Runtime.ChainSync.Api
2525
( Address
@@ -30,15 +30,15 @@ import Language.Marlowe.Runtime.ChainSync.Api
3030
, fromJSONEncodedTransactionMetadata
3131
, renderTxOutRef
3232
)
33+
import Language.Marlowe.Runtime.Client (createContract)
3334
import Language.Marlowe.Runtime.Core.Api
3435
( ContractId(ContractId)
3536
, IsMarloweVersion(Contract)
3637
, MarloweVersion(MarloweV1)
3738
, MarloweVersionTag(V1)
3839
, SomeMarloweVersion(SomeMarloweVersion)
3940
)
40-
import Language.Marlowe.Runtime.Transaction.Api
41-
(ContractCreated(..), CreateError, MarloweTxCommand(Create), RoleTokensConfig(..), mkMint)
41+
import Language.Marlowe.Runtime.Transaction.Api (ContractCreated(..), CreateError, RoleTokensConfig(..), mkMint)
4242
import Options.Applicative
4343
import Options.Applicative.NonEmpty (some1)
4444
import Text.Read (readMaybe)
@@ -183,9 +183,7 @@ runCreateCommand TxCommand { walletAddresses, signingMethod, metadataFile, subCo
183183
run version rolesDistribution = do
184184
contract <- readContract version
185185
metadata <- readMetadata
186-
let
187-
cmd = Create Nothing version walletAddresses rolesDistribution metadata minUTxO contract
188-
ContractCreated{contractId,txBody} <- ExceptT $ first CreateFailed <$> runTxCommand cmd
186+
ContractCreated{contractId,txBody} <- ExceptT $ first CreateFailed <$> createContract Nothing version walletAddresses rolesDistribution metadata minUTxO contract
189187
case signingMethod of
190188
Manual outputFile -> do
191189
ExceptT $ liftIO $ first TransactionFileWriteFailed <$> C.writeFileTextEnvelope outputFile Nothing txBody

marlowe-runtime/cli/Language/Marlowe/Runtime/CLI/Command/Log.hs renamed to marlowe-runtime-cli/app/Language/Marlowe/Runtime/CLI/Command/Log.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Language.Marlowe (pretty)
1616
import qualified Language.Marlowe.Core.V1.Semantics as V1
1717
import Language.Marlowe.Protocol.Sync.Client
1818
import Language.Marlowe.Runtime.CLI.Env (Env(..))
19-
import Language.Marlowe.Runtime.CLI.Monad (CLI, askEnv, runCLIExceptT, runHistorySyncClient)
19+
import Language.Marlowe.Runtime.CLI.Monad (CLI, askEnv, runCLIExceptT)
2020
import Language.Marlowe.Runtime.CLI.Option (contractIdArgument)
2121
import Language.Marlowe.Runtime.ChainSync.Api
2222
( AssetId(AssetId)
@@ -30,6 +30,7 @@ import Language.Marlowe.Runtime.ChainSync.Api
3030
, toBech32
3131
, unBlockHeaderHash
3232
)
33+
import qualified Language.Marlowe.Runtime.Client as Client
3334
import Language.Marlowe.Runtime.Core.Api
3435
( ContractId(..)
3536
, MarloweVersion(..)
@@ -71,7 +72,7 @@ logCommandParser = info parser $ progDesc "Display the history of a contract"
7172
runLogCommand :: LogCommand -> CLI ()
7273
runLogCommand LogCommand{..} = runCLIExceptT
7374
$ ExceptT
74-
$ runHistorySyncClient
75+
$ Client.runMarloweSyncClient
7576
$ MarloweSyncClient
7677
$ pure
7778
$ SendMsgFollowContract contractId ClientStFollow

marlowe-runtime/cli/Language/Marlowe/Runtime/CLI/Command/Submit.hs renamed to marlowe-runtime-cli/app/Language/Marlowe/Runtime/CLI/Command/Submit.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import qualified Data.Aeson as A
1111
import Data.Bifunctor (Bifunctor(first))
1212
import Data.ByteString.Base16 (encodeBase16)
1313
import Language.Marlowe.Runtime.CLI.Env (Env(..))
14-
import Language.Marlowe.Runtime.CLI.Monad (CLI, asksEnv, runCLIExceptT, runTxJobClient)
14+
import Language.Marlowe.Runtime.CLI.Monad (CLI, asksEnv, runCLIExceptT)
1515
import Language.Marlowe.Runtime.ChainSync.Api
1616
(BlockHeader(BlockHeader), BlockHeaderHash(unBlockHeaderHash), BlockNo(unBlockNo), SlotNo(unSlotNo))
17+
import Language.Marlowe.Runtime.Client (runMarloweTxClient)
1718
import Language.Marlowe.Runtime.Transaction.Api (MarloweTxCommand(Submit), SubmitError)
1819
import Network.Protocol.Job.Client
1920
(ClientStAwait(SendMsgDetach, SendMsgPoll), ClientStCmd(..), ClientStInit(SendMsgExec), JobClient(JobClient))
@@ -33,7 +34,7 @@ submitCommandParser = info parser $ progDesc "Submit a signed transaction to the
3334
, help "A file containing the CBOR bytes of the signed transaction to submit."
3435
]
3536

36-
data CilentSubmitError
37+
data ClientSubmitError
3738
= SubmitFailed SubmitError
3839
| SubmitInterrupted
3940
| TransactionDecodingFailed
@@ -60,12 +61,11 @@ runSubmitCommand SubmitCommand{txFile} = runCLIExceptT do
6061
, recvMsgSucceed = pure . Right
6162
}
6263
jobClient = JobClient . pure . SendMsgExec cmd $ next
63-
BlockHeader slotNo hash blockNo <- ExceptT $ runTxJobClient jobClient
64+
BlockHeader slotNo hash blockNo <- ExceptT $ runMarloweTxClient jobClient
6465
let
6566
res = A.object
6667
[ ("slotNo", toJSON $ unSlotNo slotNo)
6768
, ("blockHeaderHash", toJSON . encodeBase16 $ unBlockHeaderHash hash)
6869
, ("blockNo", toJSON $ unBlockNo blockNo)
6970
]
7071
liftIO . print $ A.encode res
71-

0 commit comments

Comments
 (0)