Skip to content

Commit 01f20d0

Browse files
committed
feat(verifier): adapt Verifier to http-typed events
Signed-off-by: Takuma TAKEUCHI <[email protected]>
1 parent 24f8c25 commit 01f20d0

File tree

85 files changed

+1242
-280
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1242
-280
lines changed

examples/run-transaction/supply-chain-app-stub/app/routes/cars.ts

-17
This file was deleted.

examples/run-transaction/supply-chain-app-stub/app/routes/index.ts

-17
This file was deleted.

examples/run-transaction/supply-chain-app-stub/app/routes/login.ts

-17
This file was deleted.

examples/run-transaction/BusinessLogicRunTransaction.ts renamed to examples/test-run-transaction/BusinessLogicRunTransaction.ts

+41-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { transactionManagement } from '../../packages/routing-interface/routes/i
1414
import { verifierFactory } from '../../packages/routing-interface/routes/index';
1515
import { BusinessLogicBase } from '../../packages/business-logic-plugin/BusinessLogicBase';
1616
//import { makeRawTransaction } from './TransactionEthereum'
17-
//import { LedgerEvent } from '../../packages/ledger-plugin/LedgerPlugin';
17+
import { LedgerEvent } from '../../packages/ledger-plugin/LedgerPlugin';
1818
import { json2str } from '../../packages/ledger-plugin/DriverCommon'
1919

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

6767
const useValidator = JSON.parse(transactionManagement.getValidatorToUse(tradeInfo.businessLogicID));
68+
6869
// TODO: Temporarily specify no monitoring required (# 3rd parameter = false)
6970
const verifier = verifierFactory.getVerifier(useValidator['validatorID'][0], {}, false);
7071
logger.debug("getVerifier");
7172

73+
// TODO: for Temporarily specify no monitoring required (# 3rd parameter = false)
74+
verifier.setEventListener(transactionManagement);
75+
7276
const contract = {};
73-
const method = {command: "run-transaction"};
77+
const method = {command: "test-run-transaction"};
7478
const args = {"args": {
7579
"keychainId": requestInfo.keychainId,
7680
"keychainRef": requestInfo.keychainRef,
@@ -80,8 +84,43 @@ export class BusinessLogicRunTransaction extends BusinessLogicBase {
8084
"functionArgs": requestInfo.functionArgs
8185
}};
8286

87+
logger.debug(`##before call verifier.requestLedgerOperationHttp()`);
8388
verifier.requestLedgerOperationHttp(contract, method, args);
89+
logger.debug(`##after call verifier.requestLedgerOperationHttp()`);
90+
91+
}
92+
93+
94+
onEvent(ledgerEvent: LedgerEvent, targetIndex: number): void {
95+
logger.debug(`##in BLP:onEvent()`);
96+
logger.debug(`##onEvent(): ${json2str(ledgerEvent)}`);
97+
}
98+
99+
100+
getEventDataNum(ledgerEvent: LedgerEvent): number {
101+
// NOTE: This method implements the BisinessLogcPlugin operation(* Override by subclass)
102+
// TODO:
103+
logger.debug(`##in getEventDataNum(), ledgerEvent: ${JSON.stringify(ledgerEvent)}`);
104+
const retEventNum = ledgerEvent.data['blockData'].length;
105+
logger.debug(`##retEventNum: ${retEventNum}`);
106+
return retEventNum;
107+
}
108+
109+
110+
getTxIDFromEvent(ledgerEvent: LedgerEvent, targetIndex: number): string | null {
111+
// NOTE: This method implements the BisinessLogcPlugin operation(* Override by subclass)
112+
// TODO:
113+
logger.debug(`##in getTxIDFromEvent(), ledgerEvent: ${JSON.stringify(ledgerEvent)}`);
114+
115+
const txId = ledgerEvent.data['txId'];
116+
117+
if (typeof txId !== 'string') {
118+
logger.warn(`#getTxIDFromEvent(): skip(invalid block, not found txId.), event: ${json2str(ledgerEvent)}`);
119+
return null;
120+
}
84121

122+
logger.debug(`###getTxIDFromEvent(): txId: ${txId}`);
123+
return txId;
85124
}
86125

87126

