diff --git a/examples/cartrade/AssetManagement.ts b/examples/cartrade/AssetManagement.ts new file mode 100644 index 0000000000..00ad0bbad9 --- /dev/null +++ b/examples/cartrade/AssetManagement.ts @@ -0,0 +1,100 @@ +/* + * Copyright 2020-2021 Hyperledger Cactus Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * AssetManagement.ts + */ + +import { LPInfoHolder } from '../../packages/routing-interface/util/LPInfoHolder'; +import { VerifierBase } from '../../packages/ledger-plugin/VerifierBase'; +import { ContractInfoHolder } from '../../packages/routing-interface/util/ContractInfoHolder'; +import { ConfigUtil } from '../../packages/routing-interface/util/ConfigUtil'; + +const fs = require('fs'); +const path = require('path'); +const config: any = ConfigUtil.getConfig(); +import { getLogger } from "log4js"; +const moduleName = 'AssetManagement'; +const logger = getLogger(`${moduleName}`); +logger.level = config.logLevel; + +export class AssetManagement { + private connectInfo: LPInfoHolder = null; // connection information + private contractInfoholder: ContractInfoHolder = null; // contract information + private verifierEthereum: VerifierBase = null; + + constructor() { + this.connectInfo = new LPInfoHolder(); + this.contractInfoholder = new ContractInfoHolder(); + } + + addAsset(amount: string): Promise { + return new Promise((resolve, reject) => { + if (this.verifierEthereum === null) { + logger.debug("create verifierEthereum"); + const ledgerPluginInfo: string = this.connectInfo.getLegerPluginInfo("84jUisrs"); + this.verifierEthereum = new VerifierBase(ledgerPluginInfo); + } + + // for Neo + const contractInfo: string = this.contractInfoholder.getContractInfo("AssetContract"); + const contractInfoObj: {} = JSON.parse(contractInfo); + const coinbase = contractInfoObj['_eth']['coinbase']; + const address = contractInfoObj['address']; + const abi = contractInfoObj['abi']; + const contract = { + "address": address, + "abi": abi + }; + const method = {type: "contract", command: "addAsset", function: "sendTransaction"}; + const args = {"args": [amount, {from: coinbase}]}; + + this.verifierEthereum.execSyncFunctionNeo(contract, method, args).then(result => { + const response = { + "status": result.status, + "Transaction hash": result.data + } + resolve(response); + }).catch((err) => { + logger.error(err); + reject(err); + }); + + }); + } + + getAsset(): Promise { + return new Promise((resolve, reject) => { + if (this.verifierEthereum === null) { + logger.debug("create verifierEthereum"); + const ledgerPluginInfo: string = this.connectInfo.getLegerPluginInfo("84jUisrs"); + this.verifierEthereum = new VerifierBase(ledgerPluginInfo); + } + + // for Neo + const contractInfo: string = this.contractInfoholder.getContractInfo("AssetContract"); + const contractInfoObj: {} = JSON.parse(contractInfo); + const address = contractInfoObj['address']; + const abi = contractInfoObj['abi']; + const contract = { + "address": address, + "abi": abi + }; + const method = {type: "contract", command: "getAsset", function: "call"}; + const args = {"args": []}; + + this.verifierEthereum.execSyncFunctionNeo(contract, method, args).then(result => { + const response = { + "status": result.status, + "asset": parseFloat(result.data) + } + resolve(response); + }).catch((err) => { + logger.error(err); + reject(err); + }); + + }); + } + +} diff --git a/examples/cartrade/BalanceManagement.ts b/examples/cartrade/BalanceManagement.ts new file mode 100644 index 0000000000..4c4def3205 --- /dev/null +++ b/examples/cartrade/BalanceManagement.ts @@ -0,0 +1,59 @@ +/* + * Copyright 2020-2021 Hyperledger Cactus Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * BalanceManagement.ts + */ + +import { LPInfoHolder } from '../../packages/routing-interface/util/LPInfoHolder'; +import { VerifierBase } from '../../packages/ledger-plugin/VerifierBase'; +import { ConfigUtil } from '../../packages/routing-interface/util/ConfigUtil'; + +const fs = require('fs'); +const path = require('path'); +const config: any = ConfigUtil.getConfig(); +import { getLogger } from "log4js"; +const moduleName = 'BalanceManagement'; +const logger = getLogger(`${moduleName}`); +logger.level = config.logLevel; + +export class BalanceManagement { + private connectInfo: LPInfoHolder = null; // connection information + private verifierEthereum: VerifierBase = null; + + constructor() { + this.connectInfo = new LPInfoHolder(); + } + + getBalance(account: string): Promise { + return new Promise((resolve, reject) => { + if (this.verifierEthereum === null) { + logger.debug("create verifierEthereum"); + const ledgerPluginInfo: string = this.connectInfo.getLegerPluginInfo("84jUisrs"); + this.verifierEthereum = new VerifierBase(ledgerPluginInfo); + } + + // for LedgerOperation + // const execData = {"referedAddress": account}; + // const ledgerOperation: LedgerOperation = new LedgerOperation("getNumericBalance", "", execData); + + // for Neo + const contract = {}; // NOTE: Since contract does not need to be specified, specify an empty object. + const method = {type: "web3Eth", command: "getBalance"}; + const args = {"args": [account]}; + + this.verifierEthereum.execSyncFunctionNeo(contract, method, args).then(result => { + const response = { + "status": result.status, + "amount": parseFloat(result.data) + } + resolve(response); + }).catch((err) => { + logger.error(err); + reject(err); + }); + + }); + } + +} diff --git a/examples/cartrade/BusinessLogicCartrade.ts b/examples/cartrade/BusinessLogicCartrade.ts index c7ba47dabb..c30ad2f9ff 100644 --- a/examples/cartrade/BusinessLogicCartrade.ts +++ b/examples/cartrade/BusinessLogicCartrade.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020 Hyperledger Cactus Contributors + * Copyright 2020-2021 Hyperledger Cactus Contributors * SPDX-License-Identifier: Apache-2.0 * * BusinessLogicCartrade.ts @@ -14,6 +14,7 @@ import { TransactionData } from './TransactionData'; import { BusinessLogicInquireCartradeStatus } from './BusinessLogicInquireCartradeStatus'; import { TxInfoData } from './TxInfoData'; import { transactionManagement } from '../../packages/routing-interface/routes/index'; +import { verifierFactory } from '../../packages/routing-interface/routes/index'; import { LedgerOperation } from '../../packages/business-logic-plugin/LedgerOperation'; import { BusinessLogicBase } from '../../packages/business-logic-plugin/BusinessLogicBase'; import { makeRawTransaction } from './TransactionEthereum' @@ -106,7 +107,8 @@ export class BusinessLogicCartrade extends BusinessLogicBase { // Get Verifier Instance logger.debug(`##firstTransaction(): businessLogicID: ${tradeInfo.businessLogicID}`); const useValidator = JSON.parse(transactionManagement.getValidatorToUse(tradeInfo.businessLogicID)); - const verifierEthereum = transactionManagement.getVerifier(useValidator['validatorID'][0]); +// const verifierEthereum = transactionManagement.getVerifier(useValidator['validatorID'][0]); + const verifierEthereum = verifierFactory.getVerifier(useValidator['validatorID'][0]); logger.debug("getVerifierEthereum"); // TODO: get private key from @@ -156,7 +158,8 @@ export class BusinessLogicCartrade extends BusinessLogicBase { // Get Verifier Instance logger.debug(`##secondTransaction(): businessLogicID: ${tradeInfo.businessLogicID}`); const useValidator = JSON.parse(transactionManagement.getValidatorToUse(tradeInfo.businessLogicID)); - const verifierFabric = transactionManagement.getVerifier(useValidator['validatorID'][1]); +// const verifierFabric = transactionManagement.getVerifier(useValidator['validatorID'][1]); + const verifierFabric = verifierFactory.getVerifier(useValidator['validatorID'][1]); logger.debug("getVerifierFabric"); // Generate parameters for sendSignedProposal(changeCarOwner) @@ -195,7 +198,8 @@ export class BusinessLogicCartrade extends BusinessLogicBase { // Get Verifier Instance logger.debug(`##thirdTransaction(): businessLogicID: ${tradeInfo.businessLogicID}`); const useValidator = JSON.parse(transactionManagement.getValidatorToUse(tradeInfo.businessLogicID)); - const verifierEthereum = transactionManagement.getVerifier(useValidator['validatorID'][0]); +// const verifierEthereum = transactionManagement.getVerifier(useValidator['validatorID'][0]); + const verifierEthereum = verifierFactory.getVerifier(useValidator['validatorID'][0]); logger.debug("getVerifierEthereum"); // TODO: Get address of escrow and set parameter diff --git a/examples/cartrade/BusinessLogicInquireCartradeStatus.ts b/examples/cartrade/BusinessLogicInquireCartradeStatus.ts index 926162f706..dc6fdd051a 100644 --- a/examples/cartrade/BusinessLogicInquireCartradeStatus.ts +++ b/examples/cartrade/BusinessLogicInquireCartradeStatus.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020 Hyperledger Cactus Contributors + * Copyright 2020-2021 Hyperledger Cactus Contributors * SPDX-License-Identifier: Apache-2.0 * * BusinessLogicInquireCartradeStatus.ts diff --git a/examples/cartrade/CarsManagement.ts b/examples/cartrade/CarsManagement.ts new file mode 100644 index 0000000000..ef5aa2d236 --- /dev/null +++ b/examples/cartrade/CarsManagement.ts @@ -0,0 +1,72 @@ +/* + * Copyright 2020-2021 Hyperledger Cactus Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * CarsManagement.ts + */ + +import { LPInfoHolder } from '../../packages/routing-interface/util/LPInfoHolder'; +import { VerifierBase } from '../../packages/ledger-plugin/VerifierBase'; +import { ConfigUtil } from '../../packages/routing-interface/util/ConfigUtil'; + +const fs = require('fs'); +const path = require('path'); +const config: any = ConfigUtil.getConfig(); +import { getLogger } from "log4js"; +const moduleName = 'CarsManagement'; +const logger = getLogger(`${moduleName}`); +logger.level = config.logLevel; + +export class CarsManagement { + private connectInfo: LPInfoHolder = null; // connection information + private verifierFabric: VerifierBase = null; + + constructor() { + this.connectInfo = new LPInfoHolder(); + } + + queryCar(carID: string): Promise { + return new Promise((resolve, reject) => { + if (this.verifierFabric === null) { + logger.debug("create verifierFabric"); + const ledgerPluginInfo: string = this.connectInfo.getLegerPluginInfo("r9IS4dDf"); + this.verifierFabric = new VerifierBase(ledgerPluginInfo); + } + + const contract = {"channelName": "mychannel", "contractName": "fabcar"}; + const method = {type: "evaluateTransaction", command: "queryCar"}; + const args = {"args": [carID]}; + + this.verifierFabric.execSyncFunctionNeo(contract, method, args).then(result => { + resolve(result); + }).catch((err) => { + logger.error(err); + reject(err); + }); + + }); + } + + queryAllCars(): Promise { + return new Promise((resolve, reject) => { + if (this.verifierFabric === null) { + logger.debug("create verifierFabric"); + const ledgerPluginInfo: string = this.connectInfo.getLegerPluginInfo("r9IS4dDf"); + this.verifierFabric = new VerifierBase(ledgerPluginInfo); + } + + const contract = {"channelName": "mychannel", "contractName": "fabcar"}; + const method = {type: "evaluateTransaction", command: "queryAllCars"}; + const args = {"args": []}; + + this.verifierFabric.execSyncFunctionNeo(contract, method, args).then(result => { + resolve(result); + }).catch((err) => { + logger.error(err); + reject(err); + }); + + }); + } + +} diff --git a/examples/cartrade/ResultTransactionStatusData.ts b/examples/cartrade/ResultTransactionStatusData.ts index 8aebbc4bf2..be339db5e7 100644 --- a/examples/cartrade/ResultTransactionStatusData.ts +++ b/examples/cartrade/ResultTransactionStatusData.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020 Hyperledger Cactus Contributors + * Copyright 2020-2021 Hyperledger Cactus Contributors * SPDX-License-Identifier: Apache-2.0 * * ResultTransactionStatusData.ts diff --git a/examples/cartrade/TransactionData.ts b/examples/cartrade/TransactionData.ts index 441e871e9e..9b9eb19fcd 100644 --- a/examples/cartrade/TransactionData.ts +++ b/examples/cartrade/TransactionData.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020 Hyperledger Cactus Contributors + * Copyright 2020-2021 Hyperledger Cactus Contributors * SPDX-License-Identifier: Apache-2.0 * * TransactionData.ts diff --git a/examples/cartrade/TransactionEthereum.ts b/examples/cartrade/TransactionEthereum.ts index f538fcf880..9f2cf49051 100644 --- a/examples/cartrade/TransactionEthereum.ts +++ b/examples/cartrade/TransactionEthereum.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020 Hyperledger Cactus Contributors + * Copyright 2020-2021 Hyperledger Cactus Contributors * SPDX-License-Identifier: Apache-2.0 * * TransactionEthereum.ts diff --git a/examples/cartrade/TransactionFabric.ts b/examples/cartrade/TransactionFabric.ts index b2847bb798..43b22d4fce 100644 --- a/examples/cartrade/TransactionFabric.ts +++ b/examples/cartrade/TransactionFabric.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020 Hyperledger Cactus Contributors + * Copyright 2020-2021 Hyperledger Cactus Contributors * SPDX-License-Identifier: Apache-2.0 * * TransactionFabric.ts diff --git a/examples/cartrade/TransactionInfo.ts b/examples/cartrade/TransactionInfo.ts index 247618a317..2b9091b5a5 100644 --- a/examples/cartrade/TransactionInfo.ts +++ b/examples/cartrade/TransactionInfo.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020 Hyperledger Cactus Contributors + * Copyright 2020-2021 Hyperledger Cactus Contributors * SPDX-License-Identifier: Apache-2.0 * * TransactionInfo.ts diff --git a/examples/cartrade/TransactionInfoManagement.ts b/examples/cartrade/TransactionInfoManagement.ts index 2cc4b43410..10a0333e9e 100644 --- a/examples/cartrade/TransactionInfoManagement.ts +++ b/examples/cartrade/TransactionInfoManagement.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020 Hyperledger Cactus Contributors + * Copyright 2020-2021 Hyperledger Cactus Contributors * SPDX-License-Identifier: Apache-2.0 * * TransactionInfoManagement.ts diff --git a/examples/cartrade/TransactionStatus.ts b/examples/cartrade/TransactionStatus.ts index 55008c8ebe..b37b85c0d8 100644 --- a/examples/cartrade/TransactionStatus.ts +++ b/examples/cartrade/TransactionStatus.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020 Hyperledger Cactus Contributors + * Copyright 2020-2021 Hyperledger Cactus Contributors * SPDX-License-Identifier: Apache-2.0 * * TransactionStatus.ts diff --git a/examples/cartrade/TxInfoData.ts b/examples/cartrade/TxInfoData.ts index 532826235a..51a59c1043 100644 --- a/examples/cartrade/TxInfoData.ts +++ b/examples/cartrade/TxInfoData.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020 Hyperledger Cactus Contributors + * Copyright 2020-2021 Hyperledger Cactus Contributors * SPDX-License-Identifier: Apache-2.0 * * TxInfoData.ts diff --git a/examples/cartrade/asset.ts b/examples/cartrade/asset.ts new file mode 100644 index 0000000000..9a42d3047c --- /dev/null +++ b/examples/cartrade/asset.ts @@ -0,0 +1,76 @@ +/* + * Copyright 2020-2021 Hyperledger Cactus Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * asset.ts + */ + +import { Router, NextFunction, Request, Response } from 'express'; +import { RIFUtil } from '../../packages/routing-interface/util/RIFUtil'; +import { ConfigUtil } from '../../packages/routing-interface/util/ConfigUtil'; +import { RIFError, BadRequestError, InternalServerError } from '../../packages/routing-interface/RIFError'; +import { AssetManagement } from './AssetManagement'; + +const fs = require('fs'); +const path = require('path'); +const config: any = ConfigUtil.getConfig(); +import { getLogger } from "log4js"; +const moduleName = 'asset'; +const logger = getLogger(`${moduleName}`); +logger.level = config.logLevel; + +const router: Router = Router(); +const assetManagement: AssetManagement = new AssetManagement(); + +// POST : add asset. +router.post('/', (req: Request, res: Response, next: NextFunction) => { + try { + assetManagement.addAsset(req.body.amount).then(result => { + logger.debug("result(addAsset) = " + JSON.stringify(result)); + res.status(200).json(result); + }).catch((err) => { + logger.error(err); + }); + + } catch (err) { + logger.error(`##err name: ${err.constructor.name}`); + + if (err instanceof RIFError) { + logger.debug(`##catch RIFError, ${err.statusCode}, ${err.message}`); + res.status(err.statusCode); + res.send(err.message); + return; + } + + logger.error(`##err in asset: ${err}`); + next(err); + } +}); + +// GET : get asset. +router.get('/', (req: Request, res: Response, next: NextFunction) => { + try { + + assetManagement.getAsset().then(result => { + logger.debug("result(getAsset) = " + JSON.stringify(result)); + res.status(200).json(result); + }).catch((err) => { + logger.error(err); + }); + + } catch (err) { + logger.error(`##err name: ${err.constructor.name}`); + + if (err instanceof RIFError) { + logger.debug(`##catch RIFError, ${err.statusCode}, ${err.message}`); + res.status(err.statusCode); + res.send(err.message); + return; + } + + logger.error(`##err in asset: ${err}`); + next(err); + } +}); + +export default router; diff --git a/examples/cartrade/balance.ts b/examples/cartrade/balance.ts new file mode 100644 index 0000000000..6918ba3c5c --- /dev/null +++ b/examples/cartrade/balance.ts @@ -0,0 +1,52 @@ +/* + * Copyright 2020-2021 Hyperledger Cactus Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * balance.ts + */ + +import { Router, NextFunction, Request, Response } from 'express'; +import { RIFUtil } from '../../packages/routing-interface/util/RIFUtil'; +import { ConfigUtil } from '../../packages/routing-interface/util/ConfigUtil'; +import { RIFError, BadRequestError, InternalServerError } from '../../packages/routing-interface/RIFError'; +import { BalanceManagement } from './BalanceManagement'; + +const fs = require('fs'); +const path = require('path'); +const config: any = ConfigUtil.getConfig(); +import { getLogger } from "log4js"; +const moduleName = 'balance'; +const logger = getLogger(`${moduleName}`); +logger.level = config.logLevel; + +const router: Router = Router(); +const balanceManagement: BalanceManagement = new BalanceManagement(); + +/* GET balance. */ +router.get('/:account', (req: Request, res: Response, next: NextFunction) => { + try { + + balanceManagement.getBalance(req.params.account).then(result => { + logger.debug(`#####[sample/balance.ts]`); + logger.debug("result(getBalance) = " + JSON.stringify(result)); + res.status(200).json(result); + }).catch((err) => { + logger.error(err); + }); + + } catch (err) { + logger.error(`##err name: ${err.constructor.name}`); + + if (err instanceof RIFError) { + logger.debug(`##catch RIFError, ${err.statusCode}, ${err.message}`); + res.status(err.statusCode); + res.send(err.message); + return; + } + + logger.error(`##err in balance: ${err}`); + next(err); + } +}); + +export default router; diff --git a/examples/cartrade/cars.ts b/examples/cartrade/cars.ts new file mode 100644 index 0000000000..e346b64fc1 --- /dev/null +++ b/examples/cartrade/cars.ts @@ -0,0 +1,79 @@ +/* + * Copyright 2020-2021 Hyperledger Cactus Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * cars.ts + */ + +import { Router, NextFunction, Request, Response } from 'express'; +import { RIFUtil } from '../../packages/routing-interface/util/RIFUtil'; +import { ConfigUtil } from '../../packages/routing-interface/util/ConfigUtil'; +import { RIFError, BadRequestError, InternalServerError } from '../../packages/routing-interface/RIFError'; +import { CarsManagement } from './CarsManagement'; + +const fs = require('fs'); +const path = require('path'); +const config: any = ConfigUtil.getConfig(); +import { getLogger } from "log4js"; +const moduleName = 'cars'; +const logger = getLogger(`${moduleName}`); +logger.level = config.logLevel; + +const router: Router = Router(); +const carsManagement: CarsManagement = new CarsManagement(); + +/* GET query car. */ +router.get('/:carID', (req: Request, res: Response, next: NextFunction) => { + try { + logger.debug(`start queryCar`); + + carsManagement.queryCar(req.params.carID).then(result => { + logger.debug("result(queryCar) = " + JSON.stringify(result)); + res.status(200).json(result); + }).catch((err) => { + logger.error(err); + }); + + } catch (err) { + logger.error(`##(queryCar)err name: ${err.constructor.name}`); + + if (err instanceof RIFError) { + logger.debug(`##catch RIFError, ${err.statusCode}, ${err.message}`); + res.status(err.statusCode); + res.send(err.message); + return; + } + + logger.error(`##err in queryCar: ${err}`); + next(err); + } +}); + +/* GET query all cars. */ +router.get('/', (req: Request, res: Response, next: NextFunction) => { + try { + logger.debug(`start queryAllCars`); + + carsManagement.queryAllCars().then(result => { + logger.debug("result(queryAllCars) = " + JSON.stringify(result)); + res.status(200).json(result); + }).catch((err) => { + logger.error(err); + }); + + } catch (err) { + logger.error(`##(queryAllCars)err name: ${err.constructor.name}`); + + if (err instanceof RIFError) { + logger.debug(`##catch RIFError, ${err.statusCode}, ${err.message}`); + res.status(err.statusCode); + res.send(err.message); + return; + } + + logger.error(`##err in queryAllCars: ${err}`); + next(err); + } +}); + +export default router; diff --git a/examples/cartrade/config/BLP_config.ts b/examples/cartrade/config/BLP_config.ts index 8db0450ebb..f7f3cbd926 100644 --- a/examples/cartrade/config/BLP_config.ts +++ b/examples/cartrade/config/BLP_config.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020 Hyperledger Cactus Contributors + * Copyright 2020-2021 Hyperledger Cactus Contributors * SPDX-License-Identifier: Apache-2.0 * * BLP_config.ts diff --git a/examples/cartrade/config/usersetting.json b/examples/cartrade/config/usersetting.json index 2d467ffd15..d8cefd3ef4 100644 --- a/examples/cartrade/config/usersetting.json +++ b/examples/cartrade/config/usersetting.json @@ -18,5 +18,23 @@ "verifier": { "maxCounterRequestID":100, "syncFunctionTimeoutMillisecond":5000 - } + }, + "appRouters": [ + { + "path": "/api/v1/bl/trades/", + "routerJs": "../../examples/cartrade/trades.js" + }, + { + "path": "/api/v1/bl/asset/", + "routerJs": "../../examples/cartrade/asset.js" + }, + { + "path": "/api/v1/bl/balance/", + "routerJs": "../../examples/cartrade/balance.js" + }, + { + "path": "/api/v1/bl/cars/", + "routerJs": "../../examples/cartrade/cars.js" + } + ] } diff --git a/examples/cartrade/copyBLPConfig.ts b/examples/cartrade/copyBLPConfig.ts index 04cb725627..449b09bd65 100644 --- a/examples/cartrade/copyBLPConfig.ts +++ b/examples/cartrade/copyBLPConfig.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020 Hyperledger Cactus Contributors + * Copyright 2020-2021 Hyperledger Cactus Contributors * SPDX-License-Identifier: Apache-2.0 * * copyBLPConfig.ts diff --git a/examples/cartrade/copyStaticAssets.ts b/examples/cartrade/copyStaticAssets.ts index 29b418722e..8b5f4e0427 100644 --- a/examples/cartrade/copyStaticAssets.ts +++ b/examples/cartrade/copyStaticAssets.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020 Hyperledger Cactus Contributors + * Copyright 2020-2021 Hyperledger Cactus Contributors * SPDX-License-Identifier: Apache-2.0 * * copyStaticAssets.ts diff --git a/examples/cartrade/define.ts b/examples/cartrade/define.ts index ce6a772920..037a28d929 100644 --- a/examples/cartrade/define.ts +++ b/examples/cartrade/define.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020 Hyperledger Cactus Contributors + * Copyright 2020-2021 Hyperledger Cactus Contributors * SPDX-License-Identifier: Apache-2.0 * * define.ts diff --git a/examples/cartrade/package.json b/examples/cartrade/package.json index c179092417..b2e68bc24e 100644 --- a/examples/cartrade/package.json +++ b/examples/cartrade/package.json @@ -30,7 +30,8 @@ "shelljs": "^0.8.4", "socket.io": "^2.0.4", "ts-node": "8.9.1", - "web3": "^1.2.9" + "web3": "^1.2.9", + "xmlhttprequest": "^1.8.0" }, "devDependencies": { "tslint": "6.0.0", diff --git a/examples/cartrade/replaceBLPConfigPath.ts b/examples/cartrade/replaceBLPConfigPath.ts index b33b92aea2..f3c59b358a 100644 --- a/examples/cartrade/replaceBLPConfigPath.ts +++ b/examples/cartrade/replaceBLPConfigPath.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020 Hyperledger Cactus Contributors + * Copyright 2020-2021 Hyperledger Cactus Contributors * SPDX-License-Identifier: Apache-2.0 * * ReplacePath.js diff --git a/examples/cartrade/script-build-all.sh b/examples/cartrade/script-build-all.sh index 34b2cc5bea..ade44f36d6 100755 --- a/examples/cartrade/script-build-all.sh +++ b/examples/cartrade/script-build-all.sh @@ -1,3 +1,5 @@ +# Copyright 2020-2021 Hyperledger Cactus Contributors +# SPDX-License-Identifier: Apache-2.0 cd ../.. ## Build validator for Fabric diff --git a/examples/cartrade/script-build-cartrade.sh b/examples/cartrade/script-build-cartrade.sh index 5f85d05487..7b4ed67527 100755 --- a/examples/cartrade/script-build-cartrade.sh +++ b/examples/cartrade/script-build-cartrade.sh @@ -1,3 +1,5 @@ +# Copyright 2020-2021 Hyperledger Cactus Contributors +# SPDX-License-Identifier: Apache-2.0 ## Build a cartrade app echo "[process] Build a cartrade app" npm install diff --git a/examples/cartrade/script-build-get-app.sh b/examples/cartrade/script-build-get-app.sh index c7cc039359..d7b259d096 100755 --- a/examples/cartrade/script-build-get-app.sh +++ b/examples/cartrade/script-build-get-app.sh @@ -1,3 +1,5 @@ +# Copyright 2020-2021 Hyperledger Cactus Contributors +# SPDX-License-Identifier: Apache-2.0 ## Build a getting app echo "[process] Build an app for getting Balance on Ethereum" cd script-test-getFunctions/go-ethereum diff --git a/examples/cartrade/script-get-app.sh b/examples/cartrade/script-get-app.sh index 6642f437f9..6a08c81382 100755 --- a/examples/cartrade/script-get-app.sh +++ b/examples/cartrade/script-get-app.sh @@ -1,3 +1,5 @@ +# Copyright 2020-2021 Hyperledger Cactus Contributors +# SPDX-License-Identifier: Apache-2.0 ## Execute a getting app echo "[process] Execute an app for getting Balance on Ethereum" cd script-test-getFunctions/go-ethereum diff --git a/examples/cartrade/script-post-cartrade-sample.sh b/examples/cartrade/script-post-cartrade-sample.sh index f1513538db..cd1021b9cd 100755 --- a/examples/cartrade/script-post-cartrade-sample.sh +++ b/examples/cartrade/script-post-cartrade-sample.sh @@ -1 +1,3 @@ +# Copyright 2020-2021 Hyperledger Cactus Contributors +# SPDX-License-Identifier: Apache-2.0 curl localhost:5034/api/v1/bl/trades/ -XPOST -H "Content-Type: application/json" -d '{"businessLogicID":"guks32pf","tradeParams":["0x06fc56347d91c6ad2dae0c3ba38eb12ab0d72e97", "0x9d624f7995e8bd70251f8265f2f9f2b49f169c55", "Brad", "Cathy", 50, "CAR1"],"authParams":["none"]}' \ No newline at end of file diff --git a/examples/cartrade/script-start-cartrade.sh b/examples/cartrade/script-start-cartrade.sh index b955686730..4d10f5fac8 100755 --- a/examples/cartrade/script-start-cartrade.sh +++ b/examples/cartrade/script-start-cartrade.sh @@ -1,3 +1,5 @@ +# Copyright 2020-2021 Hyperledger Cactus Contributors +# SPDX-License-Identifier: Apache-2.0 cd ../.. ## Start cartrade app diff --git a/examples/cartrade/script-start-ledgers.sh b/examples/cartrade/script-start-ledgers.sh index 93c7196d45..77110631dc 100755 --- a/examples/cartrade/script-start-ledgers.sh +++ b/examples/cartrade/script-start-ledgers.sh @@ -1,3 +1,5 @@ +# Copyright 2020-2021 Hyperledger Cactus Contributors +# SPDX-License-Identifier: Apache-2.0 cd ../.. ## Start docker environment for Go-Ethereum testnet diff --git a/examples/cartrade/script-start-validator-ethereum.sh b/examples/cartrade/script-start-validator-ethereum.sh index 70df1f048e..0d7fefdfb2 100755 --- a/examples/cartrade/script-start-validator-ethereum.sh +++ b/examples/cartrade/script-start-validator-ethereum.sh @@ -1,3 +1,5 @@ +# Copyright 2020-2021 Hyperledger Cactus Contributors +# SPDX-License-Identifier: Apache-2.0 cd ../.. echo "[process] Start the validator for Go-Ethereum" diff --git a/examples/cartrade/script-start-validator-fabric.sh b/examples/cartrade/script-start-validator-fabric.sh index 575cd167e1..4923a71337 100755 --- a/examples/cartrade/script-start-validator-fabric.sh +++ b/examples/cartrade/script-start-validator-fabric.sh @@ -1,3 +1,5 @@ +# Copyright 2020-2021 Hyperledger Cactus Contributors +# SPDX-License-Identifier: Apache-2.0 cd ../.. echo "[process] Start the validator for Fabric" diff --git a/examples/cartrade/script-stop-cartrade.sh b/examples/cartrade/script-stop-cartrade.sh index 0849294110..785e2074aa 100755 --- a/examples/cartrade/script-stop-cartrade.sh +++ b/examples/cartrade/script-stop-cartrade.sh @@ -1,3 +1,5 @@ +# Copyright 2020-2021 Hyperledger Cactus Contributors +# SPDX-License-Identifier: Apache-2.0 echo "[process] Stop the validators and the cartrade app" # stop the validator for Ethereum kill -9 $(lsof -t -i:5050) diff --git a/examples/cartrade/script-test-getFunctions/fabric/queryCar.js b/examples/cartrade/script-test-getFunctions/fabric/queryCar.js index 7418edfa00..2e292531fd 100644 --- a/examples/cartrade/script-test-getFunctions/fabric/queryCar.js +++ b/examples/cartrade/script-test-getFunctions/fabric/queryCar.js @@ -1,5 +1,5 @@ /* - * Copyright 2019-2020 Fujitsu Laboratories Ltd. + * Copyright 2021 Hyperledger Cactus Contributors * SPDX-License-Identifier: Apache-2.0 * * queryCar.js @@ -49,17 +49,17 @@ async function main() { // Evaluate the specified transaction. if (process.argv.length > 2) { - const key = process.argv[2]; - //console.log('##queryCar Params: ' + key); - console.log(`##queryCar Params: ${key}`); - const result = await contract.evaluateTransaction('queryCar', key); - console.log(`Transaction has been evaluated, result is: ${result.toString()}`); - } - else { - console.log('##queryAllCars: '); - const result = await contract.evaluateTransaction('queryAllCars'); - console.log(`Transaction has been evaluated, result is: ${result.toString()}`); - } + const key = process.argv[2]; + //console.log('##queryCar Params: ' + key); + console.log(`##queryCar Params: ${key}`); + const result = await contract.evaluateTransaction('queryCar', key); + console.log(`Transaction has been evaluated, result is: ${result.toString()}`); + } + else { + console.log('##queryAllCars: '); + const result = await contract.evaluateTransaction('queryAllCars'); + console.log(`Transaction has been evaluated, result is: ${result.toString()}`); + } } catch (error) { console.error(`Failed to evaluate transaction: ${error}`); diff --git a/examples/cartrade/script-test-getFunctions/go-ethereum/getBalance.js b/examples/cartrade/script-test-getFunctions/go-ethereum/getBalance.js index 65a591190a..23baf07478 100644 --- a/examples/cartrade/script-test-getFunctions/go-ethereum/getBalance.js +++ b/examples/cartrade/script-test-getFunctions/go-ethereum/getBalance.js @@ -1,3 +1,9 @@ +/* + * Copyright 2020-2021 Hyperledger Cactus Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * getBalance.js + */ const Web3 = require('web3'); const web3 = new Web3(); web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545")); diff --git a/examples/cartrade/trades.ts b/examples/cartrade/trades.ts new file mode 100644 index 0000000000..70e000d3ae --- /dev/null +++ b/examples/cartrade/trades.ts @@ -0,0 +1,62 @@ +/* + * Copyright 2020-2021 Hyperledger Cactus Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * trades.ts + */ + +import { Router, NextFunction, Request, Response } from 'express'; +import { TransactionManagement } from '../../packages/routing-interface/TransactionManagement'; +import { RIFError } from '../../packages/routing-interface/RIFError'; +import { ConfigUtil } from '../../packages/routing-interface/util/ConfigUtil'; + +const fs = require('fs'); +const path = require('path'); +const config: any = ConfigUtil.getConfig(); +import { getLogger } from "log4js"; +const moduleName = 'trades'; +const logger = getLogger(`${moduleName}`); +logger.level = config.logLevel; + +const router: Router = Router(); +export const transactionManagement: TransactionManagement = new TransactionManagement(); + +// Request Execution of Trade +router.post('/', (req: Request, res: Response, next: NextFunction) => { + try { + const tradeID: string = transactionManagement.startBusinessLogic(req); + + const result = {tradeID: tradeID}; + res.status(201).location(config.applicationHostInfo.hostName + "/api/v1/trades/" + tradeID).json(result); + + } catch (err) { + if (err instanceof RIFError) { + res.status(err.statusCode); + res.send(err.message); + return; + } + + next(err); + } +}); + +// Show Current Status of Trade +router.get('/:id', (req: Request, res: Response, next: NextFunction) => { + try { + + + const result = transactionManagement.getOperationStatus(req.params.id); + res.status(200).json(result); + + } catch (err) { + if (err instanceof RIFError) { + res.status(err.statusCode); + res.send(err.message); + return; + } + + next(err); + } +}); + +export default router; diff --git a/examples/electricity-trade/.gitignore b/examples/electricity-trade/.gitignore new file mode 100644 index 0000000000..ce2a32fbf1 --- /dev/null +++ b/examples/electricity-trade/.gitignore @@ -0,0 +1,2 @@ +MeterInfo.json + diff --git a/examples/electricity-trade/BalanceManagement.ts b/examples/electricity-trade/BalanceManagement.ts new file mode 100644 index 0000000000..4c4def3205 --- /dev/null +++ b/examples/electricity-trade/BalanceManagement.ts @@ -0,0 +1,59 @@ +/* + * Copyright 2020-2021 Hyperledger Cactus Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * BalanceManagement.ts + */ + +import { LPInfoHolder } from '../../packages/routing-interface/util/LPInfoHolder'; +import { VerifierBase } from '../../packages/ledger-plugin/VerifierBase'; +import { ConfigUtil } from '../../packages/routing-interface/util/ConfigUtil'; + +const fs = require('fs'); +const path = require('path'); +const config: any = ConfigUtil.getConfig(); +import { getLogger } from "log4js"; +const moduleName = 'BalanceManagement'; +const logger = getLogger(`${moduleName}`); +logger.level = config.logLevel; + +export class BalanceManagement { + private connectInfo: LPInfoHolder = null; // connection information + private verifierEthereum: VerifierBase = null; + + constructor() { + this.connectInfo = new LPInfoHolder(); + } + + getBalance(account: string): Promise { + return new Promise((resolve, reject) => { + if (this.verifierEthereum === null) { + logger.debug("create verifierEthereum"); + const ledgerPluginInfo: string = this.connectInfo.getLegerPluginInfo("84jUisrs"); + this.verifierEthereum = new VerifierBase(ledgerPluginInfo); + } + + // for LedgerOperation + // const execData = {"referedAddress": account}; + // const ledgerOperation: LedgerOperation = new LedgerOperation("getNumericBalance", "", execData); + + // for Neo + const contract = {}; // NOTE: Since contract does not need to be specified, specify an empty object. + const method = {type: "web3Eth", command: "getBalance"}; + const args = {"args": [account]}; + + this.verifierEthereum.execSyncFunctionNeo(contract, method, args).then(result => { + const response = { + "status": result.status, + "amount": parseFloat(result.data) + } + resolve(response); + }).catch((err) => { + logger.error(err); + reject(err); + }); + + }); + } + +} diff --git a/examples/electricity-trade/BusinessLogicElectricityTrade.ts b/examples/electricity-trade/BusinessLogicElectricityTrade.ts index 313bb90ebc..cb99c2d043 100644 --- a/examples/electricity-trade/BusinessLogicElectricityTrade.ts +++ b/examples/electricity-trade/BusinessLogicElectricityTrade.ts @@ -11,6 +11,7 @@ import { MeterManagement } from './MeterManagement'; import { MeterInfo } from './MeterInfo'; import { TradeInfo } from '../../packages/routing-interface/TradeInfo'; import { transactionManagement } from '../../packages/routing-interface/routes/index'; +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'; @@ -59,7 +60,8 @@ export class BusinessLogicElectricityTrade extends BusinessLogicBase { const options = { "filterKey": config.electricityTradeInfo.sawtooth.filterKey } - const verifierSawtooth = transactionManagement.getVerifier(useValidator['validatorID'][0], options); +// const verifierSawtooth = transactionManagement.getVerifier(useValidator['validatorID'][0], options); + const verifierSawtooth = verifierFactory.getVerifier(useValidator['validatorID'][0], options); logger.debug("getVerifierSawtooth"); } @@ -86,7 +88,8 @@ export class BusinessLogicElectricityTrade extends BusinessLogicBase { // Get Verifier Instance logger.debug(`##remittanceTransaction(): businessLogicID: ${this.businessLogicID}`); const useValidator = JSON.parse(transactionManagement.getValidatorToUse(this.businessLogicID)); - const verifierEthereum = transactionManagement.getVerifier(useValidator['validatorID'][1]); +// const verifierEthereum = transactionManagement.getVerifier(useValidator['validatorID'][1]); + const verifierEthereum = verifierFactory.getVerifier(useValidator['validatorID'][1]); logger.debug("getVerifierEthereum"); // Generate parameters for// sendRawTransaction diff --git a/examples/electricity-trade/balance.ts b/examples/electricity-trade/balance.ts new file mode 100644 index 0000000000..6918ba3c5c --- /dev/null +++ b/examples/electricity-trade/balance.ts @@ -0,0 +1,52 @@ +/* + * Copyright 2020-2021 Hyperledger Cactus Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * balance.ts + */ + +import { Router, NextFunction, Request, Response } from 'express'; +import { RIFUtil } from '../../packages/routing-interface/util/RIFUtil'; +import { ConfigUtil } from '../../packages/routing-interface/util/ConfigUtil'; +import { RIFError, BadRequestError, InternalServerError } from '../../packages/routing-interface/RIFError'; +import { BalanceManagement } from './BalanceManagement'; + +const fs = require('fs'); +const path = require('path'); +const config: any = ConfigUtil.getConfig(); +import { getLogger } from "log4js"; +const moduleName = 'balance'; +const logger = getLogger(`${moduleName}`); +logger.level = config.logLevel; + +const router: Router = Router(); +const balanceManagement: BalanceManagement = new BalanceManagement(); + +/* GET balance. */ +router.get('/:account', (req: Request, res: Response, next: NextFunction) => { + try { + + balanceManagement.getBalance(req.params.account).then(result => { + logger.debug(`#####[sample/balance.ts]`); + logger.debug("result(getBalance) = " + JSON.stringify(result)); + res.status(200).json(result); + }).catch((err) => { + logger.error(err); + }); + + } catch (err) { + logger.error(`##err name: ${err.constructor.name}`); + + if (err instanceof RIFError) { + logger.debug(`##catch RIFError, ${err.statusCode}, ${err.message}`); + res.status(err.statusCode); + res.send(err.message); + return; + } + + logger.error(`##err in balance: ${err}`); + next(err); + } +}); + +export default router; diff --git a/examples/electricity-trade/config/usersetting.json b/examples/electricity-trade/config/usersetting.json index b794425970..b649afd621 100644 --- a/examples/electricity-trade/config/usersetting.json +++ b/examples/electricity-trade/config/usersetting.json @@ -22,5 +22,15 @@ "verifier": { "maxCounterRequestID":100, "syncFunctionTimeoutMillisecond":5000 - } + }, + "appRouters": [ + { + "path": "/api/v1/bl/electricity-trade/", + "routerJs": "../../examples/electricity-trade/electricity-trade.js" + }, + { + "path": "/api/v1/bl/balance/", + "routerJs": "../../examples/electricity-trade/balance.js" + } + ] } diff --git a/examples/electricity-trade/electricity-trade.ts b/examples/electricity-trade/electricity-trade.ts new file mode 100644 index 0000000000..97ddf52ba6 --- /dev/null +++ b/examples/electricity-trade/electricity-trade.ts @@ -0,0 +1,64 @@ +/* + * Copyright 2021 Hyperledger Cactus Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * electricity-trade.ts + */ + +import { Router, NextFunction, Request, Response } from 'express'; +import { TransactionManagement } from '../../packages/routing-interface/TransactionManagement'; +import { RIFError } from '../../packages/routing-interface/RIFError'; +import { ConfigUtil } from '../../packages/routing-interface/util/ConfigUtil'; + +const fs = require('fs'); +const path = require('path'); +const config: any = ConfigUtil.getConfig(); +import { getLogger } from "log4js"; +const moduleName = 'trades'; +const logger = getLogger(`${moduleName}`); +logger.level = config.logLevel; + +const router: Router = Router(); +export const transactionManagement: TransactionManagement = new TransactionManagement(); + +// Request Execution of Trade +router.post('/', (req: Request, res: Response, next: NextFunction) => { + try { + const tradeID: string = transactionManagement.startBusinessLogic(req); + + const result = {tradeID: tradeID}; + res.status(200).json(result); + + } catch (err) { + if (err instanceof RIFError) { + res.status(err.statusCode); + res.send(err.message); + return; + } + + next(err); + } +}); + +// Request Execution of Trade +router.post('/meter/register/', (req: Request, res: Response, next: NextFunction) => { + try { + const result: object = transactionManagement.setBusinessLogicConfig(req); + let status: number = 200; + if (result['action'] === "add") { + status = 201; + } + res.status(status).json(result); + + } catch (err) { + if (err instanceof RIFError) { + res.status(err.statusCode); + res.send(err.message); + return; + } + + next(err); + } +}); + +export default router; diff --git a/examples/electricity-trade/package.json b/examples/electricity-trade/package.json index 5a31bd239e..278720bea3 100644 --- a/examples/electricity-trade/package.json +++ b/examples/electricity-trade/package.json @@ -30,7 +30,8 @@ "shelljs": "^0.8.4", "socket.io": "^2.0.4", "ts-node": "8.9.1", - "web3": "^1.2.9" + "web3": "^1.2.9", + "xmlhttprequest": "^1.8.0" }, "devDependencies": { "tslint": "6.0.0", diff --git a/examples/run-transaction/BusinessLogicRunTransaction.ts b/examples/run-transaction/BusinessLogicRunTransaction.ts new file mode 100644 index 0000000000..36272363b9 --- /dev/null +++ b/examples/run-transaction/BusinessLogicRunTransaction.ts @@ -0,0 +1,88 @@ +/* + * Copyright 2021 Hyperledger Cactus Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * BusinessLogicRunTransaction.ts + */ + +import { Request } from 'express'; +import { RequestInfo } from './RequestInfo'; +//import { MeterManagement } from './MeterManagement'; +//import { MeterInfo } from './MeterInfo'; +import { TradeInfo } from '../../packages/routing-interface/TradeInfo'; +import { transactionManagement } from '../../packages/routing-interface/routes/index'; +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 { json2str } from '../../packages/ledger-plugin/DriverCommon' + +const fs = require('fs'); +const path = require('path'); +const config: any = JSON.parse(fs.readFileSync(path.resolve(__dirname, "./config/default.json"), 'utf8')); +import { getLogger } from "log4js"; +const moduleName = 'BusinessLogicRunTransaction'; +const logger = getLogger(`${moduleName}`); +logger.level = config.logLevel; + +export class BusinessLogicRunTransaction extends BusinessLogicBase { + businessLogicID: string; + + constructor(businessLogicID: string) { + super(); + this.businessLogicID = businessLogicID; + } + + startTransaction(req: Request, businessLogicID: string, tradeID: string) { + + logger.debug("called startTransaction()"); + + // set RequestInfo + const requestInfo: RequestInfo = new RequestInfo(); + requestInfo.setBusinessLogicID(businessLogicID); + requestInfo.keychainId = req.body.tradeParams[0]; + requestInfo.keychainRef = req.body.tradeParams[1]; + requestInfo.channelName = req.body.tradeParams[2]; + requestInfo.invocationType = req.body.tradeParams[3]; + requestInfo.functionName = req.body.tradeParams[4]; + requestInfo.functionArgs = req.body.tradeParams[5]; + logger.debug(`tradeParams: ${req.body.tradeParams}`); + + // set TradeID + requestInfo.setTradeID(tradeID); + + // Create trade information + const tradeInfo: TradeInfo = new TradeInfo(requestInfo.businessLogicID, requestInfo.tradeID); + + // TODO: Verifierを呼び出して、機能を実行する + this.execTransaction(requestInfo, tradeInfo); + + } + + + execTransaction(requestInfo: RequestInfo, tradeInfo: TradeInfo) { + + logger.debug("called execTransaction()"); + + const useValidator = JSON.parse(transactionManagement.getValidatorToUse(tradeInfo.businessLogicID)); + // TODO: 暫定的に監視不要を指定(※第3パラメタ=false) + const verifier = verifierFactory.getVerifier(useValidator['validatorID'][0], {}, false); + logger.debug("getVerifier"); + + const contract = {}; + const method = {command: "run-transaction"}; + const args = {"args": { + "keychainId": requestInfo.keychainId, + "keychainRef": requestInfo.keychainRef, + "channelName": requestInfo.channelName, + "invocationType": requestInfo.invocationType, + "functionName": requestInfo.functionName, + "functionArgs": requestInfo.functionArgs + }}; + + verifier.requestLedgerOperationHttp(contract, method, args); + + } + + +} diff --git a/examples/run-transaction/RequestInfo.ts b/examples/run-transaction/RequestInfo.ts new file mode 100644 index 0000000000..8c9a1939f6 --- /dev/null +++ b/examples/run-transaction/RequestInfo.ts @@ -0,0 +1,28 @@ +/* + * Copyright 2021 Hyperledger Cactus Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * RequestInfo.ts + */ + +// request information +export class RequestInfo { + businessLogicID: string; + tradeID: string; + + keychainId: string; + keychainRef: string; + channelName: string; + invocationType: string; + functionName: string; + functionArgs: Array; + + setBusinessLogicID(businessLogicID: string) { + this.businessLogicID = businessLogicID; + } + + setTradeID(tradeID: string) { + this.tradeID = tradeID; + } +} + diff --git a/examples/run-transaction/config/BLP_config.ts b/examples/run-transaction/config/BLP_config.ts new file mode 100644 index 0000000000..650be3b5d2 --- /dev/null +++ b/examples/run-transaction/config/BLP_config.ts @@ -0,0 +1,21 @@ +/* + * Copyright 2021 Hyperledger Cactus Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * BLP_config.ts + */ + +import { BusinessLogicPlugin } from '../../../packages/business-logic-plugin/BusinessLogicPlugin'; +import { BusinessLogicRunTransaction } from '../BusinessLogicRunTransaction'; +// import { BusinessLogicCartrade } from '../examples/cartrade/BusinessLogicXxxxTrade'; + +export function getTargetBLPInstance(businessLogicID: string): BusinessLogicPlugin | null { + switch (businessLogicID) { + case "j71S9gLN": + return new BusinessLogicRunTransaction(businessLogicID); + // case "xxxxxxxx": + // return new BusinessLogicXxxxTrade(); + default: + return null; + } +} diff --git a/examples/run-transaction/config/default.json b/examples/run-transaction/config/default.json new file mode 100644 index 0000000000..9fea9f0575 --- /dev/null +++ b/examples/run-transaction/config/default.json @@ -0,0 +1,8 @@ +{ + "runTransactionInfo": { + "connector": { + "validatorID": "vIdAcnCF" + } + }, + "logLevel": "debug" +} \ No newline at end of file diff --git a/examples/run-transaction/config/usersetting.json b/examples/run-transaction/config/usersetting.json new file mode 100644 index 0000000000..3b0b0caf8b --- /dev/null +++ b/examples/run-transaction/config/usersetting.json @@ -0,0 +1,19 @@ +{ + "blpRegistry": [ + { + "businessLogicID": "j71S9gLN", + "validatorID": ["vIdAcnCF"] + } + ], + "logLevel": "debug", + "applicationHostInfo": { + "hostName": "http://xxx.xxxxx.xxx:xxxx", + "hostPort": 5034 + }, + "appRouters": [ + { + "path": "/api/v1/bl/run-transaction/", + "routerJs": "../../examples/run-transaction/run-transaction.js" + } + ] +} diff --git a/examples/run-transaction/copyBLPConfig.ts b/examples/run-transaction/copyBLPConfig.ts new file mode 100644 index 0000000000..fabfbffaaa --- /dev/null +++ b/examples/run-transaction/copyBLPConfig.ts @@ -0,0 +1,13 @@ +/* + * Copyright 2021 Hyperledger Cactus Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * copyBLPConfig.ts + */ + +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/'); diff --git a/examples/run-transaction/copyStaticAssets.ts b/examples/run-transaction/copyStaticAssets.ts new file mode 100644 index 0000000000..1d243b04a4 --- /dev/null +++ b/examples/run-transaction/copyStaticAssets.ts @@ -0,0 +1,14 @@ +/* + * Copyright 2021 Hyperledger Cactus Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * copyStaticAssets.ts + */ + +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/usersetting.json', '../../dist/packages/config/'); diff --git a/examples/run-transaction/package.json b/examples/run-transaction/package.json new file mode 100644 index 0000000000..3fa0d408b4 --- /dev/null +++ b/examples/run-transaction/package.json @@ -0,0 +1,40 @@ +{ + "name": "run-transaction", + "private": true, + "scripts": { + "start": "node ../../dist/packages/routing-interface/www.js", + "debug": "nodemon --inspect ../../dist/packages/routing-interface/www.js", + "build": "npm run build-ts && npm run copy-static-assets && npm run copy-blp-config && npm run replace-blp-config-path", + "build-ts": "tsc -p ./tsconfig.json", + "tslint": "tslint -c tslint.json -p tsconfig.json './*.ts'", + "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" + }, + "dependencies": { + "@types/node": "^14.0.24", + "body-parser": "^1.19.0", + "cookie-parser": "~1.4.4", + "debug": "~2.6.9", + "ethereumjs-common": "^1.5.1", + "ethereumjs-tx": "^2.1.2", + "express": "~4.16.1", + "fabric-ca-client": "~1.4.0", + "fabric-network": "~1.4.0", + "http-errors": "~1.6.3", + "jade": "~1.11.0", + "jsonwebtoken": "^8.5.1", + "log4js": "^3.0.6", + "morgan": "~1.9.1", + "shelljs": "^0.8.4", + "socket.io": "^2.0.4", + "ts-node": "8.9.1", + "web3": "^1.2.9", + "xmlhttprequest": "^1.8.0" + }, + "devDependencies": { + "tslint": "6.0.0", + "typescript": "3.9.3" + } +} diff --git a/examples/run-transaction/replaceBLPConfigPath.ts b/examples/run-transaction/replaceBLPConfigPath.ts new file mode 100644 index 0000000000..032b745ef1 --- /dev/null +++ b/examples/run-transaction/replaceBLPConfigPath.ts @@ -0,0 +1,22 @@ +/* + * Copyright 2021 Hyperledger Cactus Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * ReplacePath.js + */ +const fs = require('fs') + +const targetFile = '../../dist/packages/config/BLP_config.js'; +const srcStr = '"../BusinessLogicRunTransaction"'; +const distStr = '"../../examples/run-transaction/BusinessLogicRunTransaction"'; + +fs.readFile(targetFile, 'utf8', (readErr, data) => { + if (readErr) { + return console.log(readErr); + } + const result = data.replace(srcStr, distStr); + + fs.writeFile(targetFile, result, 'utf8', (writeErr) => { + if (writeErr) return console.log(writeErr); + }); +}); diff --git a/examples/run-transaction/run-transaction.ts b/examples/run-transaction/run-transaction.ts new file mode 100644 index 0000000000..7b387e1451 --- /dev/null +++ b/examples/run-transaction/run-transaction.ts @@ -0,0 +1,44 @@ +/* + * Copyright 2021 Hyperledger Cactus Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * run-transaction.ts + */ + +import { Router, NextFunction, Request, Response } from 'express'; +import { TransactionManagement } from '../../packages/routing-interface/TransactionManagement'; +import { RIFError } from '../../packages/routing-interface/RIFError'; +import { ConfigUtil } from '../../packages/routing-interface/util/ConfigUtil'; + +const fs = require('fs'); +const path = require('path'); +const config: any = ConfigUtil.getConfig(); +import { getLogger } from "log4js"; +const moduleName = '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 +router.post('/', (req: Request, res: Response, next: NextFunction) => { + try { + console.log("run-transaction()"); + const tradeID: string = transactionManagement.startBusinessLogic(req); + + const result = {tradeID: tradeID}; + res.status(200).json(result); + + } catch (err) { + if (err instanceof RIFError) { + res.status(err.statusCode); + res.send(err.message); + return; + } + + next(err); + } +}); + +export default router; diff --git a/examples/run-transaction/tsconfig.json b/examples/run-transaction/tsconfig.json new file mode 100644 index 0000000000..98a8691880 --- /dev/null +++ b/examples/run-transaction/tsconfig.json @@ -0,0 +1,80 @@ +{ + "compilerOptions": { + /* Basic Options */ + "incremental": true, /* Enable incremental compilation */ + "target": "ES2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ + "module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "lib": [ + "es2015", + "es2016", + "es2017", + "dom" + ], /* Specify library files to be included in the compilation. */ + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationDir": "dist/types", + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + // "outDir": "./dist/lib/", /* Redirect output structure to the directory. */ + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + /* Strict Type-Checking Options */ +// "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + /* Module Resolution Options */ + "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + "resolveJsonModule": true, /* When true allows the importing of json files in Typescript code */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + "typeRoots": [ + "./node_modules/@types", + "./typings" + ], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + /* Advanced Options */ + "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */ + "outDir": "../../dist" + }, + "include": [ + "./*.ts", + "./config/*.ts" + ], + "exclude": [ + "copyStaticAssets.ts", + "copyBLPConfig.ts", + "replaceBLPConfigPath.ts" + ] +} diff --git a/examples/run-transaction/tslint.json b/examples/run-transaction/tslint.json new file mode 100644 index 0000000000..9a00b4aa19 --- /dev/null +++ b/examples/run-transaction/tslint.json @@ -0,0 +1,28 @@ +{ + "defaultSeverity": "error", + "extends": [ + "tslint:recommended" + ], + "jsRules": {}, + "rules": { + "variable-name": { + "options": [ + "allow-leading-underscore", + "ban-keywords", + "check-format" + ] + }, + "no-string-literal": false, + "no-var-requires": false, + "object-literal-shorthand": false, + "max-classes-per-file": false, + "no-console": false + }, + "rulesDirectory": [], + "linterOptions": { + "exclude": [ + "packages/cactus-sdk/src/main/typescript/generated/**/*.ts", + "packages/cactus-sdk/src/main/typescript/public-api.ts" + ] + } +} diff --git a/packages/business-logic-plugin/app.ts b/packages/business-logic-plugin/app.ts index 4f5c0afd51..9d12cde313 100644 --- a/packages/business-logic-plugin/app.ts +++ b/packages/business-logic-plugin/app.ts @@ -16,12 +16,10 @@ import bodyParser = require('body-parser'); import indexRouter from '../routing-interface/routes/index'; import loginRouter from '../routing-interface/routes/login'; -import tradesRouter from '../routing-interface/routes/trades'; -import balanceRouter from '../routing-interface/routes/balance'; -import carsRouter from '../routing-interface/routes/cars'; -import assetRouter from '../routing-interface/routes/asset'; import blockmonitorRouter from '../routing-interface/routes/blockmonitor'; -import electricityTradeRouter from '../routing-interface/routes/electricity-trade'; +import { ConfigUtil } from '../routing-interface/util/ConfigUtil'; + +const config: any = ConfigUtil.getConfig(); const app: express.Express = express(); @@ -35,12 +33,15 @@ app.use(bodyParser.json()); app.use('/', indexRouter); app.use('/api/v1/bl/login/', loginRouter); -app.use('/api/v1/bl/trades/', tradesRouter); -app.use('/api/v1/bl/balance/', balanceRouter); -app.use('/api/v1/bl/cars/', carsRouter); -app.use('/api/v1/bl/asset/', assetRouter); app.use('/api/v1/bl/blockmonitor/', blockmonitorRouter); -app.use('/api/v1/bl/electricity-trade/', electricityTradeRouter); + +// Dynamic loading +console.debug(`start Dynamic loading.`); +for (var appRouter of config.appRouters) { + console.debug(`path: ${appRouter.path}, routerJs: ${appRouter.routerJs}`); + app.use(appRouter.path, require(appRouter.routerJs).default); +} + // catch 404 and forward to error handler app.use((req: Request, res: Response, next: NextFunction) => { diff --git a/packages/config/default.json b/packages/config/default.json index 2ac143e55b..3a9f9ca588 100644 --- a/packages/config/default.json +++ b/packages/config/default.json @@ -7,6 +7,10 @@ { "businessLogicID": "h40Q9eMD", "validatorID": ["sUr7d10R", "84jUisrs"] + }, + { + "businessLogicID": "j71S9gLN", + "validatorID": ["vIdAcnCF"] } ], "logLevel": "debug", @@ -22,5 +26,6 @@ "verifier": { "maxCounterRequestID":100, "syncFunctionTimeoutMillisecond":5000 - } + }, + "appRouters": [] } \ No newline at end of file diff --git a/packages/config/verifier-config.json b/packages/config/verifier-config.json index 90299d35d8..6f8bbca6ca 100644 --- a/packages/config/verifier-config.json +++ b/packages/config/verifier-config.json @@ -89,6 +89,33 @@ "ledgerAbstract": "Sawtooth Ledger" }, "apiInfo": [] + }, + { + "validatorID": "vIdAcnCB", + "validatorURL": "http://localhost:5053/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/", + "validatorKeyPath": "", + "ledgerInfo": { + "ledgerAbstract": "Cactus Besu Ledger via http connection" + }, + "apiInfo": [] + }, + { + "validatorID": "vIdAcnCF", + "validatorURL": "http://localhost:5053/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-fabric/", + "validatorKeyPath": "", + "ledgerInfo": { + "ledgerAbstract": "Cactus Fabric Ledger via http connection" + }, + "apiInfo": [] + }, + { + "validatorID": "vIdAcnCQ", + "host": "http://localhost:5053/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-quorum/", + "validatorKeyPath": "", + "ledgerInfo": { + "ledgerAbstract": "Cactus Quorum Ledger via http connection" + }, + "apiInfo": [] } ] } diff --git a/packages/ledger-plugin/VerifierBase.ts b/packages/ledger-plugin/VerifierBase.ts index cb8bf4da23..7872cfcaa0 100644 --- a/packages/ledger-plugin/VerifierBase.ts +++ b/packages/ledger-plugin/VerifierBase.ts @@ -12,6 +12,7 @@ import { LedgerOperation } from './../business-logic-plugin/LedgerOperation'; import { Socket } from 'dgram'; import { ConfigUtil } from '../routing-interface/util/ConfigUtil'; import { VerifierAuthentication } from './VerifierAuthentication'; +const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; const io = require('socket.io-client'); @@ -261,6 +262,35 @@ export class VerifierBase implements Verifier { }); } + requestLedgerOperationHttp(contract: object, method: object, args: object): Promise { + return new Promise((resolve, reject) => { + try { + logger.debug(`##in requestLedgerOperationHttp, contract = ${JSON.stringify(contract)}, method = ${JSON.stringify(method)}, args = ${JSON.stringify(args)}`); + + const httpReq = new XMLHttpRequest(); + httpReq.onload = function() { + // TODO: responding in JSON format? + logger.debug(`responseObj = ${httpReq.responseText}`); + const responseObj = JSON.parse(httpReq.responseText); + logger.debug(`responseObj = ${JSON.stringify(responseObj)}`); + resolve(responseObj); + }; + + logger.debug(`validatorUrl: ${this.validatorUrl}`); + httpReq.open('POST', this.validatorUrl + method['command']); + // httpReq.setRequestHeader('content-type', 'application/json'); + httpReq.setRequestHeader('Content-Type', 'application/json'); + // httpReq.send(args['args']); + logger.debug(`args['args']: ${JSON.stringify(args['args'])}`); + httpReq.send(JSON.stringify(args['args'])); + } + catch (err) { + logger.error(`##Error: requestLedgerOperationHttp, ${err}`); + reject(err); + } + }); + } + startMonitor(options = {}): Promise { return new Promise((resolve, reject) => { logger.debug('call : startMonitor'); diff --git a/packages/ledger-plugin/VerifierFactory.ts b/packages/ledger-plugin/VerifierFactory.ts new file mode 100644 index 0000000000..8517b16047 --- /dev/null +++ b/packages/ledger-plugin/VerifierFactory.ts @@ -0,0 +1,48 @@ +/* + * Copyright 2021 Hyperledger Cactus Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * VerifierFactory.ts + */ + +import { transactionManagement } from '../routing-interface/routes/index'; +import { VerifierBase } from '../ledger-plugin/VerifierBase'; +import { LPInfoHolder } from '../routing-interface/util/LPInfoHolder'; +import { ConfigUtil } from '../routing-interface/util/ConfigUtil'; + +const config: any = ConfigUtil.getConfig(); +import { getLogger } from "log4js"; +const moduleName = 'VerifierFactory'; +const logger = getLogger(`${moduleName}`); +logger.level = config.logLevel; + +export class VerifierFactory { + private connectInfo: LPInfoHolder = null; // connection information + private verifierArray: [] = []; // Verifier + + constructor() { + this.connectInfo = new LPInfoHolder(); + } + + // Get Verifier + getVerifier(validatorId: string, monitorOptions: {} = {}, monitorMode: boolean = true): VerifierBase { + + // Return Verifier + // If you have already made it, please reply. If you haven't made it yet, make it and reply. + if (this.verifierArray[validatorId]) { + return this.verifierArray[validatorId]; + } + else { + const ledgerPluginInfo: string = this.connectInfo.getLegerPluginInfo(validatorId); + // TODO: I want to manage an instance using the validatorId as a key instead of a dedicated member variable + this.verifierArray[validatorId] = new VerifierBase(ledgerPluginInfo); + logger.debug("##startMonitor"); + if (monitorMode) { + this.verifierArray[validatorId].setEventListener(transactionManagement); + this.verifierArray[validatorId].startMonitor(monitorOptions); + } + return this.verifierArray[validatorId]; + } + + } +} diff --git a/packages/package.json b/packages/package.json index 9f7f38a5e7..f81b58f7b4 100644 --- a/packages/package.json +++ b/packages/package.json @@ -26,7 +26,8 @@ "shelljs": "^0.8.4", "socket.io": "^2.0.4", "ts-node": "8.9.1", - "web3": "^1.2.9" + "web3": "^1.2.9", + "xmlhttprequest": "^1.8.0" }, "devDependencies": { "@types/jest": "^26.0.19", diff --git a/packages/routing-interface/TransactionManagement.ts b/packages/routing-interface/TransactionManagement.ts index 7d35d0d5d1..66f1ad5293 100644 --- a/packages/routing-interface/TransactionManagement.ts +++ b/packages/routing-interface/TransactionManagement.ts @@ -25,14 +25,14 @@ logger.level = config.logLevel; export class TransactionManagement { private blpRegistry: BLPRegistry = null; // Verifier information used in business logic - private connectInfo: LPInfoHolder = null; // connection information - private verifierArray: [] = []; // Verifier +// private connectInfo: LPInfoHolder = null; // connection information +// private verifierArray: [] = []; // Verifier // private txIDMapInfo: Map = null; private tradeIDMapInfo: Map = null; constructor() { this.blpRegistry = new BLPRegistry(); - this.connectInfo = new LPInfoHolder(); +// this.connectInfo = new LPInfoHolder(); // this.blpMap = new Map(); // this.txIDMapInfo = new Map(); this.tradeIDMapInfo = new Map(); @@ -50,7 +50,7 @@ export class TransactionManagement { logger.info(`tradeID: ${tradeID}`); // object judgment - if ((businessLogicID === "guks32pf") || (businessLogicID === "h40Q9eMD")) { + if ((businessLogicID === "guks32pf") || (businessLogicID === "h40Q9eMD") || (businessLogicID === "j71S9gLN")) { const blp = getTargetBLPInstance(businessLogicID); if (blp === null) { @@ -138,7 +138,7 @@ export class TransactionManagement { return result; } - +/* // Get Verifier getVerifier(validatorId: string, monitorOptions = {}): VerifierBase { @@ -158,7 +158,7 @@ export class TransactionManagement { } } - +*/ // Get validator to use getValidatorToUse(businessLogicId: string): string { diff --git a/packages/routing-interface/routes/index.ts b/packages/routing-interface/routes/index.ts index d7596532c2..0b227e08cd 100644 --- a/packages/routing-interface/routes/index.ts +++ b/packages/routing-interface/routes/index.ts @@ -7,9 +7,11 @@ import { Router, NextFunction, Request, Response } from 'express'; import { TransactionManagement } from '../TransactionManagement'; +import { VerifierFactory } from '../../ledger-plugin/VerifierFactory'; const router: Router = Router(); export const transactionManagement: TransactionManagement = new TransactionManagement(); +export const verifierFactory: VerifierFactory = new VerifierFactory(); /* GET home page. */ router.get('/', (req: Request, res: Response, next: NextFunction) => {