Skip to content

Commit

Permalink
refactor(cbdc-example): using sdk for the oapi requests to the gatewa…
Browse files Browse the repository at this point in the history
…ys, readme update, package.json, dockerfiles update, frontend does requests to the backend, rename destiny to receipient, fix bugs

Signed-off-by: Carlos Amaro <carlosrscamaro@tecnico.ulisboa.pt>
  • Loading branch information
LordKubaya committed Oct 15, 2024
1 parent 34c81e7 commit 078f0d9
Show file tree
Hide file tree
Showing 283 changed files with 11,882 additions and 42,867 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ weaver/common/protos-js/build/
**/src/main/typescript/generated/proto/**
**/src/main/typescript/generated/wasm-pack/**

packages/cactus-plugin-satp-hermes/src/main/typescript/generated/*

examples/cactus-common-example-server/src/main/typescript/business-logic-plugin/BusinessLogicBase.ts
examples/cactus-common-example-server/src/main/typescript/business-logic-plugin/LedgerOperation.ts
examples/cactus-common-example-server/src/main/typescript/business-logic-plugin/app.ts
Expand Down
2 changes: 0 additions & 2 deletions examples/cactus-example-cbdc-bridging-backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ COPY ./examples/cactus-example-cbdc-bridging-backend/healthcheck.sh /
ENV API_HOST=localhost
ENV API_SERVER_1_PORT=4000
ENV API_SERVER_2_PORT=4100
ENV API_HOST_FRONTEND=localhost
ENV API_PORT_FRONTEND=2000
ENV API_GATEWAY_1_BLO_PORT=4010
ENV API_GATEWAY_2_BLO_PORT=4110
ENV API_GATEWAY_1_CLIENT_PORT=3011
Expand Down
27 changes: 21 additions & 6 deletions examples/cactus-example-cbdc-bridging-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,46 @@
On the terminal, issue the following commands in the project root:

1. `npm run configure`
2. `npm run start:example-cbdc-bridging-app`
1. `yarn run configure`
2. `yarn run start:example-cbdc-bridging-app`

Wait for the output to show the message `CbdcBridgingApp running...`

In a second terminal run the following commands from the project root:
3. `cd examples/cactus-example-cbdc-bridging-backend`
4. `npm run test`
4. `yarn run test`

## Running the Example Application Locally

> Make sure you have all the dependencies set up as explained in `BUILD.md`
On the terminal, issue the following commands:

1. `npm run configure`
2. `npm run start:example-cbdc-bridging-app`
1. `yarn run configure`
2. `yarn run start:example-cbdc-bridging-app`

Wait for the output to show the message `CbdcBridgingApp running...`

## Running with a different configuration

There is a `process.env` file where you can change the following variables:
```
API_HOST=localhost // the path where the backend will be running
API_SERVER_1_PORT=4000 // port assign to the FabricConnectorApi
API_SERVER_2_PORT=4100 // port assign to the BesuConnectorApi
API_GATEWAY_1_BLO_PORT=4010 // port assign to the Gateway1's OpenApi Service
API_GATEWAY_2_BLO_PORT=4110 // port assign to the Gateway2's SATP Service
API_GATEWAY_1_CLIENT_PORT=3011 // port assign to the Gateway1's SATP Client Service
API_GATEWAY_2_CLIENT_PORT=3111 // port assign to the Gateway2's SATP Client Service
API_GATEWAY_1_SERVER_PORT=3010 // port assign to the Gateway1's SATP Server Service
API_GATEWAY_2_SERVER_PORT=3110 // port assign to the Gateway2's SATP Server Service
```

## Debugging the Example Application Locally

On the terminal, issue the following commands (steps 1 to 6) and then perform the rest of the steps manually.

1. `npm run configure`
1. `yarn run configure`
2. Locate the `.vscode/template.launch.json` file
3. Within that file locate the entry named `"Example: CBDC Bridging Fabric-EVM App"`
4. Copy the VSCode debug definition object from 2) to your `.vscode/launch.json` file
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "7.8.0"
}
}
30 changes: 23 additions & 7 deletions examples/cactus-example-cbdc-bridging-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@
"contributors": [
{
"name": "Eduardo Vasques",
"email": "eduardovasques10@tecnico.ulisboa.pt",
"url": "https://example.com"
"email": "eduardovasques10@tecnico.ulisboa.pt"
},
{
"name": "André Augusto",
"email": "andre.augusto@tecnico.ulisboa.pt"
},
{
"name": "Carlos Amaro",
"email": "carlosrscamaro@tecnico.ulisboa.pt"
}
],
"main": "dist/lib/main/typescript/index.js",
Expand All @@ -46,16 +49,24 @@
"scripts": {
"build:dev:backend:postbuild": "mkdir -p ./dist/lib/fabric-contracts && cp -r ./src/fabric-contracts/* ./dist/lib/fabric-contracts/",
"forge": "forge build ./src/solidity/main/*.sol --out ./src/solidity/main/generated",
"forge:all": "yarn run --top-level run-s 'forge' 'forge:test'",
"forge:all": "run-s 'forge' 'forge:test'",
"forge:test": "forge build ./src/solidity/test/*.sol --out ./src/solidity/test/generated",
"solidity": "hardhat compile",
"start": "node dist/lib/main/typescript/cbdc-bridging-app-cli.js dotenv_config_path=./process.env",
"start": "npx ts-node ./src/main/typescript/cbdc-bridging-app-cli.ts dotenv_config_path=./process.env",
"test": "nyc cucumber-js ./src/test/typescript/cucumber/features/*.feature --require-module ts-node/register --require './src/test/typescript/cucumber/*/*.ts'",
"watch": "npm-watch",
"webpack": "npm-run-all webpack:dev",
"webpack:dev": "npm-run-all webpack:dev:node webpack:dev:web",
"webpack:dev:node": "webpack --env=dev --target=node --config ../../webpack.config.js",
"webpack:dev:web": "webpack --env=dev --target=web --config ../../webpack.config.js"
"webpack:dev:web": "webpack --env=dev --target=web --config ../../webpack.config.js",
"codegen": "run-p 'codegen:*'",
"codegen:openapi": "npm run generate-sdk",
"generate-sdk": "run-p 'generate-sdk:*'",
"generate-sdk:typescript-axios": "yarn bundle-openapi-yaml && yarn bundle-openapi-json && openapi-generator-cli generate -i ./src/main/yml/openapi-bundled.yml -g typescript-axios -o ./src/main/typescript/generated/openapi/typescript-axios/ --reserved-words-mappings protected=protected --enable-post-process-file",
"generate-sdk:go": "openapi-generator-cli generate -i ./src/main/yml/openapi.yml -g go -o ./src/main/go/generated/openapi --additional-properties=packageName=generated,generateInterfaces=true,packageVersion=v0.0.1,moduleName=github.com/hyperledger/cacti/examples/cactus-example-cbdc-bridging-backend/src/main/go/generated --git-user-id hyperledger --git-repo-id cacti/examples/cactus-example-cbdc-bridging-backend/src/main/go/generated",
"bundle-openapi-yaml": "swagger-cli bundle ./src/main/yml/openapi.yml -o ./src/main/yml/openapi-bundled.yml -r -t yaml",
"bundle-openapi-json": "swagger-cli bundle ./src/main/yml/openapi.yml -o ./src/main/json/openapi-bundled.json -r -t json",
"lint:oapi": "vacuum lint -d -e ./src/main/yml/openapi-bundled.yml"
},
"dependencies": {
"@foundry-rs/hardhat-forge": "0.1.17",
Expand Down Expand Up @@ -92,23 +103,28 @@
"typescript-optional": "2.0.1",
"uuid": "9.0.1",
"web3-core": "1.10.1",
"web3-utils": "1.10.1"
"web3-utils": "1.10.1",
"webpack": "^5.94.0"
},
"devDependencies": {
"@apidevtools/swagger-cli": "4.0.4",
"@types/crypto-js": "4.1.1",
"@types/cucumber": "4.0.4",
"@types/express": "5.0.0",
"@types/express-jwt": "6.0.2",
"@types/fs-extra": "9.0.13",
"@types/node": "18.11.9",
"@types/swagger-ui-express": "4.1.6",
"@types/uuid": "9.0.8",
"cucumber": "5.0.3",
"ethereum-abi-types-generator": "1.3.4",
"hardhat": "2.17.2",
"http-status-codes": "2.1.4",
"jose": "4.15.5",
"npm-run-all": "4.1.5",
"remix-tests": "0.1.34",
"ts-node": "7.0.1"
"swagger-cli": "4.0.4",
"ts-node": "10.9.2"
},
"engines": {
"node": ">=18",
Expand Down
2 changes: 0 additions & 2 deletions examples/cactus-example-cbdc-bridging-backend/process.env
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
API_HOST=localhost
API_SERVER_1_PORT=4000
API_SERVER_2_PORT=4100
API_HOST_FRONTEND=localhost
API_PORT_FRONTEND=2000
API_GATEWAY_1_BLO_PORT=4010
API_GATEWAY_2_BLO_PORT=4110
API_GATEWAY_1_CLIENT_PORT=3011
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
.gitignore
.openapi-generator-ignore
.travis.yml
README.md
api/openapi.yaml
api_approve.go
api_get_amount_approved.go
api_get_balance.go
api_get_sessions_references.go
api_mint.go
api_transact.go
api_transfer.go
client.go
configuration.go
docs/APIError.md
docs/ApproveAPI.md
docs/ApproveRequest.md
docs/AssetType.md
docs/BalanceResponse.md
docs/GetAmountApprovedAPI.md
docs/GetBalanceAPI.md
docs/GetSessionsReferencesAPI.md
docs/MintAPI.md
docs/MintRequest.md
docs/SessionReference.md
docs/StatusResponse.md
docs/TransactAPI.md
docs/TransactRequest.md
docs/TransactResponse.md
docs/TransferAPI.md
docs/TransferRequest.md
git_push.sh
go.mod
go.sum
model_api_error.go
model_approve_request.go
model_asset_type.go
model_balance_response.go
model_mint_request.go
model_session_reference.go
model_status_response.go
model_transact_request.go
model_transact_response.go
model_transfer_request.go
response.go
test/api_approve_test.go
test/api_get_amount_approved_test.go
test/api_get_balance_test.go
test/api_get_sessions_references_test.go
test/api_mint_test.go
test/api_transact_test.go
test/api_transfer_test.go
utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.8.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Go API client for generated

Cactus-Example


## Overview
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client.

- API version: 0.0.2
- Package version: v0.0.1
- Generator version: 7.8.0
- Build package: org.openapitools.codegen.languages.GoClientCodegen

## Installation

Install the following dependencies:

```sh
go get github.com/stretchr/testify/assert
go get golang.org/x/net/context
```

Put the package under your project folder and add the following in import:

```go
import generated "github.com/hyperledger/cacti/examples/cactus-example-cbdc-bridging-backend/src/main/go/generated"
```

To use a proxy, set the environment variable `HTTP_PROXY`:

```go
os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")
```

## Configuration of Server URL

Default configuration comes with `Servers` field that contains server objects as defined in the OpenAPI specification.

### Select Server Configuration

For using other server than the one defined on index 0 set context value `generated.ContextServerIndex` of type `int`.

```go
ctx := context.WithValue(context.Background(), generated.ContextServerIndex, 1)
```

### Templated Server URL

Templated server URL is formatted using default variables from configuration or from context value `generated.ContextServerVariables` of type `map[string]string`.

```go
ctx := context.WithValue(context.Background(), generated.ContextServerVariables, map[string]string{
"basePath": "v2",
})
```

Note, enum values are always validated and all unused variables are silently ignored.

### URLs Configuration per Operation

Each operation can use different server URL defined using `OperationServers` map in the `Configuration`.
An operation is uniquely identified by `"{classname}Service.{nickname}"` string.
Similar rules for overriding default operation server index and variables applies by using `generated.ContextOperationServerIndices` and `generated.ContextOperationServerVariables` context maps.

```go
ctx := context.WithValue(context.Background(), generated.ContextOperationServerIndices, map[string]int{
"{classname}Service.{nickname}": 2,
})
ctx = context.WithValue(context.Background(), generated.ContextOperationServerVariables, map[string]map[string]string{
"{classname}Service.{nickname}": {
"port": "8443",
},
})
```

## Documentation for API Endpoints

All URIs are relative to *http://localhost*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*ApproveAPI* | [**Approve**](docs/ApproveAPI.md#approve) | **Post** /api/v1/@hyperledger/cactus-example-cbdc/approve-tokens | Submit a transaction intent
*GetAmountApprovedAPI* | [**GetAmountApproved**](docs/GetAmountApprovedAPI.md#getamountapproved) | **Get** /api/v1/@hyperledger/cactus-example-cbdc/get-amount-approved | Get the amount approved for a transaction
*GetBalanceAPI* | [**GetBalance**](docs/GetBalanceAPI.md#getbalance) | **Get** /api/v1/@hyperledger/cactus-example-cbdc/get-balance |
*GetSessionsReferencesAPI* | [**GetSessionsReferences**](docs/GetSessionsReferencesAPI.md#getsessionsreferences) | **Get** /api/v1/@hyperledger/cactus-example-cbdc/get-sessions-references | Get SATP current sessions data
*MintAPI* | [**Mint**](docs/MintAPI.md#mint) | **Post** /api/v1/@hyperledger/cactus-example-cbdc/mint-tokens | Submit a transaction intent
*TransactAPI* | [**Transact**](docs/TransactAPI.md#transact) | **Post** /api/v1/@hyperledger/cactus-example-cbdc/transact | Submit a transaction intent
*TransferAPI* | [**Transfer**](docs/TransferAPI.md#transfer) | **Post** /api/v1/@hyperledger/cactus-example-cbdc/transfer-tokens | Submit a transaction intent


## Documentation For Models

- [APIError](docs/APIError.md)
- [ApproveRequest](docs/ApproveRequest.md)
- [AssetType](docs/AssetType.md)
- [BalanceResponse](docs/BalanceResponse.md)
- [MintRequest](docs/MintRequest.md)
- [SessionReference](docs/SessionReference.md)
- [StatusResponse](docs/StatusResponse.md)
- [TransactRequest](docs/TransactRequest.md)
- [TransactResponse](docs/TransactResponse.md)
- [TransferRequest](docs/TransferRequest.md)


## Documentation For Authorization

Endpoints do not require authorization.


## Documentation for Utility Methods

Due to the fact that model structure members are all pointers, this package contains
a number of utility functions to easily obtain pointers to values of basic types.
Each of these functions takes a value of the given basic type and returns a pointer to it:

* `PtrBool`
* `PtrInt`
* `PtrInt32`
* `PtrInt64`
* `PtrFloat`
* `PtrFloat32`
* `PtrFloat64`
* `PtrString`
* `PtrTime`

## Author



Loading

0 comments on commit 078f0d9

Please sign in to comment.