examples/run-transaction/README.md renamed to examples/test-run-transaction/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# run-transaction
1+
# test-run-transaction
22

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

55
## Setup for communication app with http-server
66

examples/run-transaction/config/default.json renamed to examples/test-run-transaction/config/default.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"runTransactionInfo": {
33
"connector": {
4-
"validatorID": "vIdAcnCF"
4+
"validatorID": "vIdO32CF"
55
}
66
},
77
"logLevel": "debug"

examples/run-transaction/config/usersetting.json renamed to examples/test-run-transaction/config/usersetting.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"blpRegistry": [
33
{
44
"businessLogicID": "j71S9gLN",
5-
"validatorID": ["vIdAcnCF"]
5+
"validatorID": ["vIdO32CF"]
66
}
77
],
88
"logLevel": "debug",
@@ -12,8 +12,8 @@
1212
},
1313
"appRouters": [
1414
{
15-
"path": "/api/v1/bl/run-transaction/",
16-
"routerJs": "../../examples/run-transaction/run-transaction.js"
15+
"path": "/api/v1/bl/test-run-transaction/",
16+
"routerJs": "../../examples/test-run-transaction/test-run-transaction.js"
1717
}
1818
]
1919
}

examples/run-transaction/copyBLPConfig.ts renamed to examples/test-run-transaction/copyBLPConfig.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ import * as shell from 'shelljs';
1010
// NOTE: Copy the static assets to the dist folder.
1111
// Example:
1212
// shell.cp('-R', 'src/routing-interface/views', 'dist/routing-interface/views/');
13-
shell.cp('../../dist/examples/run-transaction/config/BLP_config.js', '../../dist/packages/config/');
13+
shell.cp('../../dist/examples/test-run-transaction/config/BLP_config.js', '../../dist/packages/config/');

examples/run-transaction/copyStaticAssets.ts renamed to examples/test-run-transaction/copyStaticAssets.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ import * as shell from 'shelljs';
1010
// NOTE: Copy the static assets to the dist folder.
1111
// Example:
1212
// shell.cp('-R', 'src/routing-interface/views', 'dist/routing-interface/views/');
13-
shell.cp('-R', 'config/default.json', '../../dist/examples/run-transaction/config/');
13+
shell.cp('-R', 'config/default.json', '../../dist/examples/test-run-transaction/config/');
1414
shell.cp('-R', 'config/usersetting.json', '../../dist/packages/config/');

