Skip to content
Snippets Groups Projects
Commit 99279831 authored by Javier Diaz's avatar Javier Diaz
Browse files

Code Cleanup

parent d2c60740
No related branches found
No related tags found
2 merge requests!294Release TeraFlowSDN 4.0,!259Resolve "(CTTC) Replace DLT Gateway functionality with an opensource and Hyper Ledger v2.4+ compliant version"
# ADRENALINE DLT App
<figure>
<img src="./resources/System.png"
alt="DLT Gateway for chaincode interaction"
width="960"
height="480">
<figcaption>DLT_APP for chaincode tests.</figcaption>
</figure>
# DLT Gateway
## Description
The DLT app consists of a **fabricConnect.ts** TypeScript file, which contains the logic for identification management (certificates required for the MSP), connection management to the blockchain, and finally, it exposes a contract object with all the required information for interacting with the chaincode. The **fabricConnect.ts** is coded following the Fabric Gateway API recommendations from Hyperledger Fabric 2.4+. The compiled **fabricConnect.ts** logic is imported into a **dltGateway.js** file, which contains the gRPC logic for interaction with the TFS controller. Testing code for various performance tests is included inside the [/dltApp/tests](./dltApp/tests/) folder.
The DLT Gateway consists of a **fabricConnect.ts** TypeScript file, which contains the logic for identification management (certificates required for the MSP), connection management to the blockchain, and finally, it exposes a contract object with all the required information for interacting with the chaincode. The **fabricConnect.ts** is coded following the Fabric Gateway API recommendations from Hyperledger Fabric 2.4+. The compiled **fabricConnect.ts** logic is imported into a **dltGateway.js** file, which contains the gRPC logic for interaction with the TFS controller. Testing code for various performance tests is included inside the [/tests](./tests/) folder.
The chaincode is written in Go, providing a reference for the operations that are recorded in the blockchain. This chaincode must already be deployed in a working Hyperledger Fabric blockchain.
......@@ -20,38 +12,3 @@ The chaincode is written in Go, providing a reference for the operations that ar
* Docker
* K8s
## Building the App
Install the dependencies and compile the source code.
```bash
npm install
```
## Packing the App
The [automation](./automation/) folder contains the Dockerfiles and Kubernetes configuration files alongside deployment scripts.
### Build a Docker Image
Using the Dockerfile, create a Docker image of the Gateway.
```bash
docker build -t your-username/dltgateway:v1.0.0 .
```
If necessary, upload the Docker image to a Docker repository for convenience. (You can work with the local image if deploying the Kubernetes service on the same machine.)
```bash
docker push your-username/dltgateway:v1.0.0
```
### Run the Deployment Script
Make the necessary changes to the environment variables inside the **configmap.yaml** according to the specific Fabric deployment. Also, update the path in the **persistent-volume.yaml** with the correct information.
```bash
./deploy_dlt_gateway.sh
```
Once the Kubernetes service is deployed, TFS can perform gRPC requests to as usual.
\ No newline at end of file
{
"name": "adrenalineDLT_APP",
"name": "dlt_gateway",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "adrenalineDLT_APP",
"name": "dlt_gateway",
"version": "1.0.0",
"license": "Apache-2.0",
"dependencies": {
......
{
"name": "adrenalineDLT_APP",
"name": "dlt_gateway",
"version": "1.0.0",
"description": "A DLT application that record and manages topology data as JSON implemented in typeScript using fabric-gateway",
"description": "A DLT application that record and manages network related data as JSON, implemented in typeScript using HLF fabric-gateway",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"engines": {
......@@ -13,7 +13,7 @@
"lint": "eslint . --ext .ts",
"prepare": "npm run build",
"pretest": "npm run lint",
"start": "node dist/adrenalineDLT_app.js"
"start": "node dist/dlt_gateway.js"
},
"engineStrict": true,
"author": "CTTC-Javier",
......
......@@ -9,8 +9,7 @@
"noImplicitAny": true
},
"include": [
"./src/**/*"
, "src.old/grpcClient.js", "src.old/grpcServer.js", "tests/testEvents.js", "tests/testGateway.js" ],
"./src/**/*" ],
"exclude": [
"./src/**/*.spec.ts"
]
......
......@@ -12,15 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.
const { connectToNetwork } = require('../dist/fabricConnect');
const { connectToNetwork } = require('../dltApp/dist/fabricConnect');
const fsp = require('fs').promises;
const fs = require('fs');
const util = require('util');
const utf8Decoder = new TextDecoder();
const topoDirectory = '../samples/';
//const topologies = ['topo1.json', 'topo2.json', 'topo3.json', 'topo4.json'];
const topologies = ['topo4.json'];
const topologies = ['topo1.json', 'topo2.json', 'topo3.json', 'topo4.json'];
//const topologies = ['topo4.json'];
const iterations = 1000;
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
const { connectToNetwork } = require('../dist/fabricConnect');
const { connectToNetwork } = require('../dltApp/dist/fabricConnect');
const fs = require('fs');
const util = require('util');
const appendFile = util.promisify(fs.appendFile);
......
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
const { connectToNetwork } = require('../dist/fabricConnect');
const { connectToNetwork } = require('../dltApp/dist/fabricConnect');
const fs = require('fs');
const util = require('util');
const appendFile = util.promisify(fs.appendFile);
......
......@@ -17,7 +17,7 @@ const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const path = require('path');
const PROTO_PATH = path.resolve(__dirname, '../proto/dlt_gateway.proto');
const PROTO_PATH = path.resolve(__dirname, '../../../../proto/dlt_gateway.proto');
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
keepCase: true,
longs: String,
......@@ -28,7 +28,7 @@ const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
const dltProto = grpc.loadPackageDefinition(packageDefinition).dlt;
const client = new dltProto.DltGatewayService(
'10.1.1.96:32001',
'10.1.1.96:32001', //Replace with TFS server IP_ADDRESS
grpc.credentials.createInsecure()
);
......
......@@ -20,7 +20,7 @@ const fs = require('fs').promises;
const { v4: uuidv4 } = require('uuid'); // Import the UUID library
const PROTO_PATH = path.resolve(__dirname, '../proto/dlt_gateway.proto');
const PROTO_PATH = path.resolve(__dirname, '../../../../proto/dlt_gateway.proto');
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
keepCase: true,
longs: String,
......@@ -40,7 +40,7 @@ const domainUuid = `domain-${uuidv4()}`; // Generate a pretty domain UUID
async function getTopoData(filename) {
try {
const data = await fs.readFile(`../../samples/${filename}`, 'utf8');
const data = await fs.readFile(`../samples/${filename}`, 'utf8');
return data;
} catch (error) {
console.error('Failed to read file:', filename, error);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment