Skip to content

Commit

Permalink
feat(verifier): adapt Verifier to http-typed events
Browse files Browse the repository at this point in the history
Signed-off-by: Takuma TAKEUCHI <takeuchi.takuma@fujitsu.com>
  • Loading branch information
takeutak committed Mar 30, 2021
1 parent 24f8c25 commit 01f20d0
Show file tree
Hide file tree
Showing 85 changed files with 1,242 additions and 280 deletions.
17 changes: 0 additions & 17 deletions examples/run-transaction/supply-chain-app-stub/app/routes/cars.ts

This file was deleted.

17 changes: 0 additions & 17 deletions examples/run-transaction/supply-chain-app-stub/app/routes/index.ts

This file was deleted.

17 changes: 0 additions & 17 deletions examples/run-transaction/supply-chain-app-stub/app/routes/login.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { transactionManagement } from '../../packages/routing-interface/routes/i
import { verifierFactory } from '../../packages/routing-interface/routes/index';
import { BusinessLogicBase } from '../../packages/business-logic-plugin/BusinessLogicBase';
//import { makeRawTransaction } from './TransactionEthereum'
//import { LedgerEvent } from '../../packages/ledger-plugin/LedgerPlugin';
import { LedgerEvent } from '../../packages/ledger-plugin/LedgerPlugin';
import { json2str } from '../../packages/ledger-plugin/DriverCommon'

