Skip to content

Commit

Permalink
Merge branch 'main' into zeme-iohk/iogxxx
Browse files Browse the repository at this point in the history
  • Loading branch information
zeme-wana committed May 26, 2023
2 parents 644822c + 47e066f commit 1191715
Show file tree
Hide file tree
Showing 295 changed files with 10,289 additions and 7,918 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -9,5 +9,5 @@ trim_trailing_whitespace = true
insert_final_newline = true

[*.hs]
indent_size = 4
indent_size = 2
max_line_length = 120
3 changes: 3 additions & 0 deletions README.adoc
Expand Up @@ -214,8 +214,11 @@ Services currently included:
* `marlowe--sync`: `marlowe-sync` for the `preprod` network.
* `marlowe--indexer`: `marlowe-indexer` for the `preprod` network.
* `marlowe-tx`: A `marlowe-tx` instance.
* `marlowe-contract`: A `marlowe-contract` instance.
* `marlowe-proxy`: A `marlowe-proxy` instance.
* `web`: A `marlowe-web-server` instance.
* `otel-collector`: A shared `opentelemetry` collector instance for distributed tracing.
* `jaeger`: A trace viewer service.

The following commands may be useful:

Expand Down
1 change: 0 additions & 1 deletion async-components/async-components.cabal
Expand Up @@ -54,6 +54,5 @@ library
, servant >= 0.19 && < 0.20
, servant-client >= 0.19 && < 0.20
, servant-server >= 0.19 && < 0.20
, stm >= 2.5 && < 2.6
, unliftio >= 0.2.1 && < 0.3
, warp >= 3.3 && < 4
21 changes: 21 additions & 0 deletions deploy/nomadTasks.nix
Expand Up @@ -165,12 +165,33 @@ rec
resources.memory = 1024;
};

marlowe-contract = {
env = {
HOST = "0.0.0.0";
PORT = "\${NOMAD_PORT_marlowe_load}";
# TODO replace with a persistent volume
STORE_DIR = "/tmp/store";
HTTP_PORT = "\${NOMAD_PORT_contract_http}";
};
config.image = ociNamer oci-images.marlowe-contract;
config.ports = [ "marlowe_load" "contract_http" ];
service.port = "marlowe_load";
user = "0:0";
driver = "docker";
kill_signal = "SIGINT";
kill_timeout = "30s";
resources.cpu = 1000;
resources.memory = 1024;
};

marlowe-proxy = {
env = {
HOST = "0.0.0.0";
PORT = "\${NOMAD_PORT_proxy}";
TX_HOST = "localhost";
TX_PORT = "\${NOMAD_PORT_tx}";
CONTRACT_HOST = "localhost";
LOAD_PORT = "\${NOMAD_PORT_marlowe_load}";
SYNC_HOST = "localhost";
MARLOWE_SYNC_PORT = "\${NOMAD_PORT_marlowe_sync}";
MARLOWE_HEADER_SYNC_PORT = "\${NOMAD_PORT_marlowe_header_sync}";
Expand Down
4 changes: 4 additions & 0 deletions deploy/oci-images.nix
Expand Up @@ -41,6 +41,10 @@ let
name = "marlowe-tx";
description = "A Marlowe transaction creation service for the Marlowe Runtime.";
};
marlowe-contract = mkImage {
name = "marlowe-contract";
description = "A content-addressable contract store service for the Marlowe runtime.";
};
marlowe-proxy = mkImage {
name = "marlowe-proxy";
description = "An API Gateway service for the Marlowe Runtime.";
Expand Down
38 changes: 38 additions & 0 deletions deploy/operables.nix
Expand Up @@ -384,6 +384,38 @@ in
'';
};

marlowe-contract = mkOperableWithProbes {
package = packages.marlowe-contract;
runtimeInputs = [ coreutils ];
runtimeScript = ''
#################
# REQUIRED VARS #
#################
# HOST, PORT: network binding
# STORE_DIR: location of the contract store directory
# HTTP_PORT: port number for the HTTP healthcheck server
#################
# OPTIONAL VARS #
#################
# OTEL_EXPORTER_OTLP_ENDPOINT: The url of the open telemetry collector
[ -z "''${HOST:-}" ] && echo "HOST env var must be set -- aborting" && exit 1
[ -z "''${PORT:-}" ] && echo "PORT env var must be set -- aborting" && exit 1
[ -z "''${STORE_DIR:-}" ] && echo "STORE_DIR env var must be set -- aborting" && exit 1
[ -z "''${HTTP_PORT:-}" ] && echo "HTTP_PORT env var must be set -- aborting" && exit 1
mkdir -p /tmp
export OTEL_SERVICE_NAME=marlowe-contract
${packages.marlowe-contract}/bin/marlowe-contract \
--host "$HOST" \
--port "$PORT" \
--store-dir "$STORE_DIR" \
--http-port "$HTTP_PORT"
'';
};

marlowe-proxy = mkOperableWithProbes {
package = packages.marlowe-proxy;
runtimeScript = ''
Expand All @@ -393,6 +425,7 @@ in
# HOST, PORT: network binding
# TX_HOST, TX_PORT: connection info to marlowe-tx
# SYNC_HOST, MARLOWE_SYNC_PORT, MARLOWE_HEADER_SYNC_PORT, MARLOWE_QUERY_PORT: connection info to marlowe-sync
# CONTRACT_HOST, LOAD_PORT: connection info to marlowe-contract
# HTTP_PORT: port number for the HTTP healthcheck server
#################
Expand All @@ -404,13 +437,16 @@ in
[ -z "''${PORT:-}" ] && echo "PORT env var must be set -- aborting" && exit 1
[ -z "''${TX_HOST:-}" ] && echo "TX_HOST env var must be set -- aborting" && exit 1
[ -z "''${TX_PORT:-}" ] && echo "TX_PORT env var must be set -- aborting" && exit 1
[ -z "''${CONTRACT_HOST:-}" ] && echo "CONTRACT_HOST env var must be set -- aborting" && exit 1
[ -z "''${LOAD_PORT:-}" ] && echo "LOAD_PORT env var must be set -- aborting" && exit 1
[ -z "''${SYNC_HOST:-}" ] && echo "SYNC_HOST env var must be set -- aborting" && exit 1
[ -z "''${MARLOWE_SYNC_PORT:-}" ] && echo "MARLOWE_SYNC_PORT env var must be set -- aborting" && exit 1
[ -z "''${MARLOWE_HEADER_SYNC_PORT:-}" ] && echo "MARLOWE_HEADER_SYNC_PORT env var must be set -- aborting" && exit 1
[ -z "''${MARLOWE_QUERY_PORT:-}" ] && echo "MARLOWE_QUERY_PORT env var must be set -- aborting" && exit 1
[ -z "''${HTTP_PORT:-}" ] && echo "HTTP_PORT env var must be set -- aborting" && exit 1
${wait-for-tcp}/bin/wait-for-tcp "$TX_HOST" "$TX_PORT"
${wait-for-tcp}/bin/wait-for-tcp "$CONTRACT_HOST" "$LOAD_PORT"
${wait-for-tcp}/bin/wait-for-tcp "$SYNC_HOST" "$MARLOWE_QUERY_PORT"
export OTEL_SERVICE_NAME=marlowe-proxy
Expand All @@ -422,6 +458,8 @@ in
--marlowe-sync-port "$MARLOWE_SYNC_PORT" \
--marlowe-header-port "$MARLOWE_HEADER_SYNC_PORT" \
--marlowe-query-port "$MARLOWE_QUERY_PORT" \
--marlowe-contract-host "$CONTRACT_HOST" \
--marlowe-load-host "$LOAD_PORT" \
--tx-host "$TX_HOST" \
--tx-command-port "$TX_PORT" \
--http-port "$HTTP_PORT"
Expand Down
1 change: 1 addition & 0 deletions eventuo11y-extras/eventuo11y-extras.cabal
Expand Up @@ -52,6 +52,7 @@ library
build-depends:
, base >= 4.9 && < 5
, eventuo11y ^>= { 0.9, 0.10 }
, exceptions >= 0.10 && < 0.11
, general-allocate ^>= { 0.2 }
, resourcet >= 1.3 && < 2
, some >= 1 && < 2
Expand Down
4 changes: 4 additions & 0 deletions eventuo11y-extras/src/Control/Monad/Event/Class.hs
Expand Up @@ -15,6 +15,7 @@ module Control.Monad.Event.Class
import Control.Applicative (Alternative)
import Control.Monad (MonadPlus)
import Control.Monad.Allocate (MonadAllocate)
import Control.Monad.Catch (MonadCatch, MonadMask, MonadThrow)
import Control.Monad.Fix (MonadFix)
import Control.Monad.IO.Class (MonadIO)
import Control.Monad.Trans.Class (lift)
Expand All @@ -41,6 +42,9 @@ newtype NoopEventT r (s :: * -> *) m a = NoopEventT { runNoopEventT :: m a }
, Applicative
, Monad
, Alternative
, MonadThrow
, MonadCatch
, MonadMask
, MonadFail
, MonadFix
, MonadIO
Expand Down
26 changes: 26 additions & 0 deletions flake.nix
Expand Up @@ -158,9 +158,35 @@
operables = import ./deploy/operables.nix {
inputs = nosys.lib.deSys system inputs;
};

oci-images = import ./deploy/oci-images.nix {
inputs = nosys.lib.deSys system inputs;

marlowe-sync = {
type = "app";
program = "${packages.marlowe-sync}/bin/marlowe-sync";
};

marlowe-tx = {
type = "app";
program = "${packages.marlowe-tx}/bin/marlowe-tx";
};

marlowe-proxy = {
type = "app";
program = "${packages.marlowe-proxy}/bin/marlowe-proxy";
};

marlowe-contract = {
type = "app";
program = "${packages.marlowe-contract}/bin/marlowe-contract";
};

marlowe-web-server = {
type = "app";
program = "${packages.marlowe-web-server}/bin/marlowe-web-server";
};

nomadTasks = import ./deploy/nomadTasks.nix {
inputs = nosys.lib.deSys system inputs;
};
Expand Down
1 change: 1 addition & 0 deletions marlowe-apps/ReadMe.md
Expand Up @@ -4,3 +4,4 @@
- [General-purpose oracle](Oracle.md)
- [Find active Marlowe contracts](Finder.md)
- [JSON pipe for Marlowe Runtime](Pipe.md)
- [A signing service](Signing.md)
61 changes: 61 additions & 0 deletions marlowe-apps/Signing.md
@@ -0,0 +1,61 @@
# A Signing Service

This service is a simple utility for signing transactions in demonstrations, where a signing tool such as `cardano-cli` or a CIP-30 wallet is not available.


## Deployment

Simply provide the bind address and port number for the service when starting it.

```bash
cabal run exe:signing-service -- 127.0.0.1 3779
```

In this example, the service endpoint is `http://127.0.0.1:3779/sign`.


## Example

For a request, the body is the unsigned transaction provided by Marlowe Runtime and the payment keys is the signing key file.

```JSON
{
"body" : {
"type": "TxBodyBabbage",
"description": "",
"cborHex": "86a3008182582013735748e79d7d049f4761cd47c3523935337f474f3d942517ea28687fe137cf000181a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a0be9415b021a000280a59fff8080f5f6"
}
, "paymentKeys" : [
{
"type": "PaymentSigningKeyShelley_ed25519",
"description": "Payment Signing Key",
"cborHex": "5820bb921c6af621b3336460e6df335d73d4d91012718240bb95dd0301fd9aa5b5e6"
}
]
, "paymentExtendedKeys" : []
}
```

Next call the endpoint for the service.

```bash
curl -sS \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d @request.json \
-o response.json \
http://127.0.0.1:3779/sign
```

The response is the tx is suitable for sending to Marlowe Runtime for submission.

```JSON
{
"tx" : {
"cborHex" : "84a3008182582013735748e79d7d049f4761cd47c3523935337f474f3d942517ea28687fe137cf000181a200581d6054705dbd6072d78dc3555ce3a77058fcaf769f9f98385fec07b1f889011a0be9415b021a000280a5a10081825820ae56efbd10931edd0bcc4c1f929ab9c8d30fe15a58ea4df515aa281d1479a21c58407486e300ebf2401ed5be16c9efcb30828489b68b8dea87a5d391d5a246d96284ed2311bec05d219606246d236dc613926eccac278cdd0cfa6db6d5c1e5455b0cf5f6",
"description" : "",
"type" : "Tx BabbageEra"
},
"txId" : "b21e5b0fc853ae86e33ec54b2886b589dfe3fadf08d1b28e5942c483eef16677"
}
```
@@ -0,0 +1,4 @@
Added
-----

- Added simple transaction signing service for use in demonstrations.
20 changes: 20 additions & 0 deletions marlowe-apps/marlowe-apps.cabal
Expand Up @@ -175,3 +175,23 @@ executable marlowe-finder
-Widentities
-Wunused-packages
default-language : Haskell2010

executable signing-service
main-is : Main.hs
hs-source-dirs : signing
build-depends : base >= 4.9 && < 5
, aeson
, cardano-api
, marlowe-apps
, marlowe-chain-sync
, servant-server
, wai
, warp
ghc-options : -Wall
-Wnoncanonical-monad-instances
-Wincomplete-uni-patterns
-Wincomplete-record-updates
-Wredundant-constraints
-Widentities
-Wunused-packages
default-language : Haskell2010

0 comments on commit 1191715

Please sign in to comment.