examples/run-transaction/package.json renamed to examples/test-run-transaction/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "run-transaction",
2+
"name": "test-run-transaction",
33
"private": true,
44
"scripts": {
55
"start": "node ../../dist/packages/routing-interface/www.js",
@@ -10,7 +10,7 @@
1010
"copy-static-assets": "ts-node copyStaticAssets.ts",
1111
"copy-blp-config": "ts-node copyBLPConfig.ts",
1212
"replace-blp-config-path": "ts-node replaceBLPConfigPath.ts",
13-
"init-run-transaction": "ln -s ../examples/run-transaction/node_modules ../../dist/node_modules"
13+
"init-test-run-transaction": "ln -s ../examples/test-run-transaction/node_modules ../../dist/node_modules"
1414
},
1515
"dependencies": {
1616
"@types/node": "^14.0.24",

examples/run-transaction/replaceBLPConfigPath.ts renamed to examples/test-run-transaction/replaceBLPConfigPath.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const fs = require('fs')
88

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

1313
fs.readFile(targetFile, 'utf8', (readErr, data) => {
1414
if (readErr) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.js

examples/run-transaction/supply-chain-app-stub/app/app.ts renamed to examples/test-run-transaction/supply-chain-app-stub/app/app.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*
2+
* Copyright 2021 Hyperledger Cactus Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* app.ts
6+
*/
7+
18
// Load the library
29
import express from 'express';
310
import helmet from 'helmet';
@@ -7,7 +14,7 @@ app.use(helmet());
714
app.use(cors());
815
const bodyParser = require('body-parser');
916

10-
import indexRouter from './routes/index';
17+
//import indexRouter from './routes/index';
1118
///import loginRouter from './routes/login';
1219
//import carsRouter from './routes/cars';
1320
//var carsRouter = require('./routes/cars.js').default;
@@ -18,16 +25,16 @@ import indexRouter from './routes/index';
1825
app.use(bodyParser.urlencoded({ extended: true }));
1926
app.use(bodyParser.json());
2027

21-
app.use('/api/v1/', indexRouter);
28+
//app.use('/api/v1/', indexRouter);
2229
//app.use('/api/v1/login/', loginRouter);
2330
//app.use('/api/v1/cars/', carsRouter);
2431

2532
// Dynamic loading
2633
console.debug(`start Dynamic loading`);
2734
const targetJsArray = [
28-
{uri: '/api/v1/login/', jsPath: './routes/login.js'},
29-
{uri: '/api/v1/cars/', jsPath: './routes/cars.js'},
30-
{uri: '/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-fabric/run-transaction/', jsPath: './routes/supply-chain-app.js'}
35+
// {uri: '/api/v1/login/', jsPath: './routes/login.js'},
36+
// {uri: '/api/v1/cars/', jsPath: './routes/cars.js'},
37+
{uri: '/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-fabric/test-run-transaction/', jsPath: './routes/supply-chain-app.js'}
3138
];
3239
for (var targetJs of targetJsArray) {
3340
console.debug(`url: ${targetJs.uri}, jsPath: ${targetJs.jsPath}`);

examples/run-transaction/supply-chain-app-stub/app/routes/supply-chain-app.ts renamed to examples/test-run-transaction/supply-chain-app-stub/app/routes/supply-chain-app.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*
2+
* Copyright 2021 Hyperledger Cactus Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* supply-chain-app.ts
6+
*/
7+
18
import { Router, NextFunction, Request, Response } from 'express';
29

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

3040
} catch (err) {
3141
next(err);
3242
}
3343
});
3444

3545

46+
function sleep(waitSec: number, callbackFunc: any) {
47+
var spanedSec = 0;
48+
var id = setInterval(function () {
49+
spanedSec++;
50+
if (spanedSec >= waitSec) {
51+
clearInterval(id);
52+
if (callbackFunc) callbackFunc();
53+
}
54+
}, 1000);
55+
56+
}
57+
3658
export default router;

examples/run-transaction/supply-chain-app-stub/package.json renamed to examples/test-run-transaction/supply-chain-app-stub/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"@types/express": "^4.17.11"
2020
},
2121
"scripts": {
22+
"start": "node app/app.js",
23+
"build": "npx tsc",
2224
"test": "echo \"Error: no test specified\" && exit 1"
2325
},
2426
"author": "",

examples/run-transaction/run-transaction.ts renamed to examples/test-run-transaction/test-run-transaction.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright 2021 Hyperledger Cactus Contributors
33
* SPDX-License-Identifier: Apache-2.0
44
*
5-
* run-transaction.ts
5+
* test-run-transaction.ts
66
*/
77

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

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

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

3030
const result = {tradeID: tradeID};

packages/config/default.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
{
1212
"businessLogicID": "j71S9gLN",
13-
"validatorID": ["vIdAcnCF"]
13+
"validatorID": ["vIdO32CF"]
1414
}
1515
],
1616
"logLevel": "debug",

packages/config/verifier-config.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"apiInfo": []
9292
},
9393
{
94-
"validatorID": "vIdAcnCB",
94+
"validatorID": "vIdO32CB",
9595
"validatorURL": "http://localhost:5053/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/",
9696
"validatorKeyPath": "",
9797
"ledgerInfo": {
@@ -100,7 +100,7 @@
100100
"apiInfo": []
101101
},
102102
{
103-
"validatorID": "vIdAcnCF",
103+
"validatorID": "vIdO32CF",
104104
"validatorURL": "http://localhost:5053/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-fabric/",
105105
"validatorKeyPath": "",
106106
"ledgerInfo": {
@@ -109,7 +109,7 @@
109109
"apiInfo": []
110110
},
111111
{
112-
"validatorID": "vIdAcnCQ",
112+
"validatorID": "vIdO32CQ",
113113
"host": "http://localhost:5053/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-quorum/",
114114
"validatorKeyPath": "",
115115
"ledgerInfo": {

0 commit comments

Comments
 (0)