const fs = require('fs');
Expand Down Expand Up @@ -65,12 +65,16 @@ export class BusinessLogicRunTransaction extends BusinessLogicBase {
logger.debug("called execTransaction()");

const useValidator = JSON.parse(transactionManagement.getValidatorToUse(tradeInfo.businessLogicID));

// TODO: Temporarily specify no monitoring required (# 3rd parameter = false)
const verifier = verifierFactory.getVerifier(useValidator['validatorID'][0], {}, false);
logger.debug("getVerifier");

// TODO: for Temporarily specify no monitoring required (# 3rd parameter = false)
verifier.setEventListener(transactionManagement);

const contract = {};
const method = {command: "run-transaction"};
const method = {command: "test-run-transaction"};
const args = {"args": {
"keychainId": requestInfo.keychainId,
"keychainRef": requestInfo.keychainRef,
Expand All @@ -80,8 +84,43 @@ export class BusinessLogicRunTransaction extends BusinessLogicBase {
"functionArgs": requestInfo.functionArgs
}};

logger.debug(`##before call verifier.requestLedgerOperationHttp()`);
verifier.requestLedgerOperationHttp(contract, method, args);
logger.debug(`##after call verifier.requestLedgerOperationHttp()`);

}


onEvent(ledgerEvent: LedgerEvent, targetIndex: number): void {
logger.debug(`##in BLP:onEvent()`);
logger.debug(`##onEvent(): ${json2str(ledgerEvent)}`);
}


getEventDataNum(ledgerEvent: LedgerEvent): number {
// NOTE: This method implements the BisinessLogcPlugin operation(* Override by subclass)
// TODO:
logger.debug(`##in getEventDataNum(), ledgerEvent: ${JSON.stringify(ledgerEvent)}`);
const retEventNum = ledgerEvent.data['blockData'].length;
logger.debug(`##retEventNum: ${retEventNum}`);
return retEventNum;
}


getTxIDFromEvent(ledgerEvent: LedgerEvent, targetIndex: number): string | null {
// NOTE: This method implements the BisinessLogcPlugin operation(* Override by subclass)
// TODO:
logger.debug(`##in getTxIDFromEvent(), ledgerEvent: ${JSON.stringify(ledgerEvent)}`);

const txId = ledgerEvent.data['txId'];

if (typeof txId !== 'string') {
logger.warn(`#getTxIDFromEvent(): skip(invalid block, not found txId.), event: ${json2str(ledgerEvent)}`);
return null;
}

logger.debug(`###getTxIDFromEvent(): txId: ${txId}`);
return txId;
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# run-transaction
# test-run-transaction

A proto-code of communication feature to http-type Validator for Verifier
A proto-code of communication feature to http-typed Validator for Verifier

## Setup for communication app with http-server

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"runTransactionInfo": {
"connector": {
"validatorID": "vIdAcnCF"
"validatorID": "vIdO32CF"
}
},
"logLevel": "debug"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"blpRegistry": [
{
"businessLogicID": "j71S9gLN",
"validatorID": ["vIdAcnCF"]
"validatorID": ["vIdO32CF"]
}
],
"logLevel": "debug",
Expand All @@ -12,8 +12,8 @@
},
"appRouters": [
{
"path": "/api/v1/bl/run-transaction/",
"routerJs": "../../examples/run-transaction/run-transaction.js"
"path": "/api/v1/bl/test-run-transaction/",
"routerJs": "../../examples/test-run-transaction/test-run-transaction.js"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ import * as shell from 'shelljs';
// NOTE: Copy the static assets to the dist folder.
// Example:
// shell.cp('-R', 'src/routing-interface/views', 'dist/routing-interface/views/');
shell.cp('../../dist/examples/run-transaction/config/BLP_config.js', '../../dist/packages/config/');
shell.cp('../../dist/examples/test-run-transaction/config/BLP_config.js', '../../dist/packages/config/');
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import * as shell from 'shelljs';
// NOTE: Copy the static assets to the dist folder.
// Example:
// shell.cp('-R', 'src/routing-interface/views', 'dist/routing-interface/views/');
shell.cp('-R', 'config/default.json', '../../dist/examples/run-transaction/config/');
shell.cp('-R', 'config/default.json', '../../dist/examples/test-run-transaction/config/');
shell.cp('-R', 'config/usersetting.json', '../../dist/packages/config/');
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "run-transaction",
"name": "test-run-transaction",
"private": true,
"scripts": {
"start": "node ../../dist/packages/routing-interface/www.js",
Expand All @@ -10,7 +10,7 @@
"copy-static-assets": "ts-node copyStaticAssets.ts",
"copy-blp-config": "ts-node copyBLPConfig.ts",
"replace-blp-config-path": "ts-node replaceBLPConfigPath.ts",
"init-run-transaction": "ln -s ../examples/run-transaction/node_modules ../../dist/node_modules"
"init-test-run-transaction": "ln -s ../examples/test-run-transaction/node_modules ../../dist/node_modules"
},
"dependencies": {
"@types/node": "^14.0.24",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const fs = require('fs')

const targetFile = '../../dist/packages/config/BLP_config.js';
const srcStr = '"../BusinessLogicRunTransaction"';
const distStr = '"../../examples/run-transaction/BusinessLogicRunTransaction"';
const distStr = '"../../examples/test-run-transaction/BusinessLogicRunTransaction"';

fs.readFile(targetFile, 'utf8', (readErr, data) => {
if (readErr) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright 2021 Hyperledger Cactus Contributors
* SPDX-License-Identifier: Apache-2.0
*
* app.ts
*/

// Load the library
import express from 'express';
import helmet from 'helmet';
Expand All @@ -7,7 +14,7 @@ app.use(helmet());
app.use(cors());
const bodyParser = require('body-parser');

import indexRouter from './routes/index';
//import indexRouter from './routes/index';
///import loginRouter from './routes/login';
//import carsRouter from './routes/cars';
//var carsRouter = require('./routes/cars.js').default;
Expand All @@ -18,16 +25,16 @@ import indexRouter from './routes/index';
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

app.use('/api/v1/', indexRouter);
//app.use('/api/v1/', indexRouter);
//app.use('/api/v1/login/', loginRouter);
//app.use('/api/v1/cars/', carsRouter);

// Dynamic loading
console.debug(`start Dynamic loading`);
const targetJsArray = [
{uri: '/api/v1/login/', jsPath: './routes/login.js'},
{uri: '/api/v1/cars/', jsPath: './routes/cars.js'},
{uri: '/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-fabric/run-transaction/', jsPath: './routes/supply-chain-app.js'}
// {uri: '/api/v1/login/', jsPath: './routes/login.js'},
// {uri: '/api/v1/cars/', jsPath: './routes/cars.js'},
{uri: '/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-fabric/test-run-transaction/', jsPath: './routes/supply-chain-app.js'}
];
for (var targetJs of targetJsArray) {
console.debug(`url: ${targetJs.uri}, jsPath: ${targetJs.jsPath}`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright 2021 Hyperledger Cactus Contributors
* SPDX-License-Identifier: Apache-2.0
*
* supply-chain-app.ts
*/

import { Router, NextFunction, Request, Response } from 'express';

const router: Router = Router();
Expand Down Expand Up @@ -25,12 +32,27 @@ router.post('/', (req: Request, res: Response, next: NextFunction) => {
console.debug(`invocationType: ${req.body.invocationType}`);
console.debug(`functionName: ${req.body.functionName}`);
console.debug(`functionArgs: ${req.body.functionArgs}`);
res.status(200).send(JSON.stringify({"supply-chain-app": "POST..."}));
sleep(5, function() {
console.debug(`##send response`);
res.status(200).send(JSON.stringify({"supply-chain-app": "POST..."}));
});

} catch (err) {
next(err);
}
});


function sleep(waitSec: number, callbackFunc: any) {
var spanedSec = 0;
var id = setInterval(function () {
spanedSec++;
if (spanedSec >= waitSec) {
clearInterval(id);
if (callbackFunc) callbackFunc();
}
}, 1000);

}

export default router;
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"@types/express": "^4.17.11"
},
"scripts": {
"start": "node app/app.js",
"build": "npx tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright 2021 Hyperledger Cactus Contributors
* SPDX-License-Identifier: Apache-2.0
*
* run-transaction.ts
* test-run-transaction.ts
*/

import { Router, NextFunction, Request, Response } from 'express';
Expand All @@ -14,17 +14,17 @@ const fs = require('fs');
const path = require('path');
const config: any = ConfigUtil.getConfig();
import { getLogger } from "log4js";
const moduleName = 'run-transaction';
const moduleName = 'test-run-transaction';
const logger = getLogger(`${moduleName}`);
logger.level = config.logLevel;

const router: Router = Router();
export const transactionManagement: TransactionManagement = new TransactionManagement();

// Request Execution of Run-Transaction
// Request Execution of Test-Run-Transaction
router.post('/', (req: Request, res: Response, next: NextFunction) => {
try {
console.log("run-transaction()");
console.log("test-run-transaction()");
const tradeID: string = transactionManagement.startBusinessLogic(req);

const result = {tradeID: tradeID};
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"businessLogicID": "j71S9gLN",
"validatorID": ["vIdAcnCF"]
"validatorID": ["vIdO32CF"]
}
],
"logLevel": "debug",
Expand Down
6 changes: 3 additions & 3 deletions packages/config/verifier-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"apiInfo": []
},
{
"validatorID": "vIdAcnCB",
"validatorID": "vIdO32CB",
"validatorURL": "http://localhost:5053/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/",
"validatorKeyPath": "",
"ledgerInfo": {
Expand All @@ -100,7 +100,7 @@
"apiInfo": []
},
{
"validatorID": "vIdAcnCF",
"validatorID": "vIdO32CF",
"validatorURL": "http://localhost:5053/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-fabric/",
"validatorKeyPath": "",
"ledgerInfo": {
Expand All @@ -109,7 +109,7 @@
"apiInfo": []
},
{
"validatorID": "vIdAcnCQ",
"validatorID": "vIdO32CQ",
"host": "http://localhost:5053/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-quorum/",
"validatorKeyPath": "",
"ledgerInfo": {
Expand Down

0 comments on commit 01f20d0

Please sign in to comment.