Skip to content

Commit

Permalink
refactor(examples): include sample apps in monorepo build
Browse files Browse the repository at this point in the history
- Include discounted-cartrade and electricity trade in monorepo setup,
- Update the devcontainer and include new environment setup instructions in BUILD.md,
- Fix sample apps build error,
- Rename of sample apps to cactus-example-*,
- Change any "car" references to "asset" (in code, comments, documentation, etc..),
- Rename asset-trade files to match the format of the rest of this repository.
- Remove asset-trade eth asset management class and endpoint
  (not used right now, and it would confuse with fabric asset).
- Renamed some uses of cartrade to asset-trade,
  (more complete changes are included in follow-up commit),
- Add indy build artifacts to .gitignore,
- Add cmake to devcontainer build (fixed warning during npm dependency build stage),
- Fix random whitespace and typos errors,

BREAKING CHANGE: building discounted-asset-trade app (or any future app that use indy validator)
                 requires Indy SDK to be installed on the build machine.

Closes: 2029

Signed-off-by: Michal Bajer <[email protected]>
  • Loading branch information
outSH committed May 17, 2022
1 parent c051d7f commit e7b4d3c
Show file tree
Hide file tree
Showing 109 changed files with 751 additions and 804 deletions.
17 changes: 16 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ RUN apt-get update \
RUN apt-get update \
&& apt-get -y install curl git mercurial make binutils bison gcc build-essential

# Install Indy-SDK
# Add Sovrin repository (only bionic release available, but works in recent ubuntu as well)
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys CE7709D068DB5E88 \
&& add-apt-repository "deb https://repo.sovrin.org/sdk/deb bionic stable" \
# Install Indy SDK
&& apt-get update \
&& apt-get install -y \
libindy \
libnullpay \
libvcx \
indy-cli \
# Remove auto repo entry for focal release (use one from /etc/apt/sources.list)
&& rm -f /etc/apt/sources.list.d/sovrin.list* \
# Clean up
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts/

VOLUME [ "/var/lib/docker" ]

Expand All @@ -46,7 +61,7 @@ CMD [ "sleep", "infinity" ]

# [Optional] Uncomment this section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends openjdk-11-jdk
&& apt-get -y install --no-install-recommends openjdk-11-jdk cmake

COPY post-create-commands.sh /home/vscode/bin/

Expand Down
25 changes: 14 additions & 11 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ The `npm run watch` script in action:
![Fast Developer Flow / Code Iterations](./docs/hyperledger-cactus-watch-script-tutorial-2021-03-06.gif)

## Getting Started

* Install OS level dependencies:
* Use preset environment:
* [VSCode docker container](./.devcontainer)
* ... or install OS level dependencies manually:
* Windows Only
* WSL2 or any virtual machine running Ubuntu 20.04 LTS
* Git
Expand All @@ -98,13 +99,15 @@ The `npm run watch` script in action:
nvm install 16.14.2
nvm use 16.14.2
```
* Yarn
* Yarn
* `npm run install-yarn` (from within the project directory)
* [Docker Engine](https://docs.docker.com/engine/install/ubuntu/). Make sure that Docker is working and running, for example, running ``docker ps -aq``
* Docker Compose
* [Docker Engine](https://docs.docker.com/engine/install/ubuntu/). Make sure that Docker is working and running, for example, running ``docker ps -aq``
* Docker Compose
* OpenJDK (Corda support Java 8 JDK but do not currently support Java 9 or higher)
* `sudo apt install openjdk-8-jdk-headless`
* Indy SDK
* [Installing the SDK](https://github.com/hyperledger/indy-sdk#installing-the-sdk)
* [Build the SDK from source](https://github.com/hyperledger/indy-sdk#how-to-build-indy-sdk-from-source)
* Clone the repository
Expand Down Expand Up @@ -220,16 +223,16 @@ the following decision tree (and keep in mind that we have `npm run watch` too)
## Configuring SSH to use upterm
Upload your public key onto github if not done so already. A public key is necessary to join the ssh connection to use upterm. For a comprehensive guide, see the [Generating a new SSH key and adding it to the ssh-agent](https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent).

Locate the `ci.yml` within `.github/workflows` and add to the `ci.yml` code listed below:
Locate the `ci.yml` within `.github/workflows` and add to the `ci.yml` code listed below:
- name: Setup upterm session
uses: lhotari/action-upterm@v1
with:
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

Keep in mind that the SSH upterm session should come after the checkout step (uses: actions/[email protected]) to ensure that the CI doesn't hang without before the debugging step occurs. Editing the `ci.yml` will create a new upterm session within `.github/workflows` by adding a new build step. For more details, see the [Debug your GitHub Actions by using ssh](https://github.com/marketplace/actions/debugging-with-ssh).
Keep in mind that the SSH upterm session should come after the checkout step (uses: actions/[email protected]) to ensure that the CI doesn't hang without before the debugging step occurs. Editing the `ci.yml` will create a new upterm session within `.github/workflows` by adding a new build step. For more details, see the [Debug your GitHub Actions by using ssh](https://github.com/marketplace/actions/debugging-with-ssh).

By creating a PR for the edited `ci.yml` file, this will the CI to run their tests. There are two ways to navigate to CIs.
By creating a PR for the edited `ci.yml` file, this will the CI to run their tests. There are two ways to navigate to CIs.
1) Go to the PR and click the `checks` tab
2) Go to the `Actions` tab within the main Hyperledger Cactus Repository

Click on the `CI Cactus workflow`. There should be a new job you've created be listed underneath the `build (ubuntu-20.04)` jobs. Click on the the new job (what's you've named your build) and locate the SSH Session within the `Setup Upterm Session` dropdown. Copy the SSH command that start with `ssh` and ends in `.dev` (ex. ssh **********:***********@uptermd.upterm.dev). Open your OS and paste the SSH command script in order to begin an upterm session.
Click on the `CI Cactus workflow`. There should be a new job you've created be listed underneath the `build (ubuntu-20.04)` jobs. Click on the the new job (what's you've named your build) and locate the SSH Session within the `Setup Upterm Session` dropdown. Copy the SSH command that start with `ssh` and ends in `.dev` (ex. ssh **********:***********@uptermd.upterm.dev). Open your OS and paste the SSH command script in order to begin an upterm session.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ As blockchain technology proliferates, blockchain integration will become an inc

Once the last command has finished executing, open link printed on the console with a web browser of your choice

### Discounted Car Trade Example
### Discounted Asset Trade Example

- The guidance is [here](./examples/discounted-cartrade/README.md).
- The guidance is [here](./examples/cactus-example-discounted-asset-trade/README.md).

### Electricity Trade Example

- The guidance is [here](./examples/electricity-trade/README.md).
- The guidance is [here](./examples/cactus-example-electricity-trade/README.md).


## Documentation
Expand All @@ -62,8 +62,8 @@ Once the last command has finished executing, open link printed on the console w

## Inclusive Language Statement

These guiding principles are very important to the maintainers and therefore
we respectfully ask all contributors to abide by them as well:
These guiding principles are very important to the maintainers and therefore
we respectfully ask all contributors to abide by them as well:

- Consider that users who will read the docs are from different backgrounds and
cultures and that they have different preferences.
Expand All @@ -73,9 +73,9 @@ deny list" to "white list and black list".
writing inclusive documentation might not look like a huge improvement, it's a
first step in the right direction.
- We suggest to refer to
[Microsoft bias free writing guidelines](https://docs.microsoft.com/en-us/style-guide/bias-free-communication)
and
[Google inclusive doc writing guide](https://developers.google.com/style/inclusive-documentation)
[Microsoft bias free writing guidelines](https://docs.microsoft.com/en-us/style-guide/bias-free-communication)
and
[Google inclusive doc writing guide](https://developers.google.com/style/inclusive-documentation)
as starting points.
## Roadmap
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# BLP artifacts
TransactionInfo.json
transaction-Info.json
etc/

# don't commit package-lock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ FROM cactus-cmd-socketio-server:latest

ARG NPM_PKG_VERSION=latest

ENV CARTRADE_HOME=/root/cactus
ENV APP_HOME=/root/cactus

WORKDIR ${CARTRADE_HOME}
WORKDIR ${APP_HOME}

# Required by indy-sdk
RUN apt-get update \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Cactus discounted-cartrade
# Cactus discounted-asset-trade


## Abstract

Cactus discounted-cartrade is a sample application that adds employee discounts to the original Cactus cartrade. In this application, when the users transfer the car ownership in the cactus cartrade, they present their employee proofs to the rent-a-car company to receive an employee discount. We implement the employee proofs by proofs on Hyperledger Indy. Car ownership is represented by a [asset-transfer-basic](https://github.com/hyperledger/fabric-samples/tree/release-2.2/asset-transfer-basic) chaincodetoken on Hyperledger Fabric, which can be exchanged for ETH currency on a private Ethereum blockchain. This Business Logic Plugin (BLP) application controls a process from employee certification using Hyperledger Indy to payment using Ethereum.
Cactus discounted-asset-trade is a sample application that calculates asset cost based on customer type. In this application, when the users transfer the asset ownership in the cactus discounted-asset-trade, they present their employee proofs to the asset-owner company to receive an employee discount. We implement the employee proofs by proofs on Hyperledger Indy. Asset ownership is represented by a [asset-transfer-basic](https://github.com/hyperledger/fabric-samples/tree/release-2.2/asset-transfer-basic) chaincodetoken on Hyperledger Fabric, which can be exchanged for ETH currency on a private Ethereum blockchain. This Business Logic Plugin (BLP) application controls a process from employee certification using Hyperledger Indy to payment using Ethereum.

![discounted-cartrade image](./image/discounted-cartrade-image.png)
![discounted-asset-trade image](./image/discounted-asset-trade-image.png)

## Scenario

The application works in the following scenario:

### Settings

Alice wants to rent a car using the services of rental car company Thrift Corp. Alice chose this company because she is an employee of Acme Corp., which offers discounts on Thrift Corp.'s services as a benefit.
Alice wants to buy an asset using the services of company Thrift Corp. Alice chose this company because she is an employee of Acme Corp., which offers discounts on Thrift Corp.'s services as a benefit.

**Note** : Acme Corp and Thrift Corp have the same names on the sample application on Hyperledger Indy.

Expand All @@ -23,17 +23,17 @@ Alice knows that Acme Corp. provides digital certificates. She asks Acme Corp. t

### When Alice Uses the Service

Alice will use credentials and other Indy formats such as schema and definition to create an employee proof that she will present when applying the lent-a-car service. Alice then sends a car usage application and her employee proof to the Cactus Node Server via an End User Application. The employee proofs consist of proof requests and proofs on Hyperledger Indy. The Cactus Node server receives the schema and definition from the Indy ledger via Validator and uses this information to verify the proof with the BLP. Once verified, the BLP will decide what she should pay based on the price list and then proceed with the original cartrade application using cactus as an escrow to transfer ETH currencies and car ownership tokens to each other.
Alice will use credentials and other Indy formats such as schema and definition to create an employee proof that she will present when purchasing the asset. Alice then sends a purchase order and her employee proof to the Cactus Node Server via an End User Application. The employee proofs consist of proof requests and proofs on Hyperledger Indy. The Cactus Node server receives the schema and definition from the Indy ledger via Validator and uses this information to verify the proof with the BLP. Once verified, the BLP will decide what she should pay based on the price list and then proceed with the business logic using cactus as an escrow to transfer ETH currencies and asset ownership tokens to each other.

## Setup Overview

### fabric-socketio-validator
- Validator for fabric ledger.
- Docker networks: `fabric-all-in-one_testnet-14`, `discounted-cartrade-net`
- Docker networks: `fabric-all-in-one_testnet-2x`, `cactus-example-discounted-asset-trade-net`

### ethereum-validator
- Validator for ethereum ledger.
- Docker network: `geth1net`, `discounted-cartrade-net`
- Docker network: `geth1net`, `cactus-example-discounted-asset-trade-net`

### indy-sdk-cli-base-image
- Base image for indy validator.
Expand All @@ -49,19 +49,19 @@ Alice will use credentials and other Indy formats such as schema and definition
- Load balancer / gateway for indy validator.
- Use it's endpoint to talk to indy validator.
- Uses config from `./nginx/nginx.conf`
- Docker network: `indy-testnet_indy_net`, `discounted-cartrade-net`
- Docker network: `indy-testnet_indy_net`, `cactus-example-discounted-asset-trade-net`

### cmd-socketio-base-image
- Base image for `discounted-cartrade` BLP.
- Base image for `cactus-example-discounted-asset-trade` BLP.
- Contains cactus cmd socketio server module
- It will build the image and immediately exit on run.

### discounted-cartrade-blp
### cactus-example-discounted-asset-trade-blp
- Main logic for this sample application.
- Use it's endpoint (`localhost:5034`) to interact the bussiness logic.
- Docker network: `discounted-cartrade-net`
- Docker network: `cactus-example-discounted-asset-trade-net`

### req_discounted_cartrade
### register-indy-data
- Setup application.
- Will generate proof and store it in local configuration on startup.
- This application can also be used to send requests to the BLP.
Expand All @@ -86,15 +86,10 @@ Alice will use credentials and other Indy formats such as schema and definition
- (NOTICE: Before executing the above, your account needs to be added to the docker group (`usermod -a -G docker YourAccount` from root user))
- On success, this should start three containers:
- `geth1`
- `discounted_cartrade_faio2x_testnet`
- `asset_trade_faio2x_testnet`
- `indy-testnet-pool`
1. Build cartrade:
```
./script-build-discounted-cartrade.sh
```
1. Launch cartrade and validators from local `docker-compose.yml` (use separate console for that, docker-compose will block your prompt):
1. Launch discounted-asset-trade and validators from local `docker-compose.yml` (use separate console for that, docker-compose will block your prompt):
```
docker-compose build && docker-compose up
# or
Expand All @@ -104,27 +99,27 @@ Alice will use credentials and other Indy formats such as schema and definition
This will build and launch all needed containers, the final output should look like this:
```
discounted-cartrade-ethereum-validator | listening on *:5050
cactus-example-discounted-asset-trade-ethereum-validator | listening on *:5050
...
discounted-cartrade-fabric-socketio-validator | listening on *:5040
cactus-example-discounted-asset-trade-fabric-socketio-validator | listening on *:5040
...
discounted-cartrade-indy-validator | 2022-01-31 16:00:49,552 INFO success: validator entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
cactus-example-discounted-asset-trade-indy-validator | 2022-01-31 16:00:49,552 INFO success: validator entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
...
discounted-cartrade-indy-validator-nginx | 2022/01/31 16:00:49 [notice] 1#1: start worker process 35
cactus-example-discounted-asset-trade-indy-validator-nginx | 2022/01/31 16:00:49 [notice] 1#1: start worker process 35
...
cmd-socketio-base-dummy exited with code 0
...
indy-sdk-cli-base-dummy exited with code 0
...
req_discounted_cartrade | Done.
req_discounted_cartrade exited with code 0
register-indy-data | Done.
register-indy-data exited with code 0
...
discounted-cartrade-blp | [2022-01-31T16:00:56.208] [INFO] www - listening on *: 5034
cactus-example-discounted-asset-trade-blp | [2022-01-31T16:00:56.208] [INFO] www - listening on *: 5034
```
## How to use this application
1. (Optional) Check the balance on Ethereum and the car ownership on Fabric using the following script:
1. (Optional) Check the balance on Ethereum and the asset ownership on Fabric using the following script:
```
node ./read-ledger-state.js
```
Expand Down Expand Up @@ -156,27 +151,27 @@ Alice will use credentials and other Indy formats such as schema and definition
1. Run the transaction execution using the following script:
```
./script-post-discounted-cartrade-sample.sh
./script-post-trade-request.sh
```
... or send request manually:
```
docker run --rm -ti -v "$(pwd)/etc/cactus/":"/etc/cactus/" --net="host" req_discounted_cartrade
docker run --rm -ti -v "$(pwd)/etc/cactus/":"/etc/cactus/" --net="host" register-indy-data
```
After this, the transactions are executed by order. When the following log appears on the console where you executed `docker-compose`, the transactions are completed.
```
[INFO] BusinessLogicCartrade - ##INFO: completed cartrade, businessLogicID: guks32pf, tradeID: *******-001
[INFO] BusinessLogicAssetTrade - ##INFO: completed asset-trade, businessLogicID: guks32pf, tradeID: *******-001
```
1. (Optional) Check the balance on Ethereum and the car ownership on Fabric using the following script
1. (Optional) Check the balance on Ethereum and the asset ownership on Fabric using the following script
```
node ./read-ledger-state.js
```
The result looks like the following (simplified output). In the following case, 50 coins from `fromAccount` was transferred to `toAccount`, and the car ownership ("owner") was transferred from Brad to Cathy.
The result looks like the following (simplified output). In the following case, 50 coins from `fromAccount` was transferred to `toAccount`, and the asset ownership ("owner") was transferred from Brad to Cathy.
```
# Ethereum fromAccount:
Expand Down Expand Up @@ -216,8 +211,8 @@ Alice will use credentials and other Indy formats such as schema and definition
sudo rm -r ./etc/cactus/
```
1. Stop the docker containers of Ethereum, Fabric and Indy
- `docker stop geth1 cartrade_faio2x_testnet indy-testnet-pool`
- `docker rm geth1 cartrade_faio2x_testnet indy-testnet-pool`
- `docker stop geth1 asset_trade_faio2x_testnet indy-testnet-pool`
- `docker rm geth1 asset_trade_faio2x_testnet indy-testnet-pool`
1. Clear indy testnet sandbox
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright 2020-2021 Hyperledger Cactus Contributors
* Copyright 2020-2022 Hyperledger Cactus Contributors
* SPDX-License-Identifier: Apache-2.0
*
* BalanceManagement.ts
* balance-management.ts
*/

import { LPInfoHolder } from "@hyperledger/cactus-cmd-socket-server";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2021 Hyperledger Cactus Contributors
* Copyright 2020-2022 Hyperledger Cactus Contributors
* SPDX-License-Identifier: Apache-2.0
*
* balance.ts
Expand All @@ -8,7 +8,7 @@
import { Router, NextFunction, Request, Response } from "express";
import { ConfigUtil } from "@hyperledger/cactus-cmd-socket-server";
import { RIFError } from "@hyperledger/cactus-cmd-socket-server";
import { BalanceManagement } from "./BalanceManagement";
import { BalanceManagement } from "./balance-management";

const fs = require("fs");
const path = require("path");
Expand Down
Loading

0 comments on commit e7b4d3c

Please sign in to